Shop OBEX P1 Docs P2 Docs Learn Events
- moving 2 servo at one time - — Parallax Forums

- moving 2 servo at one time -

sushiandmorihikosushiandmorihiko Posts: 40
edited 2007-10-12 19:06 in BASIC Stamp
hello,its me again,

i wonder if i can move 2 servo together at one time eg i have this code:


FOR boom = 1200 TO 470 STEP 40
PULSOUT 2, boom
PAUSE 20
NEXT

PAUSE 200

FOR boom = 470 TO 1200 STEP 40
PULSOUT 2, boom
PAUSE 20
NEXT

PAUSE 200


FOR boom = 1200 TO 300 STEP 40
PULSOUT 3, boom
PAUSE 40
NEXT

PAUSE 200

FOR boom = 300 TO 1200 STEP 40
PULSOUT 3, boom
PAUSE 40
NEXT

PAUSE 200


conventionally,they should move step by step, after the upper part is done than it will get to the lower part. can i execute these part together so that the servo will move together too?

thanks ,people

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-10-12 04:39
    Yes. You can do
    FOR boom = 1200 TO 300 STEP 40
    PULSOUT 2,boom
    PULSOUT 3,boom
    PAUSE 40
    NEXT
    


    The second loop works the same way. You can even have the two servos move differently if you
    compute the two pulse widths somehow. For example, you could have the loop count represent
    the percentage of movement from the beginning, then compute the two different pulse widths
    from that. The loop would read FOR percent = 1 TO 100 and you'd do the computation accordingly.
  • sushiandmorihikosushiandmorihiko Posts: 40
    edited 2007-10-12 05:40
    hhhmmm,,thanks mike green but i kinda not so clear on you idea on moving the servo different direction,very different movement at the same time?

    how do i do the calculation--i think it is going to be complex isnt it

    thanks mike green
  • Mike GreenMike Green Posts: 23,101
    edited 2007-10-12 05:47
    For example (in the loop shown)
    PULSOUT 2,boom
    PULSOUT 3,1500-boom
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2007-10-12 08:01
    Again, there is a much easier way to have two R/C servos always work together, if that's your goal. Just tie the signal wire of each R/C servo to the same Stamp pin.

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • allanlane5allanlane5 Posts: 3,815
    edited 2007-10-12 14:09
    Well, Bruce, it looks like he has two servo's that he wants to move in OPPOSITE directions -- using one signal wire won't let him do that.
  • David H.David H. Posts: 78
    edited 2007-10-12 16:56
    How about seperating the booms?
    It's been awhile for my program,
    but would something like this work?

    FOR
    boom1 = 1200 TO 470 STEP 40
    boom2 = 1200 TO 300 STEP 40
    PULSOUT 2, boom1
    PULSOUT 3, boom2
    PAUSE 20
    NEXT

    PAUSE 200

    FOR
    boom1 = 470 TO 1200 STEP 40
    boom2 = 300 TO 1200 STEP 40
    PULSOUT 2, boom1
    PULSOUT 3, boom2
    PAUSE 20
    NEXT

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    David


    There are 10 types of people in this world,...
    Those that understand binary numbers, and those that don't!!!
  • Mike GreenMike Green Posts: 23,101
    edited 2007-10-12 16:59
    David,
    That's not legal PBasic. Read the section of the manual on the FOR statement.
  • David H.David H. Posts: 78
    edited 2007-10-12 17:07
    Thanks Mike,
    Like I said, it's been a little bit for me.
    Just throwing out an idea.
    Have a good one!!!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    David


    There are 10 types of people in this world,...
    Those that understand binary numbers, and those that don't!!!
  • D FaustD Faust Posts: 608
    edited 2007-10-12 18:42
    boom2 = 470
    FOR boom1 = 1200 TO 470 STEP 40
    boom2 = boom2 + 40
    PULSOUT 2, boom1
    Pulsout 3, boom2
    PAUSE 20
    NEXT

    PAUSE 200

    boom2 = 1200
    FOR boom1 = 470 TO 1200 STEP 40
    boom2 = boom2 - 40
    PULSOUT 2, boom1
    pulsout 3, boom2
    PAUSE 20
    NEXT

    PAUSE 200

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    LOOKDOWN ThisThread, [noparse][[/noparse]Your_?, My_?, Cool_Thing], looknum
    LOOKUP looknum, [noparse][[/noparse]1, 2, 3], subnum
    ON subnum GOTO Hope_this_helps, Thanks!, WOW!!
    END 
    
  • allanlane5allanlane5 Posts: 3,815
    edited 2007-10-12 19:06
    Or, you could do something like:

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    BoomPos1 VAR Word
    BoomPos2 VAR Word
    I······· VAR Word

    FOR I = 0 TO 22
    · BoomPos1 = 1200 - (40 * I)
    · BoomPos2 = 400 + (40 * I)
    · PULSOUT 2, BoomPos1
    · PULSOUT 3, BoomPos2
    · PAUSE 20
    NEXT

    FOR I = 0 TO 22
    · BoomPos1 = 400 + (40 * I)
    · BoomPos2 = 1200 - (40 * I)
    · PULSOUT 2, BoomPos1
    · PULSOUT 3, BoomPos2
    · PAUSE 20
    NEXT

    Point being, you've got a 'starting position', an 'ending position', and some 'increment' to get you there, and a certain number of steps.· Within that framework, you have a lot of freedom.
Sign In or Register to comment.