Vacuum Cleaner (a). Bump&turn
- Carlos Caminero
- 15 nov 2020
- 2 Min. de lectura
Actualizado: 21 nov 2020
In this proyect, we will create a simple finite state machine for the vacuum cleaner world.
A finite state machine is an encapsulation of a sequence of actions that are repeated in a specific way adapted to the environment. It behaves in a similar way to a graph, where a state, given an external / internal factor, can cause a change towards another state (son) and the sequences of states are carried out within an infinite loop
For the vacuum Cleaner, the states will be:
GO FORWARD (GF)
GO BACKWARD (GB)
TURNING (T)
1 -> We start in GO FORWARD state with a constant velocity.
If a crash ocurred in bumper's robot or the laser detects an obstacle less than 0.1 meters, we change state 1 to 2 (GF -> GB).
2 -> While vacuum Cleaner is in state 2, we will be going backward during 1 second with a constant velocity, and then, we will change state 2 to 3 (GB -> T)
3-> In state 3, we will be turning with a random angular velocity during 3 seconds, and then, we will change state 3 to 1 (T -> GF) and we will repeat the previous states beginning in state 1 in a infinite loop.
In this picture, You can see how the sequence of states is organized (timers in the graphic have been omitted):

We have used Python for developing the states machine. For the measurement of the time, we have used rospy module from ROS middleware, and its function get_rostime(). Before the beginning of a state, we measure the current time and save it in for example "start_time", "begin_clock" type variable and then, within the new state, we measure in each iteration the current time ("end_time", "end_clock"...) until the subtraction is greater or equal to the wanted time.
In this video, you can see the Vacuum Cleaner using my finite states machine version:
Comments