Shop OBEX P1 Docs P2 Docs Learn Events
need help with programming — Parallax Forums

need help with programming

OwnononoOwnonono Posts: 14
edited 2008-11-02 04:36 in Robotics
i'm working on project of hexapod robot, the robot only use 3 servo. the problem is,when the middle leg lift the body it wont hold
because other instruction were executed.how do i maintain the program that were already executed???

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

'===============return to normal position==================
temp VAR Word
DO

FOR temp=650 TO 750
PULSOUT 15,temp
PAUSE 1 '==============
NEXT '====='= = ======
'= =
FOR temp=550 TO 750 '= =
PULSOUT 14,temp '====='= ======
PAUSE 1 '= =
NEXT '= =
'= =
FOR temp=550 TO 750 '====='= ======
PULSOUT 13,temp '==============
PAUSE 1
NEXT

'=========================
PAUSE 3000

FOR temp=750 TO 650
PULSOUT 15,temp
PAUSE 1 '==============
NEXT ''= '= = ==
'= '= = =
FOR temp=750 TO 1000 '='= = =
PULSOUT 15,650 '====='= ======
PAUSE 1 '= =
PULSOUT 14,temp '= '= =
PAUSE 1 '= '= =
NEXT '='= ==
'============== =
FOR temp=750 TO 1000 '=
PULSOUT 15, 650
PAUSE 1
PULSOUT 13,temp
PAUSE 1
NEXT

'===========================
PAUSE 10

FOR temp=850 TO 750
PULSOUT 15,temp '==============
PAUSE 1 '====='= = ======
NEXT '= =
'= =
FOR temp=1000 TO 750 '====='= ======
PULSOUT 14,temp '= =
PAUSE 1 '= =
NEXT '= =
'====='= ======
FOR temp=1000 TO 750 '==============
PULSOUT 13,temp
PAUSE 1
NEXT
'============================
PAUSE 10

FOR temp=750 TO 850
PULSOUT 15,temp '==============
PAUSE 1 '='= = = =
NEXT '= '= = =
'= '= = =
FOR temp=750 TO 550 '====='= ======
PULSOUT 15,850 '= =
PULSOUT 14,temp '='= = =
PAUSE 1 '= '= = =
NEXT '= '= ==
'==============
FOR temp=750 TO 550
PULSOUT 15,850
PULSOUT 13,temp
PAUSE 1
NEXT

PAUSE 10
LOOP
'==================================

if somebody can help i really appreciate it...

[img]http://img252.imageshack.us/img252/3315/1001860le4.jpg<img src=[/img]

Comments

  • SRLMSRLM Posts: 5,045
    edited 2008-10-30 01:22
    You should consolidate your code. Put each of the Pulsouts one after another, in a loop, with a 20 ms pulse between iterations. The way that you have it, there is a 3000 ms, then 3 ten ms pauses. To maintain a position, you have to refresh the servo every 20 ms with the desired position, hence the loops. Take a look at the LOOKUP command to relate various values together.
  • OwnononoOwnonono Posts: 14
    edited 2008-10-30 02:23
    temp VAR Word
    DO

    FOR temp=650 TO 750
    PULSOUT 15,temp
    PAUSE 1
    NEXT

    FOR temp=550 TO 750
    PULSOUT 14,temp
    PAUSE 1
    NEXT

    FOR temp=550 TO 750
    PULSOUT 13,temp
    PAUSE 1
    NEXT


    PAUSE 3000

    FOR temp=750 TO 650
    PULSOUT 15,temp
    NEXT

    FOR temp=750 TO 1000
    PULSOUT 15,650 'middle leg
    PULSOUT 14,temp 'left leg

    NEXT

    did u mean like this
  • SRLMSRLM Posts: 5,045
    edited 2008-10-30 02:42
    No. A servo must have a pause of approx. 20 ms between pulses. In all your loops, you have about 1 ms pause (due to code execution time). You want something like this:


    For temp = 650 to 750

    PULSOUT 13, temp
    PULSOUT 14, 750
    PULSOUT 15, 750
    PAUSE 17 '17 because you have three ~1 ms pulses and execution times.

    NEXT

    This will properly refresh the servos, and hold the unmoving servos in place. This would constitute one "step", or movement. It looks like your walking sequence has about 6 sequences, so you'll need to repeat this six times (or however many).
  • OwnononoOwnonono Posts: 14
    edited 2008-10-30 03:18
    temp VAR Word
    DO

    =============SERVO RETURN TO NORMAL POSITION==============
    FOR temp=650 TO 750
    PULSOUT 15,temp
    PAUSE 1
    NEXT

    FOR temp=550 TO 750
    PULSOUT 14,temp
    PAUSE 1
    NEXT

    FOR temp=550 TO 750
    PULSOUT 13,temp
    PAUSE 1
    NEXT

    PAUSE 3000 'HOLD FOR 3 SEC THEN MOVE
    ======================================

    For temp = 750 to 1000

    PULSOUT 13, 850 'MIDDLE SERVO LIFT BODY
    PULSOUT 14, TEMP 'LEFT LEG MOVES FORWARD
    PULSOUT 15, TEMP 'RIGHT LEG MOVES BACKWARD
    PAUSE 17 'WILL IT BE LIKE THIS???

    NEXT

    LOOP


    DO THE SERVO ON P13 HOLD ITS POSITION BECAUSE OF THE WEIGHT AND THE OTHER INSTRUCTION ARE RUNNING???
  • SRLMSRLM Posts: 5,045
    edited 2008-10-30 05:22
    I assuming in my answer that your question refers to the line:

    PULSOUT 13, 850 'MIDDLE SERVO LIFT BODY

    near the end. The servo holds it's position because you are refreshing it ~20ms with a constant value. The weight has nothing to do with it, and neither do the other instructions. That's one of the double edged swords about servos: you have enough time to do other stuff between refreshes, but you can't forget about them.


    You first three loops are still wrong. You have a ~2 ms refresh rate (PAUSE 1 + execution time). You need 20 ms. Also, you might as well combine the first three loops. It will get the servos to the normal position faster (they all move together, rather than wait for one to move, then the next). It's a good habit to do all your servo refresh work at the same time. (AKA, always group the PULSOUTs together unless you have a really good reason.)
  • OwnononoOwnonono Posts: 14
    edited 2008-10-30 10:35
    =============SERVO RETURN TO NORMAL POSITION==============

    FOR temp=550 TO 750
    PULSOUT 14,temp
    PULSOUT 13,temp
    PULSOUT 15,temp
    PAUSE 20
    NEXT

    PAUSE 3000 'HOLD FOR 3 SEC THEN MOVE
    ======================================

    For temp = 750 to 1000

    PULSOUT 13, 850 'MIDDLE SERVO LIFT BODY
    PULSOUT 14, TEMP 'LEFT LEG MOVES FORWARD
    PULSOUT 15, TEMP 'RIGHT LEG MOVES BACKWARD
    PAUSE 20

    NEXT

    LOOP

    it is like this??

    when i try this command,the middle servo lift it leg but then return back when left leg moving, when i check the volts, at first it receive 6 volt, then when left leg moves the middle servo show 0 volts making it goes to original position,so that why i assume the weight of robot making it return after lift it.

    and i see that my servo moves very slow.my servo type is Cytron C40S (180 degree type)
  • OwnononoOwnonono Posts: 14
    edited 2008-10-30 10:39
    1001860le4.jpg

    1001879ax0.jpg

    1001885al1.jpg
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2008-10-30 10:56
    Ownnonono -

    My guess is that either your battery pack needs a charge, or it isn't large enough for your hexapod.

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When all else fails, try inserting a new battery.
  • OwnononoOwnonono Posts: 14
    edited 2008-10-30 13:18
    no..i dont use the battery i use a power supply from the socket...it never runs out...
  • allanlane5allanlane5 Posts: 3,815
    edited 2008-10-30 14:04
    If the voltage drops to zero, then the wall-wart power-supply may be undersized. What is its voltage and amperage rating?
  • OwnononoOwnonono Posts: 14
    edited 2008-10-30 14:31
    6v 1.1 A

    the sequence like this..

    midle servo move = 6v left leg 0v
    left leg move=6v middle 0v
    middle move again=6v left leg 0v
  • allanlane5allanlane5 Posts: 3,815
    edited 2008-10-30 14:53
    Each servo can take up to 1 amp, when moving, depending on resistance. So yes, activating two servo's (or three, as you're doing) at the same time can be a problem.

    It sounds more likely that the legs have too much resistance in their moving, and this is "browning out" the supply.

    From looking at earlier posts, it does seem that you're stopping "refresh" of one of your servo's, which means it won't "hold position".

    It's better to have three variables: Servo1Pos, Servo2Pos, Servo3Pos

    Then:

    RefreshServo:
    · PULSOUT Servo1Pin, Servo1Pos
    · PULSOUT Servo2Pin, Servo2Pos
    · PULSOUT Servo3Pin, Servo3Pos
    · RETURN

    On 'return', you have 20 milliseconds before you MUST call RefreshServo again.

    Post Edited (allanlane5) : 10/30/2008 3:00:18 PM GMT
  • OwnononoOwnonono Posts: 14
    edited 2008-10-30 15:07
    looking at your comment...i try to moves servo only..without any attachment..but the servo also moves slow
    i do realize that if there is a resistance in servo movement it will draw more current.

    i want the middle servo to lift the body and hold its current position while the other leg moving
  • SRLMSRLM Posts: 5,045
    edited 2008-10-30 16:19
    Are you sure that you servos are okay? Have you always fed them ~5-6 volts? Also, I don't know what a refresh rate of 2ms does, and it might have hurt you servos. I suggest that you either a) put as little weight as possible on them or b) take them out and test to see if they acutally do work. They should move quickly to position (if you tell it some thing like 850) and then hold their quietly.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2008-10-30 19:30
    Overdriving servos (refreshing them faster than ~15 mS) doesn’t really hurt them so much as it makes them jittery depending on the servo.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Engineering
  • SRLMSRLM Posts: 5,045
    edited 2008-10-30 19:49
    Ah, thanks Chris. I've never tried to overdrive, and have not been willing to risk a servo to see what happens.
  • OwnononoOwnonono Posts: 14
    edited 2008-10-31 02:41
    allanlane5 did u mean like this

    middleright CON 850
    middleleft CON 650
    leftfwd CON 1000
    leftback CON 550
    rightfwd CON 550
    rightback CON 1000

    do

    GOTO RefreshServo
    pause 20

    PULSOUT 13, rightfwd
    PULSOUT 14, leftfwd
    PULSOUT 15, middleleft

    GOTO Refresh Servo
    pause 20

    loop



    RefreshServo:
    PULSOUT 13, rightback
    PULSOUT 14, leftback
    PULSOUT 15, middleright
    RETURN
  • SRLMSRLM Posts: 5,045
    edited 2008-10-31 07:37
    You defined constants. Allanlane said variables. The way that he has it set up (as per good programming practice: put things in methods) is to call the RefreshServo method every time that you need to refresh the servo. Aka, in your code above, you want to replace the first three pulseouts with a call to RefreshServo. You "tell" the servos where you want them to be by changing the ServoPos variable to the pulseout width (750, 800, etc.) If you want to use the constants, you'll use a line like this:


    Servo1Pos = leftfwd
    GOSUB RefreshServos
    Pause 20


    Also, note that you want to call the RefreshServo method with GOSUB, not GOTO. Take a look in the BS manual to see why.
  • OwnononoOwnonono Posts: 14
    edited 2008-10-31 09:59
    actually i want to wrote GOSUB..but just before i was programming the intel 8051..that why i accidently wrote GOTO...hohohohoh

    how to do the variables??
  • SRLMSRLM Posts: 5,045
    edited 2008-10-31 17:24
    You have three servos, so you have three servo positions:

    servo1 VAR Word
    servo2 VAR Word
    servo3 VAR Word


    In your refresh servos method, simply use these variables in place of a constant number or CON. Since the variables are global, there shouldn't be any visibility problems. When you want to change where a servo is, just change (for example) servo1 = 850.
  • OwnononoOwnonono Posts: 14
    edited 2008-11-01 10:51
    the in programming..should i wrote like this

    servo1 VAR Word 'here is where i declare
    servo2 VAR Word
    servo3 VAR Word

    do

    pulsout servo1,750 'all the in normal position
    pulsout servo2,750
    pulsout servo3,750

    pause 20

    pulsout servo1,850 'lift left body while left leg forward,right leg backward
    pulsout servo2,1000
    pulsout servo3,1000

    pause 20

    pulsout servo1,650 'lift right body while left leg backward,right leg forward
    pulsout servo2,550
    pulsout servo2,550

    pause 20

    loop

    it is like this..for simple walking only???
  • SRLMSRLM Posts: 5,045
    edited 2008-11-01 17:20
    That should almost work. Note that it will probably take longer than 20 ms to move a leg. So, you need to put each of the blocks into a loop. I'd guess a second would work, but you'll have to play with it. And are you just giving up on the subroutine? Anyway, try reading Robotics with the Boe-Bot, in specific the chapters on servo control. Those servos are continuous, so there is some theoretical differences, but the prinicples are the same and you can translate it to your code.
  • OwnononoOwnonono Posts: 14
    edited 2008-11-02 04:10
    ok ...i try that..

    this is just sample of code...later i put it into subroutine...if i put RETURN command, do i still need the PAUSE 20??

    img0707py3.jpg
  • SRLMSRLM Posts: 5,045
    edited 2008-11-02 04:24
    Whenever you pulsout a servo, you need to wait ~20 ms before the next pulsout. You can use a PAUSE 20, or other code that takes 20 ms, or any combination of the two. A subroutine (with GOSUB and RETURN) is just some code organization that we programmers do to save size and make it easier to read and change.
  • OwnononoOwnonono Posts: 14
    edited 2008-11-02 04:36
    ok ...now i get it..since u said it between pulsout...which one better??

    PULSOUT SERVO1,750
    PAUSE 20
    PULSOUT SERVO2,750
    PAUSE 20

    or

    PULSOUT SERVO1,750
    PULSOUT SERVO2,750
    PAUSE 20
Sign In or Register to comment.