Class Negotiation

Nested Relationships

Nested Types

Class Documentation

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

worker[in] 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:

cb[in] 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:

cb[in] 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.

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

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

Returns:

A TableView into what participants are proposing.

void set_retained_history_count(uint count)

Set the number of negotiations to retain.

Parameters:

count[in] 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.

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

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

Returns:

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

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.

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

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

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

Returns:

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

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.

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

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

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

Returns:

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

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