C++ YASMIN (Yet Another State MachINe)
Loading...
Searching...
No Matches
yasmin_ros::MonitorState< MsgT > Class Template Reference

Template class to monitor a ROS 2 topic and process incoming messages. More...

#include <monitor_state.hpp>

Inheritance diagram for yasmin_ros::MonitorState< MsgT >:
Collaboration diagram for yasmin_ros::MonitorState< MsgT >:

Public Member Functions

 MonitorState (const std::string &topic_name, const std::set< std::string > &outcomes, MonitorHandler monitor_handler, rclcpp::QoS qos=10, int msg_queue=10, int timeout=-1, int maximum_retry=3)
 Construct a new MonitorState with specific QoS, message queue, and timeout.
 
 MonitorState (const std::string &topic_name, const std::set< std::string > &outcomes, MonitorHandler monitor_handler, rclcpp::QoS qos=10, rclcpp::CallbackGroup::SharedPtr callback_group=nullptr, int msg_queue=10, int timeout=-1, int maximum_retry=3)
 Construct a new MonitorState with specific QoS, message queue, and timeout.
 
 MonitorState (const rclcpp::Node::SharedPtr &node, const std::string &topic_name, const std::set< std::string > &outcomes, MonitorHandler monitor_handler, rclcpp::QoS qos=10, rclcpp::CallbackGroup::SharedPtr callback_group=nullptr, int msg_queue=10, int timeout=-1, int maximum_retry=3)
 Construct a new MonitorState with ROS 2 node, specific QoS, message queue, and timeout.
 
std::string execute (std::shared_ptr< yasmin::blackboard::Blackboard > blackboard) override
 Execute the monitoring operation and process the first received message.
 
void cancel_state ()
 Cancel the current monitor state.
 
- Public Member Functions inherited from yasmin::State
 State (const std::set< std::string > &outcomes)
 Constructs a State with a set of possible outcomes.
 
StateStatus get_status () const
 Gets the current status of the state.
 
bool is_idle () const
 Checks if the state is idle.
 
bool is_running () const
 Checks if the state is currently running.
 
bool is_canceled () const
 Checks if the state has been canceled.
 
bool is_completed () const
 Checks if the state has completed execution.
 
std::string operator() (std::shared_ptr< blackboard::Blackboard > blackboard)
 Executes the state and returns the outcome.
 
std::set< std::string > const & get_outcomes ()
 Gets the set of possible outcomes for this state.
 
virtual std::string to_string ()
 Converts the state to a string representation.
 

Protected Attributes

rclcpp::Node::SharedPtr node_
 Shared pointer to the ROS 2 node.
 
- Protected Attributes inherited from yasmin::State
std::set< std::string > outcomes
 The possible outcomes of this state.
 

Private Types

using MonitorHandler
 Function type for handling messages from topic.
 

Private Member Functions

void callback (const typename MsgT::SharedPtr msg)
 Callback function for receiving messages from the subscribed topic.
 

Private Attributes

std::shared_ptr< rclcpp::Subscription< MsgT > > sub
 
std::string topic_name
 
rclcpp::QoS qos
 
std::vector< std::shared_ptr< MsgT > > msg_list
 
MonitorHandler monitor_handler
 
int msg_queue
 
int timeout
 
int maximum_retry
 
std::condition_variable msg_cond
 Condition variable for action completion.
 
std::mutex msg_mutex
 Mutex for protecting action completion.
 

Detailed Description

template<typename MsgT>
class yasmin_ros::MonitorState< MsgT >

Template class to monitor a ROS 2 topic and process incoming messages.

This class provides functionality to subscribe to a ROS 2 topic of type MsgT, execute a custom monitoring handler, and return specific outcomes based on the messages received.

Template Parameters
MsgTThe message type of the topic to subscribe to.

Member Typedef Documentation

◆ MonitorHandler

template<typename MsgT>
using yasmin_ros::MonitorState< MsgT >::MonitorHandler
private
Initial value:
std::function<std::string(
std::shared_ptr<yasmin::blackboard::Blackboard>, std::shared_ptr<MsgT>)>

Function type for handling messages from topic.

Constructor & Destructor Documentation

◆ MonitorState() [1/3]

template<typename MsgT>
yasmin_ros::MonitorState< MsgT >::MonitorState ( const std::string & topic_name,
const std::set< std::string > & outcomes,
MonitorHandler monitor_handler,
rclcpp::QoS qos = 10,
int msg_queue = 10,
int timeout = -1,
int maximum_retry = 3 )
inline

Construct a new MonitorState with specific QoS, message queue, and timeout.

Parameters
topic_nameThe name of the topic to monitor.
outcomesA set of possible outcomes for this state.
monitor_handlerA callback handler to process incoming messages.
qosQuality of Service settings for the topic.
msg_queueThe maximum number of messages to queue.
timeoutThe time in seconds to wait for messages before timing out.
maximum_retryMaximum retries of the service if it returns timeout. Default is 3.

◆ MonitorState() [2/3]

template<typename MsgT>
yasmin_ros::MonitorState< MsgT >::MonitorState ( const std::string & topic_name,
const std::set< std::string > & outcomes,
MonitorHandler monitor_handler,
rclcpp::QoS qos = 10,
rclcpp::CallbackGroup::SharedPtr callback_group = nullptr,
int msg_queue = 10,
int timeout = -1,
int maximum_retry = 3 )
inline

Construct a new MonitorState with specific QoS, message queue, and timeout.

Parameters
topic_nameThe name of the topic to monitor.
outcomesA set of possible outcomes for this state.
monitor_handlerA callback handler to process incoming messages.
qosQuality of Service settings for the topic.
callback_groupThe callback group for the subscription.
msg_queueThe maximum number of messages to queue.
timeoutThe time in seconds to wait for messages before timing out.
maximum_retryMaximum retries of the service if it returns timeout. Default is 3.

◆ MonitorState() [3/3]

template<typename MsgT>
yasmin_ros::MonitorState< MsgT >::MonitorState ( const rclcpp::Node::SharedPtr & node,
const std::string & topic_name,
const std::set< std::string > & outcomes,
MonitorHandler monitor_handler,
rclcpp::QoS qos = 10,
rclcpp::CallbackGroup::SharedPtr callback_group = nullptr,
int msg_queue = 10,
int timeout = -1,
int maximum_retry = 3 )
inline

Construct a new MonitorState with ROS 2 node, specific QoS, message queue, and timeout.

Parameters
nodeThe ROS 2 node.
topic_nameThe name of the topic to monitor.
outcomesA set of possible outcomes for this state.
monitor_handlerA callback handler to process incoming messages.
qosQuality of Service settings for the topic.
msg_queueThe maximum number of messages to queue.
timeoutThe time in seconds to wait for messages before timing out.
maximum_retryMaximum retries of the service if it returns timeout. Default is 3.

Member Function Documentation

◆ callback()

template<typename MsgT>
void yasmin_ros::MonitorState< MsgT >::callback ( const typename MsgT::SharedPtr msg)
inlineprivate

Callback function for receiving messages from the subscribed topic.

Adds the message to msg_list maintaining a maximum queue size of msg_queue.

Parameters
msgThe message received from the topic.

◆ cancel_state()

template<typename MsgT>
void yasmin_ros::MonitorState< MsgT >::cancel_state ( )
inlinevirtual

Cancel the current monitor state.

This function cancels the ongoing monitor.

Reimplemented from yasmin::State.

◆ execute()

template<typename MsgT>
std::string yasmin_ros::MonitorState< MsgT >::execute ( std::shared_ptr< yasmin::blackboard::Blackboard > blackboard)
inlineoverridevirtual

Execute the monitoring operation and process the first received message.

Parameters
blackboardA shared pointer to the blackboard for data storage.
Returns
A string outcome indicating the result of the monitoring operation.

Reimplemented from yasmin::State.

Member Data Documentation

◆ maximum_retry

template<typename MsgT>
int yasmin_ros::MonitorState< MsgT >::maximum_retry
private

Maximum number of retries.

◆ monitor_handler

template<typename MsgT>
MonitorHandler yasmin_ros::MonitorState< MsgT >::monitor_handler
private

Callback function to handle incoming messages.

◆ msg_cond

template<typename MsgT>
std::condition_variable yasmin_ros::MonitorState< MsgT >::msg_cond
private

Condition variable for action completion.

◆ msg_list

template<typename MsgT>
std::vector<std::shared_ptr<MsgT> > yasmin_ros::MonitorState< MsgT >::msg_list
private

List to store queued messages.

◆ msg_mutex

template<typename MsgT>
std::mutex yasmin_ros::MonitorState< MsgT >::msg_mutex
private

Mutex for protecting action completion.

◆ msg_queue

template<typename MsgT>
int yasmin_ros::MonitorState< MsgT >::msg_queue
private

Maximum number of messages to queue.

◆ node_

template<typename MsgT>
rclcpp::Node::SharedPtr yasmin_ros::MonitorState< MsgT >::node_
protected

Shared pointer to the ROS 2 node.

◆ qos

template<typename MsgT>
rclcpp::QoS yasmin_ros::MonitorState< MsgT >::qos
private

Quality of Service settings for the topic.

◆ sub

template<typename MsgT>
std::shared_ptr<rclcpp::Subscription<MsgT> > yasmin_ros::MonitorState< MsgT >::sub
private

Subscription to the ROS 2 topic.

◆ timeout

template<typename MsgT>
int yasmin_ros::MonitorState< MsgT >::timeout
private

Timeout in seconds for message reception.

◆ topic_name

template<typename MsgT>
std::string yasmin_ros::MonitorState< MsgT >::topic_name
private

Name of the topic to monitor.


The documentation for this class was generated from the following file: