Page 169 - Build Your Own Quadcopter_ Power Up Your Designs with the Parallax Elev-8
P. 169

148     Bu il d  Y o ur  O w n  Q u a d c o p t e r


                             PUB SIGEngineStart(leftServoPin, rightServoPin, timeout) ‘’ 9 Stack
                                                                                                Longs

                             ‘ Starts up the SIG driver running on a cog. Returns true on
                                      success and false on failure.
                             ‘ LeftServoPin - Pin for left channel servo pulse width input.
                                      Between (0 - 31).
                             ‘ RightServoPin - Pin for right channel servo pulse width input.
                                      Between (0 - 31).
                             ‘ Timeout - The timeout period before zeroing the channel pulse
                                      lengths in  centiseconds. Between 0 and 100. (Try 10).

                               SIGEngineStop
                               if(chipver == 1)  ‘checks Prop chip version number. Should be 1

                                                                                            version
                                 leftPinNumber := ((leftServoPin <# 31) #> 0)    ‘ensures pin #
                                                                               in the range 0 to 31
                                 rightPinNumber := ((rightServoPin <# 31) #> 0) ‘ditto
                                 timeoutPeriod := ((timeout <# 100) #> 0)    ‘timeout between 0
                                                                               and 100
                                 cogNumber := cognew(SIGDriver, @stack)      ‘start a new cog
                                                                               with measuring code
                                 result or= ++cogNumber             ‘result is a predefined
                                                                        variable which in this case
                                                                        stores the cog number

                             PUB SIGEngineStop ‘’ 3 Stack Longs

                             ‘ Shuts down the SIG driver running on a cog.

                               if(cogNumber)
                                 cogstop(-1 + cogNumber~)

                             PRI SIGDriver : leftTimeout | rightTimeout     ‘ 7 Stack Longs
                               ctra := constant(%0_1000 << 26) + leftPinNumber ‘ sets the cog’s
                                              A counter to start counting as soon as a positive
                                              edge is detected on the leftPinNumber pin
                               ctrb := constant(%0_1000 << 26) + rightPinNumber  ‘sets the cog’s
                                              B counter to start counting as soon as a positive
                                              edge is detected on the rightPinNumber pin

                               frqa := frqb := 1
                               leftTimeout := rightTimeout := cnt

                               repeat
   164   165   166   167   168   169   170   171   172   173   174