Lab Session 1
Introduction
The aim of this lab is to build a simple robot and to learn how to program
the Handyboard computer. As your robot will have no sensors at
first, it will be
driving "blind", so the first tasks will be fairly
simple. When you have mastered the basics, you can add some
sensors to your robot - you will learn to write programs to use the
information from these sensors next week.
To get you started quickly, we have provided
two simple robot chassis designs - simple frames for holding motors,
wheels and sensors. These are useful for learning how
to program a robot, and experimenting with the various
sensors. You can design a better robot chassis later, when you
have seen what works well and what does not.
When you have built your robot, you will write some
programs to make your robot do basic tasks like driving forward and
backward, and turning. Then you will be ready to attempt the first
challenge...
Build a Robot
Choose one of the two example robot chassis designs below, and
follow the instructions to build it.
To find the parts, refer to the kit pages.
Be careful to use two motors with the same part number - most kits
have one motor which is different from the others!
|
Tankbot - instructions
|
Castorbot - instructions
|
|
|

|
| Tank tracks on each side, each driven by a
separate motor, allow the robot to be driven in a straight
line and turned in its own length. A simple robot to build, will get you
started quickly. |
Two wheels, each driven by a separate motor,
allow rapid turning. A castor wheel supports the other
end of the robot. This is a more complicated robot to build,
but it should be fairly strong if you build it properly. |
Handyboard
The Handy-Board is a small computer. You will use it to control your Robot.
The picture below identifies the parts of the Handyboard
which you need to get started:
| 1 |
on/off switch |
| 2 |
socket for cable to interface and charger unit |
| 3 |
sockets for motors |
| 4 |
START button, used in test programs |
|  |
The Handyboard uses an interface and charging unit, as shown below:
 |
The white cable with telephone-type plugs connects the
Handyboard to the interface unit.
If you are using a laptop computer, you should connect
the computer cable to a serial port on the laptop. If
there is no serial port, ask for a USB adaptor.
If
you are using a desktop computer, the interface unit should be connected
to it already.
The charge switch on the interface board should be in the
"NORMAL" position (at the side towards the
computer cable).
The interface units has three coloured lights to show its
status. When everything is connected correctly, all
three lights should be on. |
Warning:
The charge switch on the interface board should always be set to
"NORMAL". This will charge the battery in the
Handyboard at a reasonable current. The "ZAP!" charge
mode is for emergency use ONLY - it allows a much larger current to
flow, and will destroy the battery very quickly! Do not
use it!
Connecting Motors
Connect a short motor cable to the black part on the top of each
motor on your robot - it does not matter which way around.
Mount the Handyboard on top of your robot.
| Identify the motor sockets on the Handyboard
and connect one motor cable in the socket for MOTOR-1, as
shown in the picture.
Note that each socket has three
holes, but the central one is not used. The motor
numbers are marked near the edge of the circuit board.
Now connect the other motor cable to the socket for
MOTOR-2.
Take note of which motor is on the left side of your
robot, and which is on the right.
|
 |
Interactive C
Run the interactive C software by double-clicking the icon on
your desktop.
If you are using your own laptop computer, you will have to
install the Interactive C software. Follow these instructions.
We
will use Interactive C version 7.0.7 - some of the RoboRugby programs will
not work with later versions.
When Interactive C starts, you will be asked to select the controller
type. Select Handyboard.
If you are asked to select a port,
select com1.
If the system cannot connect to the Handyboard, check that the
Handyboard is switched on, and that all the connections are in
place, then press Retry. If this does not work, ask for
help.
Interaction
To explore the interactive mode of Interactive C, type some
commands in the lower part of the window.
Try printf("Hello C
\n"); Can you see the result in the Handy-Board display?
The display
has two lines of 16 characters, but Interactive C treats them as one
line of 32 characters. Your programs can use it to display results
and let you know what is going on. You may have noticed a small
heart-shaped symbol pulsing in the lower right corner - this
indicates that the Handy-Board is alive and working properly.
Interactive C has some special functions for the Handy-Board.
One
example is the beep() function.
Try it now.
Another useful function is motor(number, speed). The
number refers to the number of the socket where the motor is
connected, in the range 0 to 3. The speed value sets the speed
of the motor. It can range from 100 for full forward speed to
-100 for full reverse, with 0 indicating stop. However, the
motor hardware only allows 7 different speeds in each direction, so
numbers close
together will give the same speed.
The meaning of forward and reverse depends on which
way around you connect the motor cables to the Handyboard and to the
motors. It also depends on which face you regard as the front
of your robot. Try running each motor forwards to see which
way it turns. If it is not the way you want, reverse the motor
plug in the Handyboard socket.
Writing a Program
The interactive mode is convenient for checking values from
sensors, or turning on a motor to see which way it turns. However,
to do anything more complicated, you will have to write a program.
Open a new program file now using the button near the top left
corner, or the File menu.
Type the following program. Try to figure out how it works as
you type it. You don't need to type all the comments, but do read them.
void main()
{
printf("Press START\n"); // print a message for the human
start_press(); // wait for the START button
to be pressed
motor(1,50); // run motor 1 at half speed
forwards
motor(2,50); // run motor 2 at half speed
forwards
sleep(1.5); // do nothing for 1.5 seconds - motors stay running
alloff(); // turn off all motors
printf("Stopped\n"); // print another message for the human
}
Save your program, using the button on the toolbar, or using
the File menu, or by typing Ctrl-s on the keyboard, as you prefer.
If you are using one of the desktop computers, save it in My
Documents\RoboRugby. Give it some
sensible name.
Now, press Check at the top of the IC window. Are there any
errors? If so, fix them. Ask for help if necessary.
When all is well, press Download. If
everything is connected correctly, your program will be
transferred to the memory on the Handyboard.
Press Run Main to run the program. Does it behave as you expected?
If not,
why not? Ask for help if you cannot sort this out quickly!
When all is well, you can disconnect the white cable from the
Handyboard, and run the program independently. Just switch off
the Handyboard, then switch it on again - it will automatically run
the last program downloaded.
Task 1
Write a program (or modify the one above) to make your robot
drive forwards some convenient distance, and then reverse the same
distance. You can test this on the laboratory bench or on the
floor. Does your robot arrive back where it started?
Task 2
Write a program to make your robot drive forwards as above, then turn
around and drive back to where it started.
Challenge 1
When you have completed the tasks above, you should be ready for
the challenge:

We will place two balls on each of the RoboRugby tables, in the
places circled in the picture. Your robot should start in the small scoring area
at one end of the table, facing any direction you like.
It must drive to the small scoring area at the other end of the table,
touching both balls on the way.
It does not matter what path your robot follows, as long as it touches both
balls and stops in the right place.
You have to write a program to make your robot do this.
Remember the basic principles - first decide what you want
your robot to do (the algorithm), then translate this into a
computer program. You will have to submit this program for
assessment, so write it properly, using the techniques which you
have been shown. Use plenty of comments to explain what is
going on.
This challenge is quite hard - your robot is relying on
"dead reckoning", as it has no sensors to guide it.
There will always be some slip between the tyres or
tracks and the table, and this may be partly random. This
means that your robot may not follow exactly the same path every
time you try it.
Do not spend too much time trying to perfect
this - the point of the exercise is to learn how to write a program,
and to learn that dead reckoning is not very reliable! Your
next step will be to add some sensors to your robot, so that it can
get some information about its surroundings.
Report
Add a large comment at the start of your program for Challenge
1. This should explain who you are, what your program was
supposed to do, and how well it did it. This report can be
quite short, but it must provide enough information so that we can
make sense of your program. An example is shown below:
/* RoboRugby*08 Team 2: Joe Bloggs, Jane Doe,
Dara Murphy. Challenge 1 report.
We planned to have our robot start in the small scoring area, facing towards
...
We wanted it to travel straight to ... and then ...
...
Finally, we wanted it to stop in the other scoring area, facing the
wall.
We found it quite difficult to achieve this perfectly, as the robot
seemed to blah blah blah. We settled
on a compromise turning time, blah blah blah.
However, blah blah blah...
The basic algorithm is:
Drive forwards for ...
Turn left through ?? degrees;
etc., ...
We connected the motor on the left side of our robot as motor
1,
and the motor on the right side as motor
2.
*/
Submit your report and program by e-mail, to roborugby@ee.ucd.ie.
Add the entire .ic file as an attachment - NOT in the body of the
e-mail. The deadline for submission is 9am on Friday 25
January. We suggest you do it now - one team member can write
the report while the others work on adding sensors to the
robot. However, the entire team will be assessed on the basis
of this report, so you should all check that you are happy with it
before you submit it.
When you have finished, be sure to save a backup copy of your
work. Copy it onto a memory key, or e-mail it to
yourself. It is important to get into the habit of keeping a
backup copy of all your hard work - losing your competition program
later in the semester could be a disaster! Ask for help if necessary.
Adding Sensors
The next step is to add some sensors to your robot, to give it some
information about its surroundings. Small switches can provide
information about collisions with the walls or other
obstacles. An optical sensor can detect the white lines on the
table. Next week, you will use this
information in your programs, to control how the robot behaves.
Bump Detection
In bag
Y, you should have a set of five small switches, called micro-switches.
These are mounted on Lego bricks, in various configurations, as
shown:

The switches are operated by a metal lever - three have short
levers, and two have long levers. You can use these switches to detect when your robot hits an
obstacle, such as the wall or another robot. For this
exercise, you only have to detect collisions at the front of your robot, but you may need to watch your back in the competition!
With
a switch on each front corner you can tell which corner of your robot has hit
an obstacle, which will help you to decide how to get away from the
obstacle.
You can detect
collisions over a larger zone by
building a Lego bumper. The picture shows an
example, using bent beams or lift-arms,
with the short-lever micro-switches mounted behind. Another beam
across the front restrains the moving parts, and stops them swinging
too far forward. It also ensures that a switch will be
operated even if the robot hits a narrow obstacle in the centre.

Add switches
Fit two switches to the front of your robot. We recommend
that you use a Lego bumper - it need not be as complicated as the
one shown.
Connect the switches to two of the digital input ports on the
Handyboard. These are the ports numbered 7 to 15 at the front
of the Handyboard, as shown below. We suggest that you avoid
port 8, as it will be needed for another sensor later. Keep a
record of the port to which each switch is connected.

Each port has three terminals, two together at the front and one
further back, as shown below (left and centre). In the Handy-Board circuit, there is a 47 kohm pull-up
resistor connecting the input terminal to the +5V supply, as shown
(below right). This means that the voltage at the input
terminal will be high (5V) if nothing is connected.
The switches are connected between the input and 0V terminals
(dashed lines above). Each switch is normally open
(open-circuit), so the voltage at the input terminal will be high,
as if nothing was connected. When the lever is pressed, the
switch is closed (short-circuit), so the voltage at the input will
be low (0V). The Handyboard maps the low voltage to binary 1,
and the high voltage to binary 0.
To test the switches, use the interactive mode in Interactive
C. With your Handyboard connected to the computer, type the
command digital(9) - replace the
number 9 with the number of a port where a switch is
connected. This command gets a binary value from the port -
either 0 or 1. You should see the result in the upper part of
the window.
What value do you get when the switch is not pressed? What
value do you get when the switch is pressed? Repeat these
tests for the other switch.
Line Detection
The RoboRugby table surface is mostly matt black, with reflective
white lines. It will be useful to be able to detect these
lines, and perhaps to follow them. You can do this using an
optical sensor of the type shown below left. You will find one
in bag Z. See the optical
parts page for details of how it works.
The sensor emits infra-red light and can detect reflected
infra-red light. It works best when the reflecting surface is
5 to 10mm from the sensor. Use insulating tape to install the sensor temporarily on your
robot, somewhere near the front. It should be facing
downwards, close to the table, but not so close that it hits the
raised lines around the scoring areas.
To use it, you should connect it to
one of the analogue input ports on the Handyboard, as shown above
right. Ports 0 and 1 are not available, and ports 4 and 5 have
been modified for other sensors, so you should use port 2 (as in the
picture) or 3 or 6.
The analogue ports measure the voltage of the input signal, in
the range 0 to 5V, and convert it to an integer in the range 0 to
255. To test your sensor in interactive mode, just
type analog(2) (or
similar - use the correct port number).
The result should be in the range 0 to 255, depending on what is in front of the sensor.
Try it with the sensor "looking" at a sheet of white
paper, and then looking at something dark, or with nothing near the
sensor. If all is well, there should be a significant
difference between the numbers that you see.
Tidying
Before you leave the laboratory, please put all your Lego parts
and your robot into the large plastic box provided.
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!
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.
|