PDA

View Full Version : Angle

pBASIC
08-02-2005, 08:34 AM
i need to get a angle of 40 degrees into a for next loop

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
==============================================

Chris

=============

Age

12

======

7

Webpage (http://members.cox.net/miniwarrior/)
Email=miniwarrior@cox.net (mailto:Email=miniwarrior@cox.net)

Beau Schwabe
08-02-2005, 09:06 AM
Chris,

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe (mailto:bschwabe@parallax.com)

IC Layout Engineer
Parallax, Inc.

pBASIC
08-02-2005, 09:51 AM
I need to get it to drive the servos for a long enough time for it to turn 40 degrees.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
==============================================

Chris

=============

Age

12

======

7

Webpage (http://members.cox.net/miniwarrior/)
Email=miniwarrior@cox.net (mailto:Email=miniwarrior@cox.net)

Beau Schwabe
08-02-2005, 10:56 AM
Servo's are not usually "time specific" when moving from point "A" to point "B" as you are indicating.
Typical servos require a signal that ranges from 1mS to 2mS for an "ON" time pulse duration, and a
15 to 25 mS range for an "OFF" time. The Stamp can easily accomplish this with the use of a PULSOUT
command, but the values that you will use, will vary from servo to servo, and depending on what model
Stamp you use.

Now, with that said, not all servos are created equal. The 1 mS to 2mS "ON" time sets the servo position.
With some servos this translates to almost 180 degres, while other servos this can be less than 90 Degrees.

BS1 = 10uS resolution
BS2, BS2e, and BS2pe = 2uS resolution
BS2sx, BS2p, and BS2px = 0.8uS resolution

Assume you have a BS2p with a resolution of 0.8uS. What this means, is that for a 1mS pulse (or 1000uS pulse)
you need to provide a value to the PULSOUT command of 1250 ( 1000 / 0.8 = 1250 ) or for a 2mS pulse (or 2000uS pulse)
you need to provide a value to the PULSOUT command of 2500 ( 2000 / 0.8 = 2500 ).

What does all of this mean?

Well assume also you have a servo that has a complete travel of 180 Degrees. Where 1mS = 0 Degrees and 2mS
= 180 Degrees.

If you want 40 Degrees, then you need to send a 1.2222 mS pulse. ( 1 + 40/180 = 1.2222 )

For the PULSOUT command you need to provide a value of 1527 ( 1222 / 0.8 = 1527.5 )

So FINALLY, if you want to put this in a for next loop, you might have something that looks like this....

' {\$STAMP BS2p}
' {\$PBASIC 2.5}

ServoPin VAR OUT0 'Designate Pin0 for your servo pin

' uS = ( 1 + Deg / 180 ) * 1000

ServoStart CON 1250 '1000uS / 0.8uS = 1250
ServoEnd CON 1527 '1222uS / 0.8uS = 1527.5

PanDelay CON 20 'Delay demo PAN interval

Servo VAR W0
ServoLoop VAR W1

DIRL = %11111111 'Set P0 to P7 as Outputs
OUTL = %00000000 'Set ALL outputs as LOW

MainLoop:

DO
RampUp:
FOR Servo = ServoStart TO ServoEnd
FOR ServoLoop = 0 TO PanDelay
PULSOUT ServoPin, Servo
PAUSE 20
NEXT
NEXT
RampDown:
FOR Servo = ServoEnd TO ServoStart
FOR ServoLoop = 0 TO PanDelay
PULSOUT ServoPin, Servo
PAUSE 20
NEXT
NEXT
LOOP

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe (mailto:bschwabe@parallax.com)

IC Layout Engineer
Parallax, Inc.

pBASIC
08-02-2005, 11:09 AM
..........basic stamp 2.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
==============================================

Chris

=============

Age

12

======