-
Notifications
You must be signed in to change notification settings - Fork 58
Smach: General Overview
sudo apt-get install ros-hydro-smach
As Smach is a Python Library, the files have an extension .py
.
Running a python file which has code using the Smach library is simple. The steps are as so:
- Create a new package with
smach
androspy
as dependencies:roscreate-pkg test rospy smach
- Change into the
src/
directory and create a.py
file (saytest.py
) - For running this file, simply use
python test.py
If the code is properly written, you will see the desired output.
Suggestion: Start with this tutorial
-
Smach is a Library for python, which is independent of ROS. (as per the official wiki)
-
Smach is a library for creating state machines. But there are many more containers, apart from a finite state machine, that Smach supports. One of these containers, the Concurrence container is important, as it allows us to make decisions about the next state that state machine will transition to, on the basis of the outcomes of more than one state.
There is an inbuilt tool called the smach-viewer which can be used to view the state diagram of a state machine that we have written.
sudo apt-get install ros-hydro-smach-viewer
Running the command rosrun smach_viewer smach_viewer.py
will open a window in which on setting the proper root, you will be able to see the state machine that is currently running.
Note that this code needs to be added to the .py
file that contains the state machine before you can start using smach-viewer:
sis = smach_ros.IntrospectionServer('server_name', sm, '/SM_ROOT')
sis.start()
outcome = sm.execute()
rospy.spin()
sis.stop()
This code creates an IntrospectionServer
and starts this server before executing the StateMachine
code.