Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add api for robot charging tasks #283

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we necessarily need this event_description schema since we don't support any ChargeBattery events in rmf_task.
With this description, users can theoretically submit a composable task with a ChargeBattery event injected between other activities but the fleet adapter will not find the right builder from rmf_task_sequence to generate the Model and Description for this event.

Not a blocker imo but it would be good to test what happens when such a compose task is submitted to make sure any errors are gracefully handled.

"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://raw.githubusercontent.com/open-rmf/rmf_ros2/main/rmf_fleet_adapter/schemas/event_description__charge_battery.json",
"title": "Charge Battery Event",
"description": "Charge a robot's battery",
"type": "object",
"properties": {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think right now the battery level to which the robot charges up to is statically defined in the fleet config. In the future it would be good to specify this % in the properties here and have the TaskPlanner accept this value in the Options it receives before it plans. Not a blocker.

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://raw.githubusercontent.com/open-rmf/rmf_ros2/main/rmf_fleet_adapter/schemas/task_description__charge_battery.json",
"title": "Charge Battery Task",
"description": "Charge a robot's battery",
"$ref": "event_description__charge_battery.json"
}
14 changes: 14 additions & 0 deletions rmf_fleet_adapter/src/rmf_fleet_adapter/agv/FleetUpdateHandle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,16 @@ void FleetUpdateHandle::Implementation::bid_notice_cb(
});
}

const auto& category = request_msg["category"].get<std::string>();
if (bid_ignored_categories.find(category) != bid_ignored_categories.end())
{
RCLCPP_WARN(
node->get_logger(),
"Fleet [%s] received bid request for category [%s] that can only "
"be a direct task assignment", name.c_str(), category.c_str());
return;
}

std::vector<std::string> errors = {};
const auto new_request = convert(task_id, request_msg, errors);
if (!new_request)
Expand Down Expand Up @@ -1130,6 +1140,7 @@ void FleetUpdateHandle::Implementation::add_standard_tasks()
node->clock());

tasks::add_charge_battery(
deserialization,
*activation.task,
activation.phase,
*activation.event,
Expand All @@ -1139,6 +1150,9 @@ void FleetUpdateHandle::Implementation::add_standard_tasks()
deserialization,
activation,
node->clock());

// TODO(luca) make this configurable to system integrators
bid_ignored_categories.insert("charge_battery");
}

//==============================================================================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,9 @@ class FleetUpdateHandle::Implementation

TaskActivation activation = TaskActivation();
TaskDeserialization deserialization = TaskDeserialization();
// Categories of tasks that the fleet adapter should not bid for but should
// still accept as direct tasks, such as battery charging
std::unordered_set<std::string> bid_ignored_categories = {};

// LegacyTask planner params
std::shared_ptr<rmf_task::CostCalculator> cost_calculator =
Expand Down
23 changes: 23 additions & 0 deletions rmf_fleet_adapter/src/rmf_fleet_adapter/tasks/ChargeBattery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
#include <rmf_task_sequence/phases/SimplePhase.hpp>
#include <rmf_task_sequence/events/Placeholder.hpp>

#include <rmf_fleet_adapter/schemas/task_description__charge_battery.hpp>
#include <rmf_fleet_adapter/schemas/event_description__charge_battery.hpp>

#include <rmf_task_sequence/Task.hpp>

namespace rmf_fleet_adapter {
Expand Down Expand Up @@ -165,6 +168,7 @@ struct ChargeBatteryEventDescription

//==============================================================================
void add_charge_battery(
agv::TaskDeserialization& deserialization,
rmf_task::Activator& task_activator,
const rmf_task_sequence::Phase::ConstActivatorPtr& phase_activator,
rmf_task_sequence::Event::Initializer& event_initializer,
Expand All @@ -180,6 +184,25 @@ void add_charge_battery(
WaitForChargeDescription::add(*private_initializer);
GoToChargerDescription::add(*private_initializer);

// TODO(luca) Populate charge event with properties such as time, desired battery soc
deserialization.add_schema(schemas::event_description__charge_battery);

auto validate_charge_task =
deserialization.make_validator_shared(
schemas::task_description__charge_battery);
deserialization.add_schema(schemas::task_description__charge_battery);

auto deserialize_charge =
[]
(const nlohmann::json&) -> agv::DeserializedTask
{
// Always accept
agv::FleetUpdateHandle::Confirmation confirm;
return {rmf_task::requests::ChargeBattery::Description::make(), {}};
};
deserialization.task->add("charge_battery", validate_charge_task,
deserialize_charge);

auto charge_battery_event_unfolder =
[](const ChargeBatteryEventDescription&)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#define SRC__RMF_FLEET_ADAPTER__TASKS__CHARGEBATTERY_HPP

#include "../LegacyTask.hpp"
#include "../agv/internal_FleetUpdateHandle.hpp"
#include "../agv/RobotContext.hpp"

#include <rmf_traffic/agv/Planner.hpp>
Expand All @@ -43,6 +44,7 @@ std::shared_ptr<LegacyTask> make_charge_battery(

//==============================================================================
void add_charge_battery(
agv::TaskDeserialization& deserialization,
rmf_task::Activator& task_activator,
const rmf_task_sequence::Phase::ConstActivatorPtr& phase_activator,
rmf_task_sequence::Event::Initializer& event_initializer,
Expand Down