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 1 commit
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
9 changes: 9 additions & 0 deletions rmf_fleet_adapter/schemas/event_description__charge.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"$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.json",
"title": "Charge Event",
Copy link
Contributor

Choose a reason for hiding this comment

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

I recommend we add "Battery" everywhere to make this more explicit, e.g. "Charge Battery Event", event_description__charge_battery.json, "Charge the battery of a robot".

If anyone develops a bull robot for a rodeo they might want "charge" to mean something else.

Copy link
Member Author

Choose a reason for hiding this comment

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

"description": "Charge a robot",
"type": "object",
"properties": {
}
}
7 changes: 7 additions & 0 deletions rmf_fleet_adapter/schemas/task_description__charge.json
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.json",
"title": "Charge Task",
"description": "Charge a robot",
"$ref": "event_description__charge.json"
}
Original file line number Diff line number Diff line change
Expand Up @@ -1104,6 +1104,7 @@ void FleetUpdateHandle::Implementation::add_standard_tasks()
node->clock());

tasks::add_charge_battery(
deserialization,
*activation.task,
activation.phase,
*activation.event,
Expand Down
22 changes: 22 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.hpp>
#include <rmf_fleet_adapter/schemas/event_description__charge.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,24 @@ 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);

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

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", 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