![]() |
Viewing State Machines (ROS)
Description: This tutorial shows you how to use the smach viewer, a simple tool to monitor state machines and get introspection into the data flow between states.Tutorial Level: BEGINNER
This is what you want to debug a running SMACH state machine:
The SMACH viewer shows a graphical representation of all the states in your (sub) state machines, the possible transitions between states, the currently active state, and the current values of the userdata. The SMACH viewer even allows you to set the initial state of you state machine. This tutorial teaches you how to start using the SMACH viewer.
Creating an Introspection Server
SMACH containers can provide a debugging interface (over ROS) which allows a developer to get full introspection into a state machine. The SMACH viewer can use this debugging interface to visualize and interact with your state machine. To add this debugging interface to a state machine, add the following lines to your code:
Designating which SMACH trees are which is done by declaring a server_name and a SM_ROOT path. The server name is the name which will be used for constructing the rostopic interface to a given SMACH container root. You should not run two servers with the same name. The root path is a virtual path representing the location in a SMACH container tree. Each container in the container root broadcasts to this single server topic, but included in each message is a path to the relevant container.
For more details on the introspection server, see the API documentation.
1 sm = smach.StateMachine()
2 sis = smach.IntrospectionServer('my_smach_node',sm,'/SM_PATH')
This will traverse the child containers of sm, if any exist, and add ros hooks to each of them. Once the introspection server has been instantiated, it will advertise a set of topics with names constructed by appending to the server name given to it on construction. In this case three topics would be advertised:
/server_name/smach/container_structure
/server_name/smach/container_status
/server_name/smach/container_init
The first two publish heartbeat and event info regarding the structure and status of the SMACH containers served out by "server_name" The third is a topic for setting the configuration of the SMACH tree over ROS.
The "SM_ROOT" argument is simply used for visualization, and forced nesting of different servers.
Running SMACH viewer
Once you have one or more introspection servers running in your ROS system, you can start the smach viewer using:
rosrun smach_viewer smach_viewer
The viewer will automatically connect to all running introspection servers.