Home / Design Lab 1 (Domo Arigato, Mr. Roboto)

Design Lab 01: Domo Arigato, Mr. Roboto

The questions below are due on Thursday February 07, 2019; 09:55:00 PM.
Partners: You have not yet been assigned a partner for this lab.
You are not logged in.

If you are a current student, please Log In for full access to this page.

Music for this Problem


Goals:This lab introduces the 6.01 software and hardware environments. You will work with one of our robots, understand its sonar sensors and motorized locomotion system, and thereby program the robot to position itself in front of a wall.

1) Getting Started

You will work with a partner in this lab. After the fifteen-minute nanoquiz is finished for your section, your partner will be displayed at the top of that day's Design Lab page on the web site. Log out of the laptop you used to take the nanoquiz, and leave it where it is; go to the table indicated by the tutor.

You must use a lab laptop for today's exercises.

  1. Find a lab laptop and a charger. They should be set out at the lab tables already. Mice are available; if you would like one, please ask a staff member.
  2. If the laptop at your table is not already on, connect the laptop to an ethernet cable via USB-to-Ethernet Adapter if it is not already connected, and power it on.
  3. Log in using your Athena user name and password.

Get today's files.

  1. Open a terminal window (press Super+t where Super refers to the Super Key (with Windows symbol)), or use the window that opens upon logging in.
  2. In the terminal window, type the following:

    athrun 6.01 getFiles

    to set up files for today's exercises in your Athena directory (under ~/Desktop/6.01_S19). Upon running this command, you will be prompted to visit a web page and copy/paste a sequence of characters into the terminal.

    Note that on our lab laptops, you can hold "Control" and click the link to open it in a web browser. You should only have to copy/paste this code once this semester. If you are having trouble, please ask a staff member for help.

    These files are also available here, and this lab is available in a printable PDF format here.

You will also need a robot!

  1. Locate a robot (there should be one near your table). It should be connected to a long, gray serial cable and a short blue serial-to-USB adapter. Plug the blue adapter into a USB socket on your lab laptop. Robots are to be kept off of the tables!
  2. Locate one of the colored foam-core boards with bubble wrap on only one side (there should be one at your table). We will use these boards to construct boundaries for the robot to follow.

2) Programming the Robot

We will use a program called soar (Snakes on a Robot) to connect our Python code to either a physical or simulated robot. To see how this works, navigate to a Terminal Window and type the following after the command prompt (including the ampersand1):

soar &

This will activate soar and bring up soar's main console window. Now press Load World to load a virtual world and double-click on wallFinderWorld.py. After this, press Load Brain load a Python robot controller file. Navigate to your designLab01 folder (note that you can type ~ and hit Enter in the file select dialog to reach your home directory) and select the wallFinderBrain.py. Next, click on the Simulator button which will bring up a Simulator window that shows the robot in a virtual world. The eight rays emanating from the robot represent the beams associated with the eight sonar sensors.

Finally, press Play to run the simulation. A stream of numbers that represent the distance to the front wall should be printed in soar's output window. You can use the mouse to drag the robot around in the world. The printed numbers should make sense. Press Stop to finish.

Now look inside the robot brain, as follows. Go back to the terminal window process and type the following after the command prompt (make sure to include the '3'!):

idle3 &

This will open the Python file editor. Press File->Open and navigate to designLab01. Double-click on wallFinderBrain.py. The file contains the definitions of procedures that are used by soar to control the robot. The only non-trivial procedure is on_step, which is run periodically to implement the desired robot behavior.

2.1) Learning the Ins and Outs of SoaR

We will be writing a controller for the robot. Our controller is a software module that is executed 10 times per second. It takes sensor values as input and uses those values, possibly together with some information remembered from previous executions, to compute a desired "action" for the robot.

In our case, the sensor values are obtained from robot.sonars which is a list containing eight numbers that represent the measured distances (in meters) from the eight sonar sensors, listed in order from left to right (from the robot's perspective).

The action is sent to the robot by setting the robot.fv and robot.rv variables 2, which set the desired forward and rotational velocities, respectively. Because the controller is executed so frequently, its job is only to decide how the robot should move for the next tenth of a second.

2.2) Investigating the Sensors

Each of the sonar sensors emits a periodic stream of ultrasonic clicks (10 clicks per second), and calculates the distance to the nearest wall by measuring the time when the first echo is received. The eight sonar sensors operate sequentially (so as not to interfere with each other). The first sonar sensor emits a click and listens for the first echo for a maximum of 10 milliseconds, before passing control to the next sonar sensor (which operates similarly).

Check Yourself 1:
What is the theoretical maximum distance that should be detectable given a 10 millisecond observation window?

Use a foam-core board with bubble wrap to determine the minimum and maximum distances that are measured with the sonar sensors. To connect to a real robot, make sure the robot is powered on. Then, use soar as before, but press the Connect button (instead of selecting a virtual world).

Check Yourself 2:
Note that the soar brain is printing the value of one of the sonars in particular. Which one of the eight sonars is it using?

Check Yourself 3:
What are the minimum and maximum sonar-sensor distances that you found through experimentation? What are the corresponding units?

The sonar sensors work best when the beam hits the wall perpendicularly. If the angle between the beam and wall is too far from perpendicular, then the sonar sensors will fail.

Check Yourself 4:
Estimate the maximum angle that can be tolerated by experimenting with the foam-core board. Is the maximum angle the same for a smooth wall and for one covered with bubble wrap?
  • Max angle for smooth wall:
  • Max angle for bubble wrap:

Which surface works best? Why?

Checkoff 1:
Explain the results of your experiments with the sonars.

3) Race to the Target!

Now that you have some experience with how the robot's sensors work, we will get started on our first task. Start by setting up a pole (a meter stick with a small wooden "foot") two feet in front of a bubble-wrapped foam-core board. Note that the tiles on the floor are exactly 1ft-by-1ft, so you can use those to measure (you can also approximate 1ft using the long dimension of a sheet of paper, which is 11 inches long).

Our goal will be to make the robot smoothly approach the pole until it is touching, without knocking the pole over; we want the robot to do this as quickly as possible.

We will do this by putting the pole two feet away from the wall, and programming the robot to move until it is also two feet away from the wall.

4) Robotic Control

Our goal is to program the robot to smoothly move forward or backward as necessary to adjust its position to be two feet from the wall in front of the robot.

To achieve these goals, we can use the robot's sonar sensors to determine the distance to the wall and then command the robot's wheels to move the robot forward or backward as appropriate.

The on_step procedure in wallFinderBrain.py assigns a value to robot.fv to specify the desired forward velocity (meters/second). Currently, it is always set to 0 (making the robot stand still), but we can adjust that parameter to make the robot move.

4.1) "Bang-Bang" Controller

One strategy for the problem above is to move forward (with a fixed velocity V) when the distance is greater than two feet, and to move backward (with the same speed but opposite direction) otherwise. This strategy is sometimes called "bang-bang" control or "on-off" control.

Modify wallFinderBrain.py to make the robot move forward or backward using bang-bang control to adjust its position to be two feet from the wall in front of it. Debug the brain using the wallFinderWorld.py simulator file.

After it works well in simulation, try it on a real robot. Place a mounted yard-stick two feet away from the "wall" and test whether your robot knocks it over.

DO NOT LET THE ROBOT CRASH! One partner should ALWAYS be ready to lift the robot up off the floor if the behavior goes awry.

WARNING: After making modifications to the brain, it is important to Reload in soar before pressing "Play" again.

Check Yourself 5:
Recall how the robot is making its distance measurements, and note that we are now placing an object between the sonar sensor and the wall it is supposed to be sensing. Are there any potential issues with this? How could you account for them in the physical setup of the world? In code?

Check Yourself 6:
What are some pros and cons to this bang-bang approach? How could you improve this controller, particularly to avoid knocking over the stick? How does velocity (V) correlate with the robot's ability to stay two feet away from the wall?

4.2) Proportional Controller

A more sophisticated strategy is proportional control. In this strategy, the robot's velocity is made proportional to the difference between its desired distance to the wall and its actual distance to the wall. We will call the proportionality constant K the "gain."

Check Yourself 7:
How would you implement a proportional controller using the information available to you in soar?

Comment out3 your bang-bang controller before continuing. Don't delete it! You'll need to keep it around to be able to compare and contrast it with your proportional controller.

Implement a proportional controller by completing the definition of the on_step procedure in wallFinderBrain.py. Test the performance of the controller in simulation. Then use a real robot with a stick placed two feet away from the wall. Does proportional control still knock over the stick?

Checkoff 2:
What are the principal strengths and weaknesses of each of these two control strategies? Explain your preferred method to a staff member, and demonstrate your algorithm on a real robot.

5) Optimizing convergence

In this section we will play with the gain K to optimize convergence of the proportional controller (i.e. how do we get the robot two feet from the wall without knocking over the stick?).

Before continuing, uncomment the line in the on_stop function (found in wallFinderBrain.py) that references PlotWindow. This will cause soar to make a plot every time the simulation is stopped.

Check Yourself 8:
What does the plot represent? What values are represented on the x and y axes? What are their units?

5.1) Simulated behavior

Test your code with the soar simulator in the wallFinderWorld.py. Notice that by adjusting K, we can get drastically different behaviors out of the simulation.

Find three different values of K: one for which the distance converges (approaches a constant value) monotonically, one for which it oscillates and converges, and one for which it does not converge.

Save the plots generated by soar for each of the three behaviors, making note of the gain that led to each behavior.

5.2) Get Real!

Now we will try running on the real robot. Set up the pole to be two feet away from the wall, and place the robot four feet away from the wall.

Check Yourself 9:
Can you use the results of the simulation to help you figure out a good value of K to try to get the robot to quickly and smoothly approach the stick without knocking it over?

Try some different values of K to find the one that causes the robot to approach the stick as smoothly as possible without knocking it over. Make sure to start the robot four feet away from the wall for each trial. Save the plots generated by soar for the gain values you tried, making note of which graph corresponds to which gain.

For each of the gains where the robot converged, estimate (from the graph) how long it took for the robot to reach its goal.

Checkoff 3:
What value of K worked best? How quickly did the robot arrive at its target?


Explain how the real robot differs from the simulated robot. How do these differences manifest themselves in the plots from soar? Show your controller code and plots to a staff member, and discuss which gains generate which results, and speculate why.


1The ampersand character causes soar to run "in the background," freeing the terminal up to accept other commands while soar is running. (click to return to text)

2Documentation for these procedures and more is available from the "Python and lib601" page of the 6.01 web site, by following the link labeled "lib601 Documentation." (click to return to text)

3By "comment out", we mean add a # to the start of every line that you don't want to execute. (click to return to text)