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

Decommissioning #233

Merged
merged 4 commits into from
Sep 16, 2022
Merged
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
Expand Up @@ -335,6 +335,19 @@ class RobotUpdateHandle
class Unstable
{
public:
/// True if this robot is allowed to accept new tasks. False if the robot
/// will not accept any new tasks.
bool is_commissioned() const;

/// Stop this robot from accepting any new tasks. It will continue to
/// perform tasks that are already in its queue. To reassign those tasks,
/// you will need to use the task request API to cancel the tasks and
/// re-request them.
void decommission();

/// Allow this robot to resume accepting new tasks.
void recommission();

/// Get the schedule participant of this robot
rmf_traffic::schedule::Participant* get_participant();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1132,6 +1132,10 @@ auto FleetUpdateHandle::Implementation::aggregate_expectations() const
Expectations expect;
for (const auto& t : task_managers)
{
// Ignore any robots that are not currently commissioned.
if (!t.first->is_commissioned())
continue;

expect.states.push_back(t.second->expected_finish_state());
const auto requests = t.second->requests();
expect.pending_requests.insert(
Expand Down
18 changes: 18 additions & 0 deletions rmf_fleet_adapter/src/rmf_fleet_adapter/agv/RobotContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,24 @@ std::shared_ptr<TaskManager> RobotContext::task_manager()
return _task_manager.lock();
}

//==============================================================================
bool RobotContext::is_commissioned() const
{
return _commissioned;
}

//==============================================================================
void RobotContext::decommission()
{
_commissioned = false;
}

//==============================================================================
void RobotContext::recommission()
{
_commissioned = true;
}

//==============================================================================
Reporting& RobotContext::reporting()
{
Expand Down
9 changes: 9 additions & 0 deletions rmf_fleet_adapter/src/rmf_fleet_adapter/agv/RobotContext.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,14 @@ class RobotContext
/// Get the task manager for this robot, if it exists.
std::shared_ptr<TaskManager> task_manager();

/// Return true if this robot is currently commissioned (available to accept
/// new tasks).
bool is_commissioned() const;

void decommission();

void recommission();

Reporting& reporting();

const Reporting& reporting() const;
Expand Down Expand Up @@ -290,6 +298,7 @@ class RobotContext

RobotUpdateHandle::Unstable::Watchdog _lift_watchdog;
rmf_traffic::Duration _lift_rewait_duration = std::chrono::seconds(0);
bool _commissioned = true;

// Mode value for RobotMode message
uint32_t _current_mode;
Expand Down
37 changes: 37 additions & 0 deletions rmf_fleet_adapter/src/rmf_fleet_adapter/agv/RobotUpdateHandle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,43 @@ const RobotUpdateHandle::Unstable& RobotUpdateHandle::unstable() const
return _pimpl->unstable;
}

//==============================================================================
bool RobotUpdateHandle::Unstable::is_commissioned() const
{
if (const auto context = _pimpl->get_context())
return context->is_commissioned();

return false;
}

//==============================================================================
void RobotUpdateHandle::Unstable::decommission()
{
if (const auto context = _pimpl->get_context())
{
context->worker().schedule(
[w = context->weak_from_this()](const auto&)
{
if (const auto context = w.lock())
context->decommission();
});
}
}

//==============================================================================
void RobotUpdateHandle::Unstable::recommission()
{
if (const auto context = _pimpl->get_context())
{
context->worker().schedule(
[w = context->weak_from_this()](const auto&)
{
if (const auto context = w.lock())
context->recommission();
});
}
}

//==============================================================================
rmf_traffic::schedule::Participant*
RobotUpdateHandle::Unstable::get_participant()
Expand Down
19 changes: 19 additions & 0 deletions rmf_fleet_adapter_python/src/adapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,25 @@ PYBIND11_MODULE(rmf_adapter, m) {
self.maximum_delay(duration);
},
py::arg("seconds"))
.def("unstable_is_commissioned",
[&](const agv::RobotUpdateHandle& self)
{
return self.unstable().is_commissioned();
},
"Check if the robot is currently allowed to accept any new tasks")
.def("unstable_decommission",
[&](agv::RobotUpdateHandle& self)
{
return self.unstable().decommission();
},
"Stop this robot from accepting any new tasks. Use recommission to resume")
.def("unstable_recommission",
[&](agv::RobotUpdateHandle& self)
{
return self.unstable().recommission();
},
"Allow this robot to resume accepting new tasks if it was ever "
"decommissioned in the past")
.def("get_unstable_participant",
[&](agv::RobotUpdateHandle& self)
{
Expand Down