Page 182 - The Ultimate Palm Robot
P. 182

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






                                                  Chapter 7 Essential Robot Programming Strategies   165



                                    loop, it will periodically ask the SV203 if sensor 1 has detected an object. If it
                                    has, the program will command the robot to move away from the object, spin
                                    around in one direction, spin around in the opposite direction, and then move
                                    back to where it was. If you read Chapter 5, you may notice that this program
                                    does the same thing as the simple.tea program we looked at there. By showing
                                    you the same program in a different language, you can compare this program
                                    to the same program written in TEA. Then you can write a 500-word essay
                                    comparing and contrasting the two programs. You must have five paragraphs
                                    at a minimum, consisting of introduction, three body paragraphs, and a con-
                                    clusion, with topic sentences for each paragraph. Essays are due next Mon-
                                    day. Send them to Dave for grading.
                                      After we show the complete program listing, we will look at its various
                                    parts in a little more detail. This program is a bit more involved than the ear-
                                    lier Hello World program, so you may want to enter it as a memo in the Palm
                                    Desktop and then perform a hot sync operation to load it to your PDA. So,
                                    without further ado, here is the listing for simple jig program .bas. If you don’t
                                    want to type this into your Palm OS device, we’ve included the source code in
                                    the \Other Applications\SimpleJig directory on the CD-ROM.

                                   # simple jig program .bas

                                   10 open "com1:", 9600 as #5
                                   15 rem draw start button
                                   20 draw -1
                                   25 draw "Stopped",40,70
                                   30 form btn 40,50, 35,15, "Start", 1
                                   35 rem wait for start button to be clicked
                                   40 x$=input$(1) : rem Start button returns chr$(14)
                                   45 if x$ <> chr$(14) then goto 40
                                   50 draw "Running...",40,70
                                   55 range = -1
                                   60 while (1)
                                   65   gosub 1200 : rem read sensor
                                   70   draw "Range value: [" + str$(range) + "]       ",2,115
                                   75   if range > 55 then gosub 1000
                                   80   fn wait(1) : rem wait 1 second
                                   85 wend
                                   90 close #5
                                   95 end

                                   1000 : rem jig function







           P:\010Comp\Bots\880-6\ch07.vp
           Monday, May 12, 2003 4:29:22 PM
   177   178   179   180   181   182   183   184   185   186   187