Page 224 - The Ultimate Palm Robot
P. 224
Color profile: Generic CMYK printer profile
Composite Default screen
Bots /The Ultimate Palm Robot/ Mukhar & Johnson / 222880-6 / Chapter 8
Chapter 8 Taking Control of the BrainStem Robot 207
int r2;
int r3;
The variable b tracks which sensor detected an object. The variables r1, r2,
and r3 hold the readings from sensors 1, 2, and 3.
This is followed by two sleep commands. The purpose of the
aCore_Sleep(int) function is to pause the program. The time that the program
pauses is given by the int parameter. This parameter specifies how many
ten-thousandths of a second that the program pauses. So, to pause for 1 sec-
ond, you pass the value 10,000 to the subroutine. In the code, the program
waits for 3 seconds, then 2 seconds, for a total wait time of 5 seconds.
/* five second wait before starting */
aCore_Sleep(30000);
aCore_Sleep(20000);
The Robot Geek Says
The Big Sleep
You might be wondering why the chase.tea source code uses two
calls to the aCore_Sleep(int) function, rather than:
aCore_Sleep(50000);
The reason is that TEA uses both signed and unsigned int parameters.
The parameter for the sleep function is defined to be an int. The range
for signed int parameters is –32768 to 32767. Thus, the largest number
you can use for aCore_Sleep is 32767. If you need the robot to sleep for
more than 3.2767 seconds, you will need to use multiple function calls.
TEA uses the following data types:
✖ void The void type represents no data. It is typically used to show
explicitly that there is no return value from a routine or no parameters
for a routine.
✖ char The char type represents a signed byte. It has a range of –128
to 127.
P:\010Comp\Bots\880-6\ch08.vp
Monday, May 12, 2003 1:16:45 PM