Skip to content

Commit

Permalink
Merge branch 'main' into arjo/feat/multiple_destinations
Browse files Browse the repository at this point in the history
  • Loading branch information
mxgrey authored Dec 21, 2023
2 parents 8521995 + 8d91b71 commit 3bec890
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 14 deletions.
4 changes: 4 additions & 0 deletions rmf_task/CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
Changelog for package rmf_task
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

2.3.3 (2023-12-15)
------------------
* Allow charging tasks to run indefinitely (`#99 <https://github.com/open-rmf/rmf_task/pull/99>`_, `#100 <https://github.com/open-rmf/rmf_task/pull/100>`_)

2.3.2 (2023-08-10)
------------------

Expand Down
3 changes: 3 additions & 0 deletions rmf_task/include/rmf_task/requests/ChargeBattery.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ class ChargeBattery
/// Generate the description for this request
static Task::ConstDescriptionPtr make();

/// Make a charging task that will last indefinitely.
static std::shared_ptr<Description> make_indefinite();

// Documentation inherited
Task::ConstModelPtr make_model(
rmf_traffic::Time earliest_start_time,
Expand Down
2 changes: 1 addition & 1 deletion rmf_task/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<?xml-model href="http://download.ros.org/schema/package_format2.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>rmf_task</name>
<version>2.3.2</version>
<version>2.3.3</version>
<description>Package for managing tasks in the Robotics Middleware Framework</description>
<maintainer email="[email protected]">Yadunund</maintainer>
<maintainer email="[email protected]">Marco A. Gutiérrez</maintainer>
Expand Down
9 changes: 9 additions & 0 deletions rmf_task/src/rmf_task/requests/ChargeBattery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,15 @@ Task::ConstDescriptionPtr ChargeBattery::Description::make()
return description;
}

//==============================================================================
auto ChargeBattery::Description::make_indefinite()
-> std::shared_ptr<Description>
{
std::shared_ptr<Description> description(new Description);
description->set_indefinite(true);
return description;
}

//==============================================================================
ChargeBattery::Description::Description()
: _pimpl(rmf_utils::make_impl<Implementation>(Implementation()))
Expand Down
47 changes: 41 additions & 6 deletions rmf_task/src/rmf_task/requests/ChargeBatteryFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,32 @@

#include <rmf_task/requests/ChargeBatteryFactory.hpp>
#include <rmf_task/requests/ChargeBattery.hpp>
#include <random>

namespace rmf_task {
namespace requests {

//==============================================================================
namespace {
std::string generate_uuid(const std::size_t length = 3)
{
std::stringstream ss;
for (std::size_t i = 0; i < length; ++i)
{
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_int_distribution<> dis(0, 255);
const auto random_char = dis(gen);
std::stringstream hexstream;
hexstream << std::hex << random_char;
auto hex = hexstream.str();
ss << (hex.length() < 2 ? '0' + hex : hex);
}
return ss.str();
}

} // anonymous namespace

//==============================================================================
class ChargeBatteryFactory::Implementation
{
Expand Down Expand Up @@ -63,20 +85,33 @@ bool ChargeBatteryFactory::indefinite() const
//==============================================================================
ConstRequestPtr ChargeBatteryFactory::make_request(const State& state) const
{

const std::string id = "Charge" + generate_uuid();
Task::ConstBookingPtr booking;
if (_pimpl->requester.has_value() && _pimpl->time_now_cb)
{
return ChargeBattery::make(
booking =
std::make_shared<const rmf_task::Task::Booking>(
std::move(id),
state.time().value(),
nullptr,
_pimpl->requester.value(),
_pimpl->time_now_cb(),
true);
}
else
{
booking =
std::make_shared<const rmf_task::Task::Booking>(
std::move(id),
state.time().value(),
nullptr,
true);
}
return ChargeBattery::make(
state.time().value(),
nullptr,
true);

const auto description = ChargeBattery::Description::make_indefinite();
description->set_indefinite(_pimpl->indefinite);

return std::make_shared<Request>(std::move(booking), std::move(description));
}

} // namespace requests
Expand Down
4 changes: 4 additions & 0 deletions rmf_task_sequence/CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
Changelog for package rmf_task_sequence
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

2.3.3 (2023-12-15)
------------------
* Fix edge case for task sequences (`#102 <https://github.com/open-rmf/rmf_task/pull/102>`_)

2.3.2 (2023-08-10)
------------------
* Fix battery drain crash for GoToPlace (`#94 <https://github.com/open-rmf/rmf_task/pull/94>`_)
Expand Down
2 changes: 1 addition & 1 deletion rmf_task_sequence/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<?xml-model href="http://download.ros.org/schema/package_format2.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>rmf_task_sequence</name>
<version>2.3.2</version>
<version>2.3.3</version>
<description>Implementation of phase-sequence tasks for the Robotics Middleware Framework</description>
<maintainer email="[email protected]">Grey</maintainer>
<maintainer email="[email protected]">Marco A. Gutiérrez</maintainer>
Expand Down
19 changes: 13 additions & 6 deletions rmf_task_sequence/src/rmf_task_sequence/events/Sequence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,12 +366,6 @@ void Sequence::Active::next()

BoolGuard lock(_inside_next);

const auto event_finished = [me = weak_from_this()]()
{
if (const auto self = me.lock())
self->next();
};

do
{
if (_reverse_remaining.empty())
Expand All @@ -384,6 +378,19 @@ void Sequence::Active::next()
++_current_event_index_plus_one;
const auto next_event = _reverse_remaining.back();
_reverse_remaining.pop_back();

const auto event_finished = [
me = weak_from_this(),
event_index_plus_one = _current_event_index_plus_one
]()
{
if (const auto self = me.lock())
{
if (event_index_plus_one == self->_current_event_index_plus_one)
self->next();
}
};

_current = next_event->begin(_checkpoint, event_finished);
} while (_current->state()->finished());

Expand Down

0 comments on commit 3bec890

Please sign in to comment.