CS 1020 - Homework 2 - Improve the follow-line program
Due: Friday, 1/11
- Print out your code from lab 2 and
submit it at the beginning of class on Friday
- Read the reading for class 2 and review the Sciborg code. Make sure you understand what each procedure is doing and how the overall functionality works.
- Improving follow-line
Your goal for Friday, is to turn your ideas from lab 1,
question 4 into reality by writing a better follow-line program. If
you are successful, your Sciborg should be able to run a race like
today's in less than half of the time it takes with the old
follow-line code! Here are some hints:
- Review your notes from class and do the reading to further your
understanding of Handy Logo.
- A common idea is to make the Sciborg do a slight-left turn and a
slight-right turn instead of the hard left and right that it does
under the present algorithm. This can be achieved by changing the
power of the motors (and thus the speed of the wheels). Each motor
has a power range from 0 to 8, where 8 is full power. This is the
default level if none is specified. You can use a command like
left-wheel setpower 4 on thisway
to turn on the left motor at half power (we are using the existing
Sciborg definition for left-wheel here).
If you want to use this strategy, you should define a slight-left and
a slight-right procedure. Experiment with different power levels. (A
good idea here is to define a new global variable "low" and create
procedures called low+1 and low-1, similar to the ones we have for
black, which can be used to change the value of low on the Handy
Board.)
- Keep the two light sensors fairly close together. We will set up
a race course with some long straight sections.
Your Sciborg should detect if both sensors see black, and should be
able to follow those sections in a straight line. If one sensor veers
off the line, however, the Sciborg should do a slight turn the
appropriate way and continue turning until both sensors can see the
line again.
- Think hard about what should happen if neither sensor can see the
line. You may want to introduce a global variable to "remember" which
sensor saw the line last (use the procedure "beep-on-off" from lecture
2 as an example).
- If you feel adventurous (and willing to re-build your car from
scratch - again!), here is an entirely different approach to this
assignment: rather than using a "sciborg" that steers with two powered
wheels and a swivel wheel, build a vehicle more like a tradional car,
with a separate steering mechanism that turns the front wheels (or
single wheel, which is probably easier). You can then attach the
light sensors to this front wheel, extending fowards, and adapt your
program to keep this steerable wheel aligned with the black line.
To power the rear wheels, you could use a single motor and a Lego
differential.
If you're interested in pursuing this approach, please consult with
use for more details and tips. We can also show you an example car.
This is a fairly tricky programming assignment. Be sure to get
started early, ask or email us for help, and also try to get debugging
help from your classmates.
Make sure you document your program well (use comments to explain in
plain English what's going on), and add your names in a comment at the
top. Hand in a printout of your code.
Sciborg Grand Prix
Friday's lab will begin with another race to test your improved
programs - this is your chance to win the coveted Sciborg Grand Prix
trophy. Sciborgs will have to follow a long, slightly curvy line to the end,
make the U-turn and come back to the starting point.
To help with the U-turn, we will add a box at the end of the track. Use
the bump sensor to detect it and do a speedy 180-degree turn.
There will be a
few hazards for cars that stray too far from the line, so your
improved follow-line algorithm should prevent this from happening.
The race course will be set up in the hallway outside our lab.
Make sure your light sensors (and wheels!) can handle the linoleum
flooring.
Besides working on your program, you may also want to improve the
mechanical design of your car, to make it go fast and smooth. One
problem many cars often have is that the coaster wheel doesn't
move freely, which makes it hard for the car to turn. To avoid this
problem, try to keep most of the weight of the car over the main
wheels.
Be sure to have a working car by Friday morning - there will be very
little time for last-minute adjustments.