Python YASMIN (Yet Another State MachINe)
Loading...
Searching...
No Matches
yasmin_ros.monitor_state.MonitorState Class Reference
Inheritance diagram for yasmin_ros.monitor_state.MonitorState:
Collaboration diagram for yasmin_ros.monitor_state.MonitorState:

Public Member Functions

None __init__ (self, Type msg_type, str topic_name, Set[str] outcomes, Callable monitor_handler, Union[QoSProfile, int] qos=10, CallbackGroup callback_group=None, int msg_queue=10, Node node=None, int timeout=None, int maximum_retry=3)
 
str execute (self, Blackboard blackboard)
 
None cancel_state (self)
 

Public Attributes

list msg_list = []
 List to store queued messages.
 
int msg_queue = msg_queue
 Maximum number of messages to queue.
 

Protected Attributes

Callable[[Blackboard, Any], str] _monitor_handler = monitor_handler
 Function to handle incoming messages.
 
Event _msg_event = Event()
 Event for message reception.
 
int _timeout = timeout
 Timeout in seconds for message reception.
 
Node _node = node
 Shared pointer to the ROS 2 node.
 
str _topic_name = topic_name
 Name of the topic to monitor.
 
Subscription _sub = None
 Subscription to the ROS 2 topic.
 
Type _msg_type = msg_type
 
Union[QoSProfile, int] _qos = qos
 
CallbackGroup _callback_group = callback_group
 
int _maximum_retry = maximum_retry
 Subscription to the ROS 2 topic.
 

Private Member Functions

None __callback (self, Any msg)
 

Detailed Description

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

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

Attributes:
    _node (Node): Shared pointer to the ROS 2 node.
    _sub (Subscription): Subscription to the ROS 2 topic.
    _monitor_handler (Callable[[Blackboard, Any], str]): Function to handle incoming messages.
    _topic_name (str): Name of the topic to monitor.
    msg_list (List[Any]): List to store queued messages.
    msg_queue (int): Maximum number of messages to queue.
    _timeout (int): Timeout in seconds for message reception.
    _maximum_retry (int): Maximum number of retries.
    _msg_event (Event): Event for message reception.

Constructor & Destructor Documentation

◆ __init__()

None yasmin_ros.monitor_state.MonitorState.__init__ ( self,
Type msg_type,
str topic_name,
Set[str] outcomes,
Callable monitor_handler,
Union[QoSProfile, int] qos = 10,
CallbackGroup callback_group = None,
int msg_queue = 10,
Node node = None,
int timeout = None,
int maximum_retry = 3 )
Construct a new MonitorState with specific QoS, message queue, and timeout.

Args:
    msg_type (Type): The type of message to be monitored.
    topic_name (str): The name of the topic to monitor.
    outcomes (Set[str]): A set of possible outcomes for this state.
    monitor_handler (Callable[[Blackboard, Any], str]): A callback handler to process incoming messages.
    qos (Union[QoSProfile, int], optional): Quality of Service settings for the topic.
    callback_group (CallbackGroup, optional): The callback group for the subscription.
    msg_queue (int, optional): The maximum number of messages to queue.
    node (Node, optional): The ROS 2 node to use. If None, a default node is created.
    timeout (int, optional): The time in seconds to wait for messages before timing out.
    maximum_retry (int, optional): Maximum retries of the monitor if it returns timeout. Default is 3.

Member Function Documentation

◆ __callback()

None yasmin_ros.monitor_state.MonitorState.__callback ( self,
Any msg )
private
Callback function for receiving messages from the subscribed topic.

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

Args:
    msg: The message received from the topic.

◆ cancel_state()

None yasmin_ros.monitor_state.MonitorState.cancel_state ( self)
Cancels the current monitor state.

This method cancels the monitor if waiting for messages.

◆ execute()

str yasmin_ros.monitor_state.MonitorState.execute ( self,
Blackboard blackboard )
Execute the monitoring operation and process the first received message.

Args:
    blackboard (Blackboard): A shared pointer to the blackboard for data storage.

Returns:
    str: A string outcome indicating the result of the monitoring operation.

Member Data Documentation

◆ _callback_group

CallbackGroup yasmin_ros.monitor_state.MonitorState._callback_group = callback_group
protected

◆ _maximum_retry

int yasmin_ros.monitor_state.MonitorState._maximum_retry = maximum_retry
protected

Subscription to the ROS 2 topic.

Maximum number of retries.

◆ _monitor_handler

Callable[[Blackboard, Any], str] yasmin_ros.monitor_state.MonitorState._monitor_handler = monitor_handler
protected

Function to handle incoming messages.

◆ _msg_event

Event yasmin_ros.monitor_state.MonitorState._msg_event = Event()
protected

Event for message reception.

◆ _msg_type

Type yasmin_ros.monitor_state.MonitorState._msg_type = msg_type
protected

◆ _node

Node yasmin_ros.monitor_state.MonitorState._node = node
protected

Shared pointer to the ROS 2 node.

◆ _qos

Union[QoSProfile, int] yasmin_ros.monitor_state.MonitorState._qos = qos
protected

◆ _sub

Subscription yasmin_ros.monitor_state.MonitorState._sub = None
protected

Subscription to the ROS 2 topic.

◆ _timeout

int yasmin_ros.monitor_state.MonitorState._timeout = timeout
protected

Timeout in seconds for message reception.

◆ _topic_name

str yasmin_ros.monitor_state.MonitorState._topic_name = topic_name
protected

Name of the topic to monitor.

◆ msg_list

yasmin_ros.monitor_state.MonitorState.msg_list = []

List to store queued messages.

◆ msg_queue

int yasmin_ros.monitor_state.MonitorState.msg_queue = msg_queue

Maximum number of messages to queue.


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