REVIVING AN ANDROBOT BOB: Part 4
Chassis with electronics installed.
will go to the SX48 co-processor. Then, it sends the
appropriate command (“L” for the chest lights or “F” for
the footlights), followed by the bit pattern to display.
Next would be functions for controlling the head. The
co-processor makes this fairly easy since we just tell it what
to do and don’t have to worry about the details. Some of
the commands dealing with the head movement are:
HEAD_MOVE(hdegrees);
HEAD_HOME();
HEAD_CLEAR();
HEAD_BUSY();
// signed position in half
// degrees (90 = 45 degrees)
// return head to home position
// (pointing forward)
// Clear HdErr flag on copro
// (in case head moved);
// Return the status of the head
// (busy moving or not)
These each use the select_SX(); to ensure the
commands go to the SX48 co-processor and then send the
command and any required parameters. If we want to
make the head move 45 degrees to the right, we just use
HEAD_MOVE( 90); where 90 is the number of degrees
times 2. A value of - 90 would send it 45 degrees to the left.
If we are moving the head to take sonar readings, we can
ENGINEERING A POLITE
CONVERSATION
Interactive-C on the Handy Board can support multiple
processes. It is important to ensure that only one process
talks to the SpeakJet and SX48 co-processor at a time.
Otherwise, the processes may end up talking to these at
the same time and clobber the communications. To avoid
this, you can talk to them through a single process.
Another option is to have some global flags defined in your
code so that each process can check to see if it is safe to
communicate with the SpeakJet and SX48 co-processor.
64 SERVO 05.2008
use the HEAD_BUSY(); function which can tell us if the
head is still moving or not. The HEAD_CLEAR(); function
will clear the flag which we use to determine if someone
moved the head manually.
There are also some low-level routines for the SpeakJet
which send out a phonemes string for the speech, check to
see if the speech is active (still speaking), and another that
will make random R2-D2 sounds:
SAY(stringpointer); // Say the string pointed to
// (terminated by 255)
SPEECH_DONE(); // returns 0 if speaking or
// 1 if done
RESET_SPEECH(); // sends code to SpeakJet to
// reset speech parameters
SET_SPEECH_RATE(speed); // Sets the speed of the speech
SET_VOLUME(volume); // Sets the SpeakJet volume
R2(); // Make a few beeps like R2-D2
All of these start by using the select_SJ(); function to
make sure the phonemes all go to the SpeakJet instead of
the SX48 co-processor.
Next would be some core routines for using the main
drive motors. These use the built-in motor control features
of the Handy Board. Currently, they use a time delay to
determine distance, but they will eventually be revised to
incorporate closed loop control using the encoders for more
accurate movements. Some of the BOB-specific movement
routines are:
FWD(distance); // distance is float value in inches
BACK(distance); // distance is float value in inches
LEFT(degrees); // turn left in degrees
RIGHT(degrees); // turn right in degrees
GO_ANGLE(degrees); // uses LEFT(); or RIGHT();
// depending upon sign of angle
With these building blocks, we can now combine the
built-in Handy Board libraries and the BOB-specific code to
start building more interesting routines which will give BOB
some character. Below are some examples:
SAY_NUM(value); // Say the signed integer value
SAY_COMP(); // Say the compass position
SAY_SONAR(sensor); // Take sonar reading and speak
// the value
// Make following speech fast
// Make following speech slow
// Test that turns head and takes sonar
// readings along the way
CHESTDEMO(); // Cycle the lights back and forth on
// chest lights
TALK_FAST();
TALK_SLOW();
SCAN_TEST();
As mentioned previously, one of the aspects of
Interactive-C that I really like is the interactive part. It makes
it easy to try out new routines and see how they work
before adding them into the main program. It is also nice
for demonstrating the robot as new routines can be written
on-the-fly. Some examples of this scripting:
Continually flash the two inner LEDs on chest panel: