Lab Session 4
Introduction
If you have not yet completed Challenge 3 from last
week, you should do this now. If you are having trouble with
programming concepts, ask a demonstrator for help - it is important
to understand these concepts now!
Your first task in this session is to learn how to find balls on the RoboRugby
table, using distance sensors. You will have to write programs to use
the information from these sensors to control how the robot behaves.
When you have completed the challenge, you can check out the the servo
actuator - you may find this useful in your competition robot.
We will be expecting a high standard of programming in this
session - it is more important to get it right than to get it
finished! There will be time on Monday afternoon next week to finish the tasks from this session if necessary.
The deadline for report submission is long enough to allow for this.
Distance sensors
| Find the distance sensors (bag
Z) and add them to your robot. One sensor should be about 20mm above the table surface -
in line with the centre of a ball. The other sensor
should be either above the first or to one side or it, far
enough away so that only one sensor at a time will
"see" a ball. If you decide to put the
second sensor above the first, you should keep it low enough
so that it will "see" the walls of the
table. Keeping it low should also reduce interference
from the beacons.
It is important that the beam of light from the sensor is
horizontal, or pointing slightly upwards - if it is pointing
down, it will be reflected by the table surface, and cause
problems.
Distance sensors can only be connected to analogue ports 4 and
5 on the Handyboard. Details of how the sensors work
and possible interference problems are on the distance
sensor page.
|

|
Task 1
Download the dist-sensor-test.ic
program. Use it to test your distance sensors on the RoboRugby
table, at various distances from a wall and from a ball. Write
down the values from the sensors - you will need them later.
Also note the difference between the two values - this may be useful
in deciding whether a ball is present.
You should also try to get some idea of how reliable are the values
from the sensors, or
how much random variation you see.
As interference from the beacons is a possible cause of variation
in the distance sensor values, make sure to do some tests with your
robot facing a beacon (and with the beacons switched on).
Task 2
Choose a suitable criterion for your robot to use to decide if a
ball (or other small object) is in front of it. Download the
ball-find.ic program, and
modify the ball() function to include your chosen criterion.
Note that this
program has very basic algorithms for ball-hunting, with no safety
features. It also includes two different algorithms - you only need one of
them! Experiment to see which algorithm works better for your robot.
Test your program on the table, with the beacons switched
on. Modify it as necessary to get reliable detection of balls
at various distances from your robot. When your robot is able
to detect balls reliably, you can improve the algorithm to add a
double-check, time limits and other safety features.
Challenge 4
Program your robot to look for balls on the RoboRugby
table. When it detects a ball, it should drive towards it and
hit it, to prove that it was pointing in the right direction.
Then it should turn through 180 degrees and drive away to start looking
for another ball. It should keep doing this until the
STOP button is pressed.
That is the basic requirement for challenge 4. To improve
your program, and make it more useful for the competition, you could add
these features:
- Print messages on the display, and/or make beeps or tones, to indicate what
your robot is doing.
- If your robot is turning around, looking for a ball, but cannot
find one, it should give up after a reasonable time and drive away
to another part of the table.
- When your robot is driving on the table, either to hit a ball or
to move to a new location, it should monitor the switches, and
react appropriately if it hits something bigger than the ball.
- When your robot is driving towards a ball, it should only drive far
enough to hit it.
When this program is working, show it to one of the staff in the
lab, and get your team number recorded.
Servo Actuator
The servo actuator allows you to position some part of your robot
very precisely. For example, you could use it to move some
part of your robot to a different position at some point during a
match. You can find the servo actuator in
bag X.
See the servo actuator page for details
of what it can do and how to use it.
Task 3
The position of the servo actuator is controlled by setting a
variable to a suitable value - an integer in the range from some hundreds to a few thousand. Each servo will operate over a
slightly different range of values, and it is important not to try
to drive the servo actuator beyond its limits - it can damage itself trying to reach an impossible
position!
The aim of this task is to find the limits of your particular
servo actuator - you will need these values later, if you decide to
use the servo in your competition robot.
First attach some Lego parts to the rotating wheel of your servo
actuator, so that you can see clearly when it rotates. There
is no need to attach the actuator to your robot for this test.
Switch off your Handyboard and connect the servo cable to servo port 0 -
the black wire should be on the left, nearest to the on-off switch,
as shown in the picture above right. Caution: connecting this
cable incorrectly will destroy the servo actuator!
Download the servo-test.ic
program and run it on your Handyboard. When you press the
START button, the servo actuator should start moving through a
pre-determined arc. If you press the STOP button, you
can then adjust the position of your servo actuator, in steps of 20, using the START and STOP
buttons. Use this facility to find the limits of movement of your
servo. Be conservative - if your servo seems to stop moving at
a value of 660, take the lower limit as 680 or 700. Record the upper
and lower limits for future use.
Report
Add a large comment at the start of your program for Challenge 4.
This should explain who you are, what your program was
supposed to do, and how well it did it. It should also explain
which port you used for each sensor and motor, if they are not
clearly defined using #define.
Your report must provide enough information so that we can
make sense of your program. The program itself should have
plenty of comments to help with this, and should be well laid out
and easy to read.
You can work on the report outside the laboratory - any text
editor, such as Notepad, can open the program file and allow you to
add comments. The deadline for submission is 10am on Tuesday
16 February. One submission from each team is sufficient,
but the entire team will be assessed on the basis
of this report and program, so you should all check that you are happy with it
before you submit it.
You can submit your report electronically, to the
Digital Dropbox in Blackboard,
with your team number in the name of the submission. If you prefer, you can print the report and program and submit on
paper (stapled pages please) before you leave the laboratory.
Tidying
Disconnect the white cable from the Handyboard, and make
sure that the Handyboard is switched off. These
two steps are necessary to prevent the Handyboard battery from being
discharged over the next few days. We will charge these
batteries for a few hours before the laboratory session next week,
but there will not be time to re-charge them fully if you let them
discharge completely!
Put all your Lego parts
and your robot into the large plastic box. Make sure the robot
is accessible in the box, so that the Handyboard battery can be
charged later. Check the desk and the floor for stray pieces
of Lego - you may need them for your competition robot! Please
do not put balls, tools or tape into your box.
If you were working at a desktop computer, you can leave the
interface and charging unit on the desk. If you were using a
laptop computer, please disconnect the interface and charging unit
from the computer, and put it and the power supply unit into the box
with everything else.
|