roscd roscreate-pkg test rospy cd test/ cd src/ # add any python source files that you want to run here.
Open a new terminal tab and start roscore
python main.py # from the src directory.
rostopic echo topicname
sudo apt-get install ros-hydro-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.)
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.