Page 234 - The Ultimate Palm Robot
P. 234

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  217



                                        ❏ Countdown two seconds
                                        ❏ Repeat

                                      Let’s start with the first message. In a reflex source file, commands are
                                    contained in block of code that looks like this:

                                   message[index] {
                                         module, command, parameters
                                   }

                                      Each message has an index so that we can reference messages by index
                                    number. The message body consists of the BrainStem module ID (which is 2),
                                    a BrainStem command, and parameters needed by the command. So, for ex-
                                    ample, consulting the BrainStem reference manual that comes with the software,
                                    you can find the command cmdSRV_REL for commanding a servo. This
                                    command takes three parameters. The reference manual states that the first
                                    parameter is the servo number (0–3), the second parameter is the servo position,
                                    and the third parameter is the relative direction for the servo to rotate (1 is
                                    forward, 0 is reverse). We must create an index for each message. We’ll simply
                                    index our messages counting up from 0. We will also use symbolic constants
                                    for each index. We use the #define macro to define the symbolic constants:

                                   #define MODULE 2

                                   /* message ids */
                                   #define mSRV1FOR 0
                                   #define mSRV1REV 1
                                   #define mSRV2FOR 2
                                   #define mSRV2REV 3
                                   #define mTIM1    4
                                   #define mTIM2    5

                                      The servo messages look like this:


                                   /* servo 1 forward */
                                   message[mSRV1FOR] {
                                      MODULE, cmdSRV_REL, 1, 127, 1
                                   }

                                   /* servo 1 reverse */









           P:\010Comp\Bots\880-6\ch08.vp
           Monday, May 12, 2003 1:16:46 PM
   229   230   231   232   233   234   235   236   237   238   239