Shop OBEX P1 Docs P2 Docs Learn Events
Controlling two+ servos with PC — Parallax Forums

Controlling two+ servos with PC

sumguy16sumguy16 Posts: 21
edited 2004-11-29 22:41 in BASIC Stamp
This is a similar post to the one before, but I thought it needed a seperate topic.· I'm controlling two servos with a joystick via Visual Basic 6 with the MScomm1 line:

MSComm1.Output = "@" & Str(intClaw) & "C" & Str(intX) & "X"

My problem is whenever I start it up I can't get the two servos to move independently from one another.· Is it possible to have two different pulsout commands or is that just impossible?

my BASIC code:

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

intY VAR Word
intClaw VAR Word

Clawpin CON 7
Ypin CON 12
delay CON 20
OUTPUT Clawpin
OUTPUT Ypin

' ===================== main =====================| 0
main:
SERIN 16, 24972, [noparse][[/noparse]WAIT("@"), NUM intClaw, WAIT("C"), NUM intY]
GOTO claw
'|====================== CLAW ======================| 1
claw:
· PULSOUT Clawpin, intClaw
· PAUSE delay
GOTO intYa

'|===================== Y-Axis =====================| 3
intYa:
· PULSOUT Ypin, intY
· PAUSE delay
GOTO main

It as if when I try to move the claw it always moves the Y-Axis with the same value. then when I move the Y-Axis it does nothing.

Thanks!
Adam

Comments

  • Bruce BatesBruce Bates Posts: 3,045
    edited 2004-11-27 22:35
    Adam -

    As it stands now with the following SERIN from your program:
    SERIN 16, 24972, [noparse][[/noparse]WAIT("@"), NUM intClaw, WAIT("C"), NUM intY]

    intClaw and intY will be presumed to have only one digit, I suspect. If the true value is greater than 9, which I suspect it may by, then you want to use NUM2 or NUM4 to indicate their true numeric capacity.

    Just as a sidenote, most folks use DEC in lieu of NUM, but the same rules apply. As an aid in debugging the progtram you may want to change from using pin port 16, and then use DEBUG to diplay the values being sent to the Stamp, just to ensure they are what you suspect. An additional reminder, pin port 16 has a fixed baudmode, as indicated in the manual.

    Regards,

    Bruce Bates
  • allanlane5allanlane5 Posts: 3,815
    edited 2004-11-29 21:37
    You should only "DELAY" once.

    A Servo *must* be updated every 20 to 50 mSec. It may take several updates before it completes its motion to the selected space. Your current code sets one, waits 20 mSec, *then* sets the other, waits an additional 20 mSec, *then* goes to the SERIN, and waits who knows how long.

    You could easily update both servos, then do a single PAUSE. You can do the PAUSE as a SERIN timeout. But you *must* refresh both servo's every 20 to 50 mSec for them to hold their position.
  • sumguy16sumguy16 Posts: 21
    edited 2004-11-29 22:22
    I've changed the delay, but does anyone know how to make the servo move smoothly?· From testing the only baud rate I can really get to work is 2400bps at 7-bits.· Whenever I use·a different baud rate it never works.· Is there anyway to have a higher baud rate with a BS2.· I would like to eventually control up to 6 servos, but it seems that the BS2 would never be able to keep up with something like:

    SERIN 0, 24972, [noparse][[/noparse]WAIT("%"), DEC4 intClaw, WAIT("C"), DEC4 intY, WAIT("X"), DEC4 intX, WAIT("Y"), DEC4 intZ, WAIT("Z"), DEC4 intZ]

    Would I have to upgrade to the BSX? or possibly go with an SX chip @ 50mhz?



    Thanks,

    Adam
  • allanlane5allanlane5 Posts: 3,815
    edited 2004-11-29 22:41
    You have a couple of problems.
    1. The BS2 only does single-tasking. This means when it is waiting in the SERIN, it is *not* updating your servos.
    · When it is updating your servo's, or spending time in a PAUSE statement, it is *not* listening to the SERIN port.
    · Solution: Don't wait in a PAUSE statement, wait in your SERIN statement, but put in a *timeout* parameter.

    2. You *still* don't have a time-out in your SERIN statement.

    3. You can update a servo position at a time with each SERIN statement -- you shouldn't update All the servo
    ··· positions in a *single* SERIN statement.

    4. You have no 'acknowledge' for your SERIN statement -- like:
    MAIN:
    · SERIN 0, 24972, 20, Timeout, [noparse][[/noparse]DEC1 intServ1, DEC1 Pos1]
    · SEROUT 1, 24972, [noparse][[/noparse]"A"] ' Acknowledge -- means data was gotten.
    · PAUSE 20 ' Pause here guarantees we get at least 20 mSec when we get data

    TIMEOUT:
    · PULSEOUT ClawPin, intClaw
    · PULSEOUT YPin, intY
    · GOTO MAIN
Sign In or Register to comment.