Page 134 - The Ultimate Palm Robot
P. 134

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






                                                                 Chapter 5  Checking Out the Robot   117



                                    jig( ) function, you can see that it uses several functions from the other TEA
                                    files, namely aPPRK_Go( ) and aCore_Sleep( ), to do its work:

                                   void jig()
                                   {
                                      aPPRK_Go(0, -100, 100, 0);
                                      aCore_Sleep(20000);
                                      aPPRK_Go(0, 0, 0, 100);
                                      aCore_Sleep(30000);
                                      aPPRK_Go(0, -100, 100, 0);
                                      aCore_Sleep(20000);
                                      aPPRK_Go(0, 0, 0, -100);
                                      aCore_Sleep(30000);
                                      aPPRK_Go(0, 0, 0, 0);
                                   }


                                      The other function in the source code is the main( ) function. This is where
                                    we found the answer. If you look at the following source code, you’ll see only
                                    one line of code that appears to read a sensor, and it appears to read IR1. That
                                    would explain why only one sensor caused the robot to do its little jig:

                                   void main()
                                   {
                                      int b;
                                      int range;

                                      /* five second wait before starting             */
                                      aCore_Sleep(25000);
                                      aCore_Sleep(25000);

                                      /* loop continuously                            */
                                      while (1) {
                                        /* take a reading                             */
                                        range = aA2D_ReadInt(APPRK_IR1);
                                        /* see if something was present and do        */
                                        /* the jig if so                              */
                                        if (range > 100)
                                          jig();
                                        /* stall for 1 second                         */
                                        aCore_Sleep(10000);
                                      } /* while */
                                   } /* main */









           P:\010Comp\Bots\880-6\ch05.vp
           Monday, May 12, 2003 4:06:14 PM
   129   130   131   132   133   134   135   136   137   138   139