Skip to content

Commit 33576ee

Browse files
authored
Customizable weights for task assignment cost (#129)
Signed-off-by: kjchee <keai_jiang_chee@cgh.com.sg>
1 parent 1ab3a1d commit 33576ee

File tree

6 files changed

+385
-11
lines changed

6 files changed

+385
-11
lines changed

rmf_task/include/rmf_task/State.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,15 @@ class State : public CompositeData
104104
/// If any necessary component is missing (i.e. CurrentWaypoint,
105105
/// CurrentOrientation, or CurrentTime) then this will return a std::nullopt.
106106
std::optional<rmf_traffic::agv::Plan::Start> extract_plan_start() const;
107+
108+
/// Check if the robot is idle.
109+
///
110+
/// True if the robot is not executing any task.
111+
/// False only when the robot is actively executing a task
112+
/// (finishing requests are not counted as execution).
113+
RMF_TASK_DEFINE_COMPONENT(bool, IsIdle);
114+
bool is_idle() const;
115+
State& idle(bool is_idle);
107116
};
108117

109118
} // namespace rmf_task

rmf_task/include/rmf_task/TaskPlanner.hpp

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,73 @@ class TaskPlanner
3939
{
4040
public:
4141

42+
/// The TaskAssignmentStrategy class contains the various profiles and
43+
/// their associated weights for cost calculation.
44+
class TaskAssignmentStrategy
45+
{
46+
public:
47+
48+
/// Predefined profiles that initialize the strategy with
49+
/// pre-defined weights and options.
50+
enum class Profile : uint32_t
51+
{
52+
/// Standard RMF assignment strategy with fastest-first approach
53+
DefaultFastest = 0,
54+
55+
/// Prioritize battery level, strongly penalize low SOC with a quadratic term.
56+
/// Still account for task efficiency (fastest-first), but ignore busyness.
57+
BatteryAware,
58+
59+
/// To be overwritten from fleet_config.yaml
60+
Unset
61+
};
62+
63+
/// Options for computing the busyness penalty.
64+
enum class BusyMode : uint8_t
65+
{
66+
/// Mode where busyness penalty is 0 if idle, else 1
67+
Binary = 0,
68+
69+
/// Mode where busyness penalty is based on task count
70+
Count
71+
};
72+
73+
/// Constructor
74+
TaskAssignmentStrategy();
75+
76+
/// Make a strategy initialized from a predefined profile
77+
static TaskAssignmentStrategy make(Profile profile);
78+
79+
/// Set the finish-time polynomial weights
80+
TaskAssignmentStrategy& finish_time_weights(std::vector<double> values);
81+
82+
/// Get the finish-time polynomial weights
83+
const std::vector<double>& finish_time_weights() const;
84+
85+
/// Set the battery penalty polynomial weights
86+
TaskAssignmentStrategy& battery_penalty_weights(std::vector<double> values);
87+
88+
/// Get the battery penalty polynomial weights
89+
const std::vector<double>& battery_penalty_weights() const;
90+
91+
/// Set the busy penalty polynomial weights
92+
TaskAssignmentStrategy& busy_penalty_weights(std::vector<double> values);
93+
94+
/// Get the busy penalty polynomial weights
95+
const std::vector<double>& busy_penalty_weights() const;
96+
97+
/// Set the busyness penalty mode
98+
TaskAssignmentStrategy& busy_mode(BusyMode mode);
99+
100+
/// Get the busyness penalty mode
101+
BusyMode busy_mode() const;
102+
103+
class Implementation;
104+
105+
private:
106+
rmf_utils::impl_ptr<Implementation> _pimpl;
107+
};
108+
42109
/// The Configuration class contains planning parameters that are immutable
43110
/// for each TaskPlanner instance and should not change in between plans.
44111
class Configuration
@@ -128,6 +195,14 @@ class TaskPlanner
128195
/// Get the request factory that will generate a finishing task
129196
ConstRequestFactoryPtr finishing_request() const;
130197

198+
/// Set the task assignment strategy (profile & custom weights)
199+
/// used by the planner
200+
Options& task_assignment_strategy(TaskAssignmentStrategy strategy);
201+
202+
/// Get the task assignment strategy (profile & custom weights)
203+
/// used by the planner
204+
const TaskAssignmentStrategy& task_assignment_strategy() const;
205+
131206
class Implementation;
132207
private:
133208
rmf_utils::impl_ptr<Implementation> _pimpl;

rmf_task/src/rmf_task/State.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,4 +169,20 @@ std::optional<rmf_traffic::agv::Plan::Start> State::extract_plan_start() const
169169
return rmf_traffic::agv::Plan::Start(t->value, wp->value, ori->value);
170170
}
171171

172+
//==============================================================================
173+
bool State::is_idle() const
174+
{
175+
if (const auto* idle = get<IsIdle>())
176+
return idle->value;
177+
178+
return false;
179+
}
180+
181+
//==============================================================================
182+
State& State::idle(bool is_idle)
183+
{
184+
with<IsIdle>(is_idle);
185+
return *this;
186+
}
187+
172188
} // namespace rmf_task

0 commit comments

Comments
 (0)