Assignment 5
Love/Hate Vehicles
Description
In this lab we will write a program to simulate the robot described in Chapters 2-4 of Braitenberg's book Vehicles.
You will be using light sensors attached to Input 1 and 3 for this assignment. Place a 1x16 rail on the front of your bot, directly in front of the connecting pads for the light sensors. Then attach the left and right sensors to the left and right extremes of the rail. The sensors should be angled downward.
You will write a program that makes the robot turn away from light when each sensor is connected to the input terminal on the same side as the sensor, and turns toward light when sensors are cross connected. Your robot should be able to change its behavior from light loving to light avoiding by either a simple change in the program code or a simple change in light sensor connections.
Devise a transform() function that will be map a light sensor value to an appropriate value for motor power. You can modify the code shown on page 26 of the Programming Lego Robots using NQC document (Overmars, 1999) in order to produce a speed rather than a power setting to the motors if you want a larger dynamic range than 0-7. Be careful if you do this; it's not wise to spend too much time wait()ing when your robot is moving around, if you want it to be responsive to changes in light. Make sure your transform function provides appropriate values (in the appropriate ranges) even if the light sensors produce values that are larger or smaller than you anticipate.
The differences between the sensor readings depends on the placement of the sensors as well as the distance from the light source. The data you collected in Assignment 4 will give you an idea of the average reading of the sensor and average difference in the reading. This will help you in coming up with the function for your motor power or speed.
You should work to find a transform function which produces the most responsive "love" robot you can make. Your robot will be graded on how responsive it is. Responsiveness is measured from two distances.
- Far - The robot will be placed two feet away from the light, pointed at the light, and then moved one foot to the left of the light, without rotating the robot (ie the robot will no longer point at the light). Your goal from this distance is to get the midline of the robot to pass within at least 5 inches of the mid-point of the light. Even closer is better.
- Near - The robot will be placed one foot away from the light, pointed at the light, and then moved one foot to the right of the light, without rotating the robot (ie the robot will no longer point at the light). Your goal from this distance is to get the midline of the robot to pass within at least 9 inches of the mid-point of the light. Even closer is better.
The light will be 1 foot above the table.
Optional part
The programs you just wrote for Love and Hate map values from one sensor to one motor, independent of the other sensor; This is the kind of robot that Braitenberg describes in the chapters you read. You can imagine, however, a program that looks at BOTH sensors to determine the speed for a motor (Braitenberg discusses such programs in later chapters, but not in the context of love/hate).
Try to write such a program. Then, briefly discuss in the comments of that program the relative performance of the two approaches, and your analysis of them. If you "optional" love/hate program works better, you can use it for the performance tests described above. Be sure to turn in both versions of your code though.
Assignment submission details
- Place all of your code in a file called LoveBot_<UCID>.nqc (Teams should use <UCID_UCID>).
- Write a very brief set of comments at the top of the file documenting your progress (e.g. showing experiments you did to show the code working), and anything else you want to communicate about the assignment.
- Attach this file to an Email message, with the subject the same as the name of the file attached, and send this email to cg8w1@icogsci1.ucsd.edu no later than Sunday, February 18 at 11:59 pm.
Demonstrations
For this assignment, you will need to demonstrate the performance of your robot (as described above). The two possible times are during Max's office hours (Friday 1-2) or on Monday between 10:30 and 12:30. Only one of the team members is required to demonstrate your robot's performance. If no one can make it to any of these times, contact cg8w1@icogsci1.ucsd.edu to make other arrangments.
Hints/Recommendations
- If you are specifying motor power, note that in order to see a noticeable turn, the motors' power levels should at least be 3 units apart.
- Make sure the code you submit is well documented, since this will make it more likely the graders will understand what you were trying to do.