Class Negotiation

Nested Relationships

Nested Types

Class Documentation

class rmf_traffic_ros2::schedule::Negotiation

A ROS2 interface for negotiating solutions to schedule conflicts.

Public Types

using TableViewPtr = rmf_traffic::schedule::Negotiation::Table::ViewerPtr
using ResponderPtr = rmf_traffic::schedule::Negotiator::ResponderPtr
using StatusUpdateCallback = std::function<void(uint64_t conflict_version, TableViewPtr table_view)>
using StatusConclusionCallback = std::function<void(uint64_t conflict_version, bool success)>

Public Functions

Negotiation(rclcpp::Node &node, std::shared_ptr<const rmf_traffic::schedule::Snappable> viewer, std::shared_ptr<Worker> worker = nullptr)

Constructor

Parameters
  • [in] worker: If a worker is provided, the Negotiation will be performed asynchronously. If it is not provided, then the Negotiators must be single-threaded, and their respond() functions must block until finished.

Negotiation &timeout_duration(rmf_traffic::Duration duration)

Set the timeout duration for negotiators. If a negotiator does not respond within this time limit, then the negotiation will automatically be forfeited. This is important to prevent negotiations from getting hung forever.

rmf_traffic::Duration timeout_duration() const

Get the current timeout duration setting.

void on_status_update(StatusUpdateCallback cb)

Register a callback with this Negotiation manager that triggers on negotiation status updates.

Parameters
  • [in] cb: The callback function to be called upon status updates.

void on_conclusion(StatusConclusionCallback cb)

Register a callback with this Negotiation manager that triggers on negotiation status conclusions.

Parameters
  • [in] cb: The callback function to be called upon status conclusions.

TableViewPtr table_view(uint64_t conflict_version, const std::vector<rmf_traffic::schedule::ParticipantId> &sequence) const

Get a Negotiation::TableView that provides a view into what participants are proposing.

This function does not care about table versioning.

Return

A TableView into what participants are proposing.

Parameters
  • [in] conflict_version: The conflict version of the negotiation

  • [in] sequence: The sequence of participant ids. Follows convention of other sequences (ie. The last ParticipantId is the owner of the table)

void set_retained_history_count(uint count)

Set the number of negotiations to retain.

Parameters
  • [in] count: The number of negotiations to retain

std::shared_ptr<void> register_negotiator(rmf_traffic::schedule::ParticipantId for_participant, std::unique_ptr<rmf_traffic::schedule::Negotiator> negotiator)

Register a negotiator with this Negotiation manager.

Return

a handle that should be kept by the caller. When this handle expires, this negotiator will be automatically unregistered.

Parameters
  • [in] for_participant: The ID of the participant that this negotiator will work for

  • [in] negotiator: The negotiator interface to use for this participant

std::shared_ptr<void> register_negotiator(rmf_traffic::schedule::ParticipantId for_participant, std::unique_ptr<rmf_traffic::schedule::Negotiator> negotiator, std::function<void()> on_negotiation_failure)

Register a negotiator with this Negotiation manager.

Return

a handle that should be kept by the caller. When this handle expires, this negotiator will be automatically unregistered.

Parameters
  • [in] for_participant: The ID of the participant that this negotiator will work for

  • [in] negotiator: The negotiator interface to use for this participant

  • [in] on_negotiation_failure: A callback that will be triggered if a negotiation for this participant fails

std::shared_ptr<void> register_negotiator(rmf_traffic::schedule::ParticipantId for_participant, std::function<void(TableViewPtr view, ResponderPtr responder)> respond, std::function<void()> on_negotiation_failure = nullptr)

Register a negotiator with this Negotiation manager using a lambda.

Return

a handle that should be kept by the caller. When this handle expires, this negotiator will be automatically unregistered.

Parameters
  • [in] for_participant: The ID of the participant that this negotiator will work for

  • [in] respond: The callback that will be used as the negotiator’s response

  • [in] on_negotiation_failure: A callback that will be triggered if a negotiation for this participant fails

class Worker

The Worker class can be used to make the Negotiation asynchronous.

Public Functions

virtual void schedule(std::function<void()> job) = 0

Tell the worker to add a callback to its schedule. It is imperative that this function is thread-safe.

virtual ~Worker() = default