Shop OBEX P1 Docs P2 Docs Learn Events
BS2 with Servo rotation 90 degrees — Parallax Forums

BS2 with Servo rotation 90 degrees

millsirmillsir Posts: 2
edited 2011-04-12 18:28 in BASIC Stamp
Hey guys, my friend and I are working on creating a mock train set using the standard servo as the gate. We are having trouble with the code and making the servo rotate only 90 degrees when BS2 reads 0 and then rotate when it reads 1. We are using a photo eye to change the output. Can anyone please help us with the code we need.

Thanks in advance

Comments

  • PJAllenPJAllen Banned Posts: 5,065
    edited 2011-04-12 11:46
  • millsirmillsir Posts: 2
    edited 2011-04-12 12:05
    We have edited the code and found how to change the numbers using temp = ### TO ### but we dont know how to make it so the code has an input in degrees. Here is our code for the Servo

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}

    OUTPUT 4
    OUTPUT 8
    INPUT 0

    Servo_pin CON 14
    Temp VAR Word

    reblink:
    DEBUG DEC IN0
    IF IN8 = 1 THEN GOTO reblink
    IF IN8 = 0 THEN GOTO start


    start:

    FOR temp = 000 TO 650
    45 deg, PULSOUT Servo_pin,temp
    PAUSE 20
    NEXT
    FOR temp = 650 TO 000
    45 deg, PULSOUT Servo_pin,temp
    PAUSE 20
    NEXT

    OUT4=1
    PAUSE 1000
    OUT4=0
    OUT8=1
    PAUSE 1000
    OUT8=0

    GOTO reblink

    We are also stuck on changing the speed and the start orientation
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2011-04-12 15:55
    Valid servo timing pulse-widths are in the range of 1,000 - 2,000 usec (1 - 2 ms); so PULSOUT in the range of 000 - 650 isn't going to make it.
    That video is short, but there's more information presented than meets the casual eye.
    Maybe someone will come along and write your code for you, I want to help you learn. I'm very mean that way.
  • $WMc%$WMc% Posts: 1,884
    edited 2011-04-12 18:13
    1ms is far left, 2ms is far right, 1.5ms is centered.
    '
    Take a look @ Exp. #26 in StampWorks
    '
    http://www.parallax.com/Portals/0/Downloads/docs/books/sw/Web-SW-v2.1.pdf
    '
    google is you friend.
  • Mike GMike G Posts: 2,702
    edited 2011-04-12 18:28
    Let's say you servo PULSOUT range is 250 to 1250 for 180 degrees of rotation. That's 180/(1250-250) = 180/1000 =18/100. Every 6 units is a little more than a degree (108/100). There is an offset from zero of 250 units. That gives us
    F(x) = (PULSOUT_VAlUE  - 250) *(18/100)
    
    Let's remove the divide by 100 because we're working with integer math.
    F(x) = (PULSOUT_VAlUE - 250) *(18)
    
Sign In or Register to comment.