Skip to content

Commit

Permalink
Provide a setting for charge tasks to run indefinitely
Browse files Browse the repository at this point in the history
Signed-off-by: Michael X. Grey <[email protected]>
  • Loading branch information
mxgrey committed Oct 11, 2023
1 parent 659b4cc commit 27ceaf2
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 2 deletions.
10 changes: 10 additions & 0 deletions rmf_task/include/rmf_task/requests/ChargeBattery.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,16 @@ class ChargeBattery
const State& initial_state,
const Parameters& parameters) const final;

/// Set the charging task to run indefinitely. This means it will never
/// declare itself as finished and must instead be canceled. This can be
/// used for idle tasks that are canceled automatically when a task request
/// comes in. If indefinite is false, the robot will charge up to its
/// designated recharge level.
void set_indefinite(bool value);

/// Should this recharge task run indefinitely?
bool indefinite() const;

class Implementation;
private:
Description();
Expand Down
10 changes: 10 additions & 0 deletions rmf_task/include/rmf_task/requests/ChargeBatteryFactory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@ class ChargeBatteryFactory : public RequestFactory
const std::string& requester,
std::function<rmf_traffic::Time()> time_now_cb);

/// Set the charging task to run indefinitely. This means it will never
/// declare itself as finished and must instead be canceled. This can be used
/// for idle tasks that are canceled automatically when a task request comes
/// in. If indefinite is false, the robot will charge up to its designated
/// recharge level.
void set_indefinite(bool value);

/// Does this factory produce charging requests that will run indefinitely?
bool indefinite() const;

/// Documentation inherited
ConstRequestPtr make_request(const State& state) const final;

Expand Down
18 changes: 16 additions & 2 deletions rmf_task/src/rmf_task/requests/ChargeBattery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ ChargeBattery::Model::Model(

//==============================================================================
std::optional<rmf_task::Estimate>
ChargeBattery::Model::estimate_finish(const State& initial_state,
ChargeBattery::Model::estimate_finish(
const State& initial_state,
const Constraints& task_planning_constraints,
const TravelEstimator& travel_estimator) const
{
Expand Down Expand Up @@ -162,7 +163,8 @@ rmf_traffic::Duration ChargeBattery::Model::invariant_duration() const
//==============================================================================
class ChargeBattery::Description::Implementation
{

public:
bool indefinite = false;
};

//==============================================================================
Expand Down Expand Up @@ -201,6 +203,18 @@ auto ChargeBattery::Description::generate_info(
};
}

//==============================================================================
void ChargeBattery::Description::set_indefinite(bool value)
{
_pimpl->indefinite = value;
}

//==============================================================================
bool ChargeBattery::Description::indefinite() const
{
return _pimpl->indefinite;
}

//==============================================================================
ConstRequestPtr ChargeBattery::make(
rmf_traffic::Time earliest_start_time,
Expand Down
13 changes: 13 additions & 0 deletions rmf_task/src/rmf_task/requests/ChargeBatteryFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class ChargeBatteryFactory::Implementation
public:
std::optional<std::string> requester;
std::function<rmf_traffic::Time()> time_now_cb;
bool indefinite = false;
};

//==============================================================================
Expand All @@ -47,6 +48,18 @@ ChargeBatteryFactory::ChargeBatteryFactory(
// Do nothing
}

//==============================================================================
void ChargeBatteryFactory::set_indefinite(bool value)
{
_pimpl->indefinite = value;
}

//==============================================================================
bool ChargeBatteryFactory::indefinite() const
{
return _pimpl->indefinite;
}

//==============================================================================
ConstRequestPtr ChargeBatteryFactory::make_request(const State& state) const
{
Expand Down
1 change: 1 addition & 0 deletions rmf_task/src/rmf_task/requests/Loop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ Loop::Model::Model(
auto itinerary_start_time = _earliest_start_time;
double forward_battery_drain = 0.0;
rmf_traffic::Duration forward_duration(0);

for (const auto& itinerary : forward_loop_plan->get_itinerary())
{
const auto& trajectory = itinerary.trajectory();
Expand Down

0 comments on commit 27ceaf2

Please sign in to comment.