Shop OBEX P1 Docs P2 Docs Learn Events
Servo Control Problem — Parallax Forums

Servo Control Problem

tsindostsindos Posts: 9
edited 2005-04-15 22:36 in BASIC Stamp
I am VERY new in robotics with fair understanding of programming. I have spent all night tonight looking for an answer to the mystery that baffles me.

I have 3 servos which I try to control via BS2. 2 servos are used to move a single rod (I needed the torque) and therefore did a small adjustment so both servos move together without one straining the other, and the 3rd servo rotates the base accordingly. The code I wrote (don't laugh but it is something new to me) is this:

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

·· BottomArmPulses·· VAR· Byte
·· BasePulses······· VAR· Byte
·· counterBA········ VAR· Byte
·· counterB········· VAR· Byte

· DEBUG CLS, "Enter Arm position (0-60):", CR
· DEBUGIN DEC BottomArmPulses
···· GOSUB BottomArm
· DEBUG CLS, "Enter Base position (250-1150):", CR
· DEBUGIN DEC BasePulses
···· GOSUB BaseRotate

· '===============================================================================

·· BottomArm:
·· FOR counterBA = 0 TO 20
···· PULSOUT 10, (BottomArmPulses * 15) + 250
···· 'PAUSE 20
··· ·PULSOUT 11, ((BottomArmPulses * 15) + 250) + (BottomArmPulses + 5) ' + Adjust
··· ·PAUSE 20
·· NEXT
·· RETURN
·· '=============================================================================
·· BaseRotate:
·· FOR counterB = 0 TO·100
·····PULSOUT 5, BasePulses······· '1150 is FAR LEFT··· 250 is FAR RIGHT· 700 is MIDDLE
··· ·PAUSE 10
·· NEXT
·· RETURN


My problem is thus:
When I remark anything that has to do with the first 2 servos (BottomArm), the 3rd servo (BaseRotate) works fine in every respect. When I try to combine both actions together, the 3rd servo always moves far clockwise (to the 250 and beyond...) and I cannot seem to get it working whatever I do concerning values.

This is probably something simple to you gurus out there but it has me baffled. I have read "What's a Microcontroller?" and information on the Internet (including of course Parallax) but could not find anything.

Is my coding wrong? (unless - which I doubt - the servo has a problem)

Comments

  • allanlane5allanlane5 Posts: 3,815
    edited 2005-04-15 20:34
    Umm -- "BasePulses" is declared as a Byte. A Byte can hold 0..255. You are trying to assign it 1000. As such, I assume you are assigning to 'BasePulses' the lowbyte, and CounterBA the high-byte.

    Thus everything works until you assign to CounterBA.

    Solution: Declare BasePulses as a Word.
  • tsindostsindos Posts: 9
    edited 2005-04-15 20:47
    It works! I cannot believe how stupid I can get sometimes. Thank you for pointing it out.

    This raises another question though...... Any idea why it works when I rem the "BottomArm" function. It should not since the values are over the 255 value..... I wonder.....

    Thanks anyway. I was too tired too climb out of a pit and you were there to pull me out.
  • allanlane5allanlane5 Posts: 3,815
    edited 2005-04-15 22:36
    Well, it actually IS storing the values in Low-byte to BasePulses, high-byte to CounterBA (apparently, otherwise it wouldn't work at all).

    Thus, when you call BaseRotate, the low-byte is read from BasePulses, and the high-byte is still in CounterBA, so it works. When you actually call BottomArm, that routine clears the high-byte, so bad things happen after that.

    Note I'm really guessing about the low-byte | high-byte thing.· It makes sense in this circumstance, given the symptoms you describe.
Sign In or Register to comment.