Skip to content

Commit

Permalink
Provide a setting for charge tasks to run indefinitely (#99)
Browse files Browse the repository at this point in the history
Signed-off-by: Michael X. Grey <mxgrey@intrinsic.ai>
  • Loading branch information
mxgrey committed Dec 15, 2023
1 parent d426a7c commit 5009f92
Show file tree
Hide file tree
Showing 4 changed files with 49 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

0 comments on commit 5009f92

Please sign in to comment.