C++ Helper Classes¶
-
template<typename MessageT, typename AllocT = std::allocator<void>>
class OrchestratedPublisher¶ Wrapper class for a LifecyclePublisher. Counts the number of publish calls made since the last counter reset.
- Template Parameters:
MessageT – The type of the message that the wrapped publisher can publish.
AllocT – Allocator
Public Types
-
using PublisherPtr = rclcpp_lifecycle::LifecyclePublisher<MessageT, AllocT>::SharedPtr¶
Type alias for a SharedPtr to a MessageT LifecyclePublisher publisher.
Type alias for an std::shared_ptr to an instance of OrchestratedPublisher.
Public Functions
-
inline explicit OrchestratedPublisher(PublisherPtr publisher)¶
Constructor. Initializes the internal publish counter to zero.
- Parameters:
publisher – Pointer to a LifecyclePublisher instance that performs the actual publishing.
-
template<typename M>
inline void publish(M msg)¶ Publish a message via the wrapped LifecyclePublisher instance, and increments the internal counter.
- Parameters:
msg – The message to publish
-
inline void reset_publish_cnt()¶
Resets the internal publish counter to zero.
-
inline std::size_t get_publish_cnt()¶
Obtain the value of the internal publish counter.
-
inline auto get_topic_name()¶
Returns the name of the topic that the wrapped publisher is publishing on.
-
inline void on_activate()¶
Calls on_activate on the wrapped LifecyclePublisher.
-
inline void on_deactivate()¶
Calls on_deactivate on the wrapped LifecyclePublisher.
-
class OrchestratorHelper¶
Public Types
Type alias for an std::shared_ptr to an instance of OrchestratorHelper.
Public Functions
-
inline explicit OrchestratorHelper(LifecycleNodePtr node)¶
Constructor.
- Parameters:
node – Pointer to a LifecycleNode which will be used to create publishers.
-
template<typename MessageT, typename ...Params, typename AllocT = std::allocator<void>>
inline auto create_publisher(Params&&... params)¶ Creates a LifecyclePublisher wrapped in an OrchestratedPublisher instance.
- Parameters:
params – Any params that shall be forwarded to the create_publisher method of the node.
- Template Parameters:
MessageT – The type of the message that the wrapped publisher can publish.
AllocT – Allocator
- Returns:
The wrapped OrchestratedPublisher instance.
-
template<typename MessageT, typename AllocT>
inline auto wrap_publisher(LifecyclePublisherPtr<MessageT, AllocT> publisher)¶ Wraps an existing LifecyclePublisher in an OrchestratedPublisher instance.
- Parameters:
publisher – Pointer to the LifecyclePublisher instance that shall be wrapped.
- Template Parameters:
MessageT – The type of the message that the wrapped publisher can publish.
AllocT – Allocator
-
template<typename CallbackT, typename ...P>
inline std::function<void(void)> wrap_callback(CallbackT &&f, P&&... publishers)¶ Wraps a ROS callback. Will publish status calls signaling to the orchestrator that a callback has completed if it did not produce any outputs or if any of the passed publishers did not publish during the callback. This is a variant in which the callback takes no parameters (e.g., a timer callback).
- Parameters:
publishers – OrchestratedPublisher instances that can publish messages during the callback
f – ROS callback function which may call publish() on the passed publishers.
- Template Parameters:
CallbackT – Type of the callback
P – Publisher types
- Returns:
The wrapped callback function
Wraps a ROS callback. Will publish status calls signaling to the orchestrator that a callback has completed if it did not produce any outputs or if any of the passed publishers did not publish during the callback. This is a variant in which the callback takes a message as a parameter (e.g., a subscription callback).
- Parameters:
publishers – OrchestratedPublisher instances that can publish messages during the callback
f – ROS callback function which may call publish() on the passed publishers.
- Template Parameters:
CallbackT – Type of the callback
P – Publisher types
- Returns:
The wrapped callback function
-
inline void publish_status(const std::vector<std::string> &omitted_outputs = {}, int debug_id = -1)¶
Publishes a status message for the orchestrator.
- Parameters:
omitted_outputs – List of omitted outputs (topics of publishers that did not publish although it is expected by the orchestrator).
debug_id – An ID for the status message to help debugging the orchestrator. Values less than 0 produce auto-incrementing debug IDs.
-
inline void advertise()¶
Advertises topics.
-
inline void on_activate()¶
Activates internal LifecyclePublishers.
-
inline void on_deactivate()¶
Deactivates internal LifecyclePublishers.
-
inline void on_cleanup()¶
Destroys internal LifecyclePublishers.