Simple example

In this example, we have four states: A, B, C, and D. This example aims to transition from one state to another on reception of an output. The end result looks like this:

Simple transition between states

Let's look at the code in detail. The complete code is available in this book's GitHub repository: https://github.com/PacktPublishing/ROS-Robotics-Projects-SecondEdition/blob/master/chapter_4_ws/src/smach_example/simple_fsm.py.

Let's look into the code in detail. We will bring in the following import statements, along with the Python shebang file:

#!/usr/bin/env pythonimport rospyfrom smach import State,StateMachinefrom time ...

Get ROS Robotics Projects now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.