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, int msg_queue=10, Node node=None, int timeout=None)
 
str execute (self, Blackboard blackboard)
 
- Public Member Functions inherited from yasmin.state.State
str __call__ (self, Blackboard blackboard=None)
 
str __str__ (self)
 
None cancel_state (self)
 
bool is_canceled (self)
 
bool is_running (self)
 
Set[str] get_outcomes (self)
 

Public Attributes

list msg_list = []
 A set of messages received from the topic.
 
int msg_queue = msg_queue
 The maximum number of messages to retain.
 
float time_to_wait = 0.001
 Time to wait between checks for messages.
 
bool monitoring = False
 Flag indicating if monitoring is active.
 

Protected Attributes

Callable[[Blackboard, Any], None] _monitor_handler = monitor_handler
 Function to handle incoming messages.
 
int _timeout = timeout
 Timeout duration for monitoring.
 
Node _node = node
 The ROS 2 node instance used for subscriptions.
 
str _topic_name = topic_name
 The name of the topic to monitor.
 
Subscription _sub
 Subscription object for the specified topic.
 
- Protected Attributes inherited from yasmin.state.State
Set _outcomes = set()
 A set of valid outcomes for this state.
 
bool _running = False
 A flag indicating whether the state is currently running.
 
bool _canceled = False
 A flag indicating whether the state has been canceled.
 

Private Member Functions

None __callback (self, msg)
 

Detailed Description

MonitorState is a state that monitors messages from a ROS topic.

Attributes:
    _node (Node): The ROS 2 node instance used for subscriptions.
    _sub (Subscription): Subscription object for the specified topic.
    _monitor_handler (Callable[[Blackboard, Any], None]): Function to handle incoming messages.
    _topic_name (str): The name of the topic to monitor.
    msg_list (List[Any]): A set of messages received from the topic.
    msg_queue (int): The maximum number of messages to retain.
    time_to_wait (float): Time to wait between checks for messages.
    monitoring (bool): Flag indicating if monitoring is active.
    _timeout (int): Timeout duration for monitoring.

Exceptions:
    None raised directly; timeout is managed via outcome handling.

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,
int msg_queue = 10,
Node node = None,
int timeout = None )
Initializes the MonitorState.

Parameters:
    msg_type (Type): The type of message to be monitored.
    topic_name (str): The name of the topic to subscribe to.
    outcomes (Set[str]): The set of possible outcomes from the state.
    monitor_handler (Callable[[Blackboard, Any], None]): The function to call with the received messages.
    qos (Union[QoSProfile, int], optional): Quality of Service profile or depth.
    msg_queue (int, optional): Maximum number of messages to store. Default is 10.
    node (Node, optional): The ROS node to use. If None, a default node is created.
    timeout (int, optional): Timeout in seconds for monitoring before giving up.

Returns:
    None

Reimplemented from yasmin.state.State.

Reimplemented in yasmin_demos.monitor_demo.PrintOdometryState.

Member Function Documentation

◆ __callback()

None yasmin_ros.monitor_state.MonitorState.__callback ( self,
msg )
private
Callback function that handles incoming messages.

This method is called when a new message is received on the monitored topic.

Parameters:
    msg: The message received from the topic.

Returns:
    None

◆ execute()

str yasmin_ros.monitor_state.MonitorState.execute ( self,
Blackboard blackboard )
Executes the monitoring state.

This method waits for messages from the monitored topic and processes them using
the specified monitor handler.

Parameters:
    blackboard (Blackboard): The blackboard instance that holds shared data.

Returns:
    str: The outcome of the monitoring process. Returns TIMEOUT if the monitoring
    time exceeds the specified timeout.

Exceptions:
    None raised directly; timeouts are handled gracefully.

Reimplemented from yasmin.state.State.

Member Data Documentation

◆ _monitor_handler

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

Function to handle incoming messages.

◆ _node

Node yasmin_ros.monitor_state.MonitorState._node = node
protected

The ROS 2 node instance used for subscriptions.

◆ _sub

Subscription yasmin_ros.monitor_state.MonitorState._sub
protected
Initial value:
= self._node.create_subscription(
msg_type, topic_name, self.__callback, qos
)

Subscription object for the specified topic.

◆ _timeout

int yasmin_ros.monitor_state.MonitorState._timeout = timeout
protected

Timeout duration for monitoring.

◆ _topic_name

str yasmin_ros.monitor_state.MonitorState._topic_name = topic_name
protected

The name of the topic to monitor.

◆ monitoring

bool yasmin_ros.monitor_state.MonitorState.monitoring = False

Flag indicating if monitoring is active.

◆ msg_list

list yasmin_ros.monitor_state.MonitorState.msg_list = []

A set of messages received from the topic.

◆ msg_queue

int yasmin_ros.monitor_state.MonitorState.msg_queue = msg_queue

The maximum number of messages to retain.

◆ time_to_wait

yasmin_ros.monitor_state.MonitorState.time_to_wait = 0.001

Time to wait between checks for messages.


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