Shop OBEX P1 Docs P2 Docs Learn Events
Angle — Parallax Forums

Angle

pBASICpBASIC Posts: 25
edited 2005-08-02 15:04 in BASIC Stamp
i need to get a angle of 40 degrees into a for next loop

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

Chris

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

Age

12

======
grade

7

Webpage
Email=miniwarrior@cox.net

Comments

  • Beau SchwabeBeau Schwabe Posts: 6,557
    edited 2005-08-02 02:06
    Chris,

    You are going to need to give us a little more information in order for us to answer your question.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
  • pBASICpBASIC Posts: 25
    edited 2005-08-02 02:51
    I need to get it to drive the servos for a long enough time for it to turn 40 degrees.

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

    Chris

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

    Age

    12

    ======
    grade

    7

    Webpage
    Email=miniwarrior@cox.net
  • Beau SchwabeBeau Schwabe Posts: 6,557
    edited 2005-08-02 03:56
    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

    IC Layout Engineer
    Parallax, Inc.
  • pBASICpBASIC Posts: 25
    edited 2005-08-02 04:09
    ..........basic stamp 2.

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

    Chris

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

    Age

    12

    ======
    grade

    7

    Webpage
    Email=miniwarrior@cox.net
  • YanroyYanroy Posts: 96
    edited 2005-08-02 15:04
    All the information you need to use Mr. Schwabe's solution is already present in his post.· You just need to adjust the timing on the PULSOUT command because the BS2 uses a 2uS resolution, not 0.8uS.· Follow the same math as for the BS2p, just changing every place you see 0.8uS to 2uS and you should be all set.
Sign In or Register to comment.