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 request_type identifier and configurable retreat_to_charger #114

Closed
wants to merge 2 commits into from
Closed
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
14 changes: 13 additions & 1 deletion rmf_task/include/rmf_task/Constraints.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,16 @@ class Constraints
/// \param[in] drain_battery
/// If true, battery drain will be considered during task allocation and
/// ChargeBattery tasks will automatically be included if necessary.
///
/// \param[in] retreat_to_charger
/// If true, a Charge task will automatically be added for the robot if it
/// is estimated to have its battery soc fall below its recharge_soc before
/// reaching a charger
Constraints(
double threshold_soc,
double recharge_soc = 1.0,
bool drain_battery = true);
bool drain_battery = true,
bool retreat_to_charger = true);

/// Gets the vehicle's state of charge threshold value.
double threshold_soc() const;
Expand All @@ -67,6 +73,12 @@ class Constraints
/// Set the value of drain_battery
Constraints& drain_battery(bool drain_battery);

/// Get the value of retreat_to_charger
bool retreat_to_charger() const;

/// Set the value of retreat_to_charger
Constraints& retreat_to_charger(bool retreat_to_charger);

class Implementation;
private:
rmf_utils::impl_ptr<Implementation> _pimpl;
Expand Down
3 changes: 3 additions & 0 deletions rmf_task/include/rmf_task/RequestFactory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ class RequestFactory
/// request.
virtual ConstRequestPtr make_request(const State& state) const = 0;

/// Returns an identifier representing the request type.
virtual const std::string& request_type() const = 0;

virtual ~RequestFactory() = default;
};

Expand Down
3 changes: 3 additions & 0 deletions rmf_task/include/rmf_task/requests/ChargeBatteryFactory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ class ChargeBatteryFactory : public RequestFactory
/// Documentation inherited
ConstRequestPtr make_request(const State& state) const final;

/// Documentation inherited
const std::string& request_type() const final;

class Implementation;

private:
Expand Down
3 changes: 3 additions & 0 deletions rmf_task/include/rmf_task/requests/ParkRobotFactory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ class ParkRobotFactory : public RequestFactory
/// Documentation inherited
ConstRequestPtr make_request(const State& state) const final;

/// Documentation inherited
const std::string& request_type() const final;

class Implementation;

private:
Expand Down
21 changes: 19 additions & 2 deletions rmf_task/src/rmf_task/Constraints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,22 @@ class Constraints::Implementation
double threshold_soc;
double recharge_soc;
bool drain_battery;
bool retreat_to_charger;
};

//==============================================================================
Constraints::Constraints(
double threshold_soc,
double recharge_soc,
bool drain_battery)
bool drain_battery,
bool retreat_to_charger)
: _pimpl(rmf_utils::make_impl<Implementation>(
Implementation
{
threshold_soc,
recharge_soc,
drain_battery
drain_battery,
retreat_to_charger
}))
{
if (threshold_soc < 0.0 || threshold_soc > 1.0)
Expand Down Expand Up @@ -116,4 +119,18 @@ auto Constraints::drain_battery(
return *this;
}

//==============================================================================
bool Constraints::retreat_to_charger() const
{
return _pimpl->retreat_to_charger;
}

//==============================================================================
auto Constraints::retreat_to_charger(
bool retreat_to_charger) -> Constraints&
{
_pimpl->retreat_to_charger = retreat_to_charger;
return *this;
}

} // namespace rmf_task
9 changes: 8 additions & 1 deletion rmf_task/src/rmf_task/requests/ChargeBatteryFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class ChargeBatteryFactory::Implementation
std::optional<std::string> requester;
std::function<rmf_traffic::Time()> time_now_cb;
bool indefinite = false;
std::string request_type = "Charge";
};

//==============================================================================
Expand Down Expand Up @@ -85,7 +86,7 @@ bool ChargeBatteryFactory::indefinite() const
//==============================================================================
ConstRequestPtr ChargeBatteryFactory::make_request(const State& state) const
{
const std::string id = "Charge" + generate_uuid();
const std::string id = _pimpl->request_type + generate_uuid();
Task::ConstBookingPtr booking;
if (_pimpl->requester.has_value() && _pimpl->time_now_cb)
{
Expand Down Expand Up @@ -114,5 +115,11 @@ ConstRequestPtr ChargeBatteryFactory::make_request(const State& state) const
return std::make_shared<Request>(std::move(booking), std::move(description));
}

//==============================================================================
const std::string& ChargeBatteryFactory::request_type() const
{
return _pimpl->request_type;
}

} // namespace requests
} // namespace rmf_task
9 changes: 8 additions & 1 deletion rmf_task/src/rmf_task/requests/ParkRobotFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class ParkRobotFactory::Implementation
std::optional<std::string> requester;
std::function<rmf_traffic::Time()> time_now_cb;
std::optional<std::size_t> parking_waypoint;
const std::string request_type = "ParkRobot";
};

//==============================================================================
Expand All @@ -76,7 +77,7 @@ ParkRobotFactory::ParkRobotFactory(
//==============================================================================
ConstRequestPtr ParkRobotFactory::make_request(const State& state) const
{
std::string id = "ParkRobot" + generate_uuid();
std::string id = _pimpl->request_type + generate_uuid();
const auto start_waypoint = state.waypoint().value();
const auto finish_waypoint = _pimpl->parking_waypoint.has_value() ?
_pimpl->parking_waypoint.value() :
Expand Down Expand Up @@ -105,5 +106,11 @@ ConstRequestPtr ParkRobotFactory::make_request(const State& state) const
true);
}

//==============================================================================
const std::string& ParkRobotFactory::request_type() const
{
return _pimpl->request_type;
}

} // namespace requests
} // namespace rmf_task
Loading