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

154


          To provide some feedback to the  human operator, lightWatcher plays tones when it sends the grab or release commands.

          The hearbeat task is very simple. It repeated ly sends the heartbeat command to the IR port.

          Programming Minerva

          Minerva's program, then, must  listen for incoming messages on the IR port and respond to them. This is fairly simple, but it's
          complica ted by two things:

          1. Minerva should listen for th e heartbeat commands from the remote. If she doesn't hear them, she should stop what she's
          doing until the IR link is established again.

          2. The human operator should be abl e to change the direction of the arm as it is moving, without waiting for an entire grab or
          release cycle to be completed. This feature, how ever, should not interfere with Minerva's ability to stop the arm when it moves
          up as far as it can go.

          Minerva's program is split into four primary task s:

          message Watcher
          The  mes sagewatcher  ta sk examines the IR  port for incoming  messages.  When one arrives, it is examined and the
             op
          appr riat e action is taken.

          grab and release
          The grab and release tasks are kicked off by  messageWatcher to control Minerva's arm. They are separate tasks so
          that  messageWatcher  can continue to receive com mands from the remote while the arm is  moving. You  could, for
          example, start driving forward while the arm was gr abbin g. grab and release have the ability to interrupt each other, so
          you can change the direction of the arm  as it's moving .

          heartbeatWatcher
          This task keeps count of missing heartbeats. When messageWatcher receives  a heartbeat, it subtracts one from a tally of
          missing heartbeats, kept in the missedBeats varia ble. The  heartbeatWatcher adds one to this count; if it's ever more
          than one, heartbeatWatcher assumes it h as lost con tact with the remote. It then stops the messageWatcher task and
          shuts down the robot's  motors.  When the  heartbeat i s heard again,  heartbeatWatcher  starts up  messageWatcher
          once again.

          Here's the enti re program. I'll describe more of the  details after the listing.
   160   161   162   163   164   165   166   167   168   169   170