Class Dispatcher
Defined in File Dispatcher.hpp
Inheritance Relationships
Base Type
public std::enable_shared_from_this< Dispatcher >
Class Documentation
-
class Dispatcher : public std::enable_shared_from_this<Dispatcher>
This dispatcher class holds an instance which handles the dispatching of tasks to all downstream RMF fleet adapters.
Public Types
-
using DispatchStates = std::unordered_map<TaskID, DispatchStatePtr>
-
using DispatchStateCallback = std::function<void(const DispatchState &status)>
Public Functions
-
std::optional<TaskID> submit_task(const rmf_task_msgs::msg::TaskDescription &task_description)
Submit task to dispatcher node. Calling this function will immediately trigger the bidding process, then the task “action”. Once submmitted, Task State will be in ‘Pending’ State, till the task is awarded to a fleet then the state will turn to ‘Queued’
- Parameters:
task_description – [in] Submit a task to dispatch
- Returns:
task_id self-generated task_id, nullopt is submit task failed
-
bool cancel_task(const TaskID &task_id)
Cancel an active task which was previously submitted to Dispatcher. This will terminate the task with a State of:
Canceled
. If a task isQueued
orExecuting
, this function will send a cancel req to the respective fleet adapter. It is the responsibility of the fleet adapter to make sure it cancels the task internally.- Parameters:
task_id – [in] Task to cancel
- Returns:
true if success
-
std::optional<DispatchState> get_dispatch_state(const TaskID &task_id) const
Check the state of a submited task. It can be either active or terminated
- Parameters:
task_id – [in] task_id obtained from
submit_task()
- Returns:
State of the task, nullopt if task is not available
-
const DispatchStates &active_dispatches() const
Get a mutable ref of active tasks map list handled by dispatcher.
-
const DispatchStates &finished_dispatches() const
Get a mutable ref of terminated tasks map list.
-
void on_change(DispatchStateCallback on_change_fn)
Trigger this callback when a task status is changed. This will return the Changed task status.
- Parameters:
callback – [in] function
-
void evaluator(bidding::Auctioneer::ConstEvaluatorPtr evaluator)
Change the default evaluator to a custom evaluator, which is used by bidding auctioneer. Default evaluator is:
QuickestFinishEvaluator
- Parameters:
evaluator – [in] evaluator used to select the best bid from fleets
-
std::shared_ptr<rclcpp::Node> node()
Get the rclcpp::Node that this dispatcher will be using for communication.
-
void spin()
spin dispatcher node
Public Static Functions
-
static std::shared_ptr<Dispatcher> init_and_make_node(const std::string dispatcher_node_name)
Initialize an rclcpp context and make an dispatcher instance. This will instantiate an rclcpp::Node, a task dispatcher node. Dispatcher node will allow you to dispatch submitted task to the best fleet/robot within RMF.
See also
- Parameters:
dispatcher_node_name – [in] The ROS 2 node to manage the Dispatching of Task
-
static std::shared_ptr<Dispatcher> make_node(const std::string dispatcher_node_name)
Similarly this will init the dispatcher, but you will also need to init rclcpp via rclcpp::init(~).
See also
- Parameters:
dispatcher_node_name – [in] The ROS 2 node to manage the Dispatching of Task
Create a dispatcher by providing the ros2 node
See also
- Parameters:
node – [in] ROS 2 node instance
-
using DispatchStates = std::unordered_map<TaskID, DispatchStatePtr>