Page 225 - The Ultimate Palm Robot
P. 225

Color profile: Generic CMYK printer profile
           Composite  Default screen
                                                      Bots / The Ultimate Palm Robot/ Mukhar & Johnson / 222880-6 / Chapter 8






                    208     The Ultimate Palm Robot



                                   ✖  unsigned char  The unsigned char type represents an unsigned byte.
                                      It has a range of 0 to 255.
                                   ✖  int  The int type represents a signed integer comprised of 2 bytes.
                                      It has a range of –32768 to 32767.
                                   ✖  unsigned int  The unsigned int type represents an unsigned integer
                                      comprised of 2 bytes. It has a range of 0 to 65535.
                                   ✖  string  The string type is a fixed series of ASCII-encoded text characters.
                                  Now we get to the main loop of the program. The first thing that occurs in
                               the loop is that the program calls the aA2D_ReadInt( ) function for each of the
                               three sensors. You can see that the function takes an argument that tells the
                               function which sensor to read. In the chase.tea program, the code uses symbolic
                               constants to refer to each of the sensors. The symbolic constants APPRK_IR1,
                               APPRK_IR2, and APPRK_IR3 are defined in the aPPRK.tea file.

                                 while (1)
                                 {
                                   r1=aA2D_ReadInt(APPRK_IR1);
                                   r2=aA2D_ReadInt(APPRK_IR2);
                                   r3=aA2D_ReadInt(APPRK_IR3);


                                 This is followed by code that sets the value of the variable b based on which
                               sensors detect an object. If one or more of the sensors detect an object, the
                               value of b will be OR’d with 1, 2, or 4, depending on which sensors detect an
                               object. If only a single sensor detects an object, b will have the value 1, 2, or 4.
                               If more than one sensor detects an object, b will have the value 3, 5, 6, or 7. If no
                               sensor detects an object, none of the if statements will evaluate to true and b
                               will remain 0.


                                   b=0;
                                   if (r1>DRANGE) b = b | 1;
                                   if (r2>DRANGE) b = b | 2;
                                   if (r3>DRANGE) b = b | 4;
                                 The code then executes a switch statement based on the value of b. If b is 1, 2,
                               or 4, the program commands the servos so that the robot moves toward the de-
                               tected object. If b is any other value, the default block executes and sets b to 0.












           P:\010Comp\Bots\880-6\ch08.vp
           Monday, May 12, 2003 1:16:45 PM
   220   221   222   223   224   225   226   227   228   229   230