Skip to content

Instantly share code, notes, and snippets.

@icyflame
Last active August 29, 2015 14:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save icyflame/dd4775c692e2df6c8bfd to your computer and use it in GitHub Desktop.
Save icyflame/dd4775c692e2df6c8bfd to your computer and use it in GitHub Desktop.
Commands related to the smach library.

ROS

To create a package :-

roscd
roscreate-pkg test rospy
cd test/
cd src/
# add any python source files that you want to run here.

LET :- Created a python file called "main.py"

Before running this python file

Open a new terminal tab and start roscore

For running a python file :-

python main.py 
# from the src directory.

To listen to a topic from the terminal

rostopic echo topicname

SMACH Viewer

Install smach-viewer

sudo apt-get install ros-hydro-smach-viewer

Before using smach_viewer

Copy this code to the end of your python file (Erase outcome=sm.execute() and paste this code :-

sis = smach_ros.IntrospectionServer('server_name', sm, '/SM_ROOT')
sis.start()
outcome = sm.execute()
rospy.spin()
sis.stop()

(This code is under the main() function and NOT under the with sm: block.)

Running smach_viewer

Open a new tab and run :-

rosrun smach_viewer smach_viewer.py

Any Python State Machine running will be automatically updated in the smach_viewer window.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment