Design Lab 01: Domo Arigato, Mr. Roboto
If you are a current student, please Log In for full access to this page.
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.
- 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.
- 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.
- Log in using your Athena user name and password.
Get today's files.
- Open a terminal window (press
Superrefers to the Super Key (with Windows symbol)), or use the window that opens upon logging in.
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.
You will also need a robot!
- 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!
- 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):
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.
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'!):
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.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 SensorsEach 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).
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).
soarbrain is printing the value of one of the sonars in particular. Which one of the eight sonars is it using?
- Max angle for smooth wall:
- Max angle for bubble wrap:
Which surface works best? Why?
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.
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.
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
soar before pressing "Play" again.
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."
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?
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
PlotWindow. This will cause
soar to make a plot every time the simulation is stopped.
5.1) Simulated behavior
Test your code with the
soar simulator in the
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.
soarfor 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.
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.
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
Show your controller code and plots to a staff
member, and discuss which gains generate which results, and