Page 151 - The Unofficial Guide to Lego Mindstorms Robots
P. 151

140


              : seek
                forward
                0 1 TIMER_SET
                BEGIN 2 sensorValue threshold @ 3 - < UNTIL
                2 sleep
                1 TIMER_GET returnTime !
                stop
              ;

              : return
                forward
                returnTime @ sleep
                stop
              ;

              : retrieve
                seek
                grab
                turnAround
                return
                release
                turnAround
              ;

              : Minerva
                initialize
                calibrate
                5 0 DO
                  retrieve
                LOOP
              ;

          The pbFORTH implem entation of Minerva's program closely resembles the NQC version of the program presented in Chapter
          5. By the time all the simpler words are defined, th e more complex words are simply combinations of the earlier ones. Keep
          this i mind—I'll describe the words in Minerva's p rogram starting at the end and returning to the beginning.
             n

          The main program word, Mi nerva, pretty much describes itself. It initializes the RCX, which includes configuring input 3 as
          a light sen sor inpu t. Then it calls calibrate to take an average reading of the light sensor. Finally, it loops five times,
          calling retrieve to go pick up something and bring it back.

          The retrieve word is also pretty self-explanatory. It calls seek to drive forward  and look for an object to pick up. Then
          grab  is called to grab the object. Minerva turns around and heads  back to her starting  point  with  turnAround  and
          return. Then she drops the object, with release, and turns around again with turnAround. With the simpler words
          defined correctly, retrieve is a highly readable piece of programming:

              : retrieve
                seek
   146   147   148   149   150   151   152   153   154   155   156