Wall Bumping and Finite-State Control

Today

  • Wall Bumping and Finite-State Control
  • Studio Time

For Next Time

  • Finish the the Warmup Project (due next Monday, the 28th).

Solutions for Today

  • The solutions can be found in the upstream comprobo20 Github repository (do git pull upstream master from your comprobo20 directory).
  • If you want to view the code on the web, the two solution files are available here.

Wall Bumping and Finite-state Control

Sometimes you want your robot to switch between multiple behaviors. One very simple architecture for this is to use something called finite-state control. The idea is that your robot can be in one of a finite number of states. Each state prescribes a different pattern of behavior for the robot. The robot transitions between states using various rules.

As an example, let’s consider a robot that can be in one of three states:

  1. moving forward
  2. moving backward
  3. rotating left

Each state prescribes a very easy to program behavior. In each case depending on the robot’s state we would either drive forward at a fixed velocity, drive backward at a fixed velocity, or rotate left at a fixed velocity.

Let’s say that our robot starts in the moving forward state. We can now define a series of rules for transitioning between the states based on the Neato’s sensors.

moving forward

  • if any bump sensor becomes activated, change state to moving backward.
  • otherwise, stay in the moving forward state

moving backward

  • if the laser scanner determines that the obstacle obstacle in front of the robot exceeds a specified distance threshold, change state to rotating left.
  • otherwise, stay in the moving backward state.

rotating left

  • if the current time is more than 1 second greater than when the robot started rotating left, change state to moving forward.
  • otherwise, stay in the rotating left state.

What would the behavior of this robot be? Do a quick whiteboard based simulation to probe the robot’s behavior in various situations. What range of behaviors would the robot exhibit.

With your partner, implement a ROS Python node that realizes this behavior. For the timing task, consider using the rospy.sleep function (a while loop could also do the job). Our solution uses rospy.sleep.

An implementation of this as a ROS node can be found in the upstream comprobo20 github repository under in_class_day05_sample/scripts/finite_state_example.py (here is a link to code on the course website).

Extension (optional)

Check out the tutorials for the smach ROS package Use smach to either rewrite your finite state controller to use smach, or devise a new finite-state controller and implement it using smach.

We have adapted the example from earlier to use the smach package. The code can be found in the comprobo20 upstream repository under in_class_day05_sample/scripts/finite_state_example_smach.py (here is a link to the solution on the course website).

To use the smach viewer, unfortunately requires quite a bit more work. We’re not even sure it can be done using Python3 in ROS Noetic. We tried for a while and gave up… If you get it working let us know! It will probably work in ROS melodic.

It might also be worth checking out FlexBE, which is a more up to date tool for creating state machines (that uses smach internally). We have no experience with it though.