Class Dispatcher

Inheritance Relationships

Base Type

  • public std::enable_shared_from_this< Dispatcher >

Class Documentation

class rmf_task_ros2::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’

Return

task_id self-generated task_id, nullopt is submit task failed

Parameters
  • [in] task_description: Submit a task to dispatch

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 is Queued or Executing, 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.

Return

true if success

Parameters
  • [in] task_id: Task to cancel

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

Return

State of the task, nullopt if task is not available

Parameters

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
  • [in] callback: function

void evaluator(bidding::Auctioneer::ConstEvaluatorPtr evaluator)

Change the default evaluator to a custom evaluator, which is used by bidding auctioneer. Default evaluator is: LeastFleetDiffCostEvaluator

Parameters
  • [in] evaluator: 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

init_and_make_node()

Parameters
  • [in] dispatcher_node_name: 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

make_node()

Parameters
  • [in] dispatcher_node_name: The ROS 2 node to manage the Dispatching of Task

static std::shared_ptr<Dispatcher> make(const std::shared_ptr<rclcpp::Node> &node)

Create a dispatcher by providing the ros2 node

See

make()

Parameters
  • [in] node: ROS 2 node instance