Page 226 - The Ultimate Palm Robot
P. 226

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  209



                                        switch (b)
                                        {
                                          case 1:
                                            aPPRK_Go(0,SPEEDL,-SPEEDL,0);
                                            b=1;
                                            break;
                                          case 2:
                                            aPPRK_Go(-SPEEDL,0,SPEEDL,0);
                                            b=1;
                                            break;
                                          case 4:
                                            aPPRK_Go(SPEEDL,-SPEEDL,0,0);
                                            b=1;
                                            break;
                                          default:
                                            b=0;
                                            break;
                                        }
                                      Finally, as seen in the following code, if b is 0 (meaning no sensor detected an
                                    object, or more than one sensor detected an object), the servos are commanded to
                                    rotate the robot. Otherwise, only a single sensor detected an object, and the else
                                    block waits for half a second, stops the servos, and waits for another half second.
                                    From there, the program jumps back to the start of the loop.

                                        if (b==0)
                                        {
                                          aPPRK_Go(0,0,0,SPEEDR);
                                        }
                                        else
                                        {
                                          aCore_Sleep(5000);
                                          aPPRK_Go(0,0,0,0);
                                          aCore_Sleep(5000);
                                        }
                                      }
                                   }
                                      In summary, this program causes the robot to spin around until it sees an
                                    object with one sensor. It then moves toward that object. If it loses the object,
                                    or if it detects objects with more than one sensor, it reverts to spinning again.











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