Shop OBEX P1 Docs P2 Docs Learn Events
A bit of a problem with servo controls...and for-nexts — Parallax Forums

A bit of a problem with servo controls...and for-nexts

PalCPalC Posts: 5
edited 2005-08-15 15:10 in Learn with BlocklyProp
I've just got into playing around with my Homework Board, nifty little platform that it is, so I decided to try a for-next loop to see what it could do with servomotors.

As you can see from the code I have posted, the syntax is tokenizable, however, the servo-motor seems to return to a certain position after every pulsout step.· The behaviour intended was for the servo to go to the most counterclockwise position, and then progress in steps to the most clockwise position.· Either I'm missing something about the nature of the servomotor itself, or I'm coding up the wrong tree here

value var byte 

PULSOUT 4, 500 
PAUSE 1000 
'Do stuff according to the same steps 
FOR value = 0 TO 40 STEP 2 
PULSOUT 4, (500+((value/2)*25)) 
PAUSE 2000 
DEBUG CR, "Interval: " 
DEBUG DEC value 
DEBUG CR, "Pulsout: " 
DEBUG DEC (500+((value/2)*25)) 

NEXT
end




Any suggestions/comments would be appreciated

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
A jug of wine
A loaf of bread
And thou

Comments

  • Martin HebelMartin Hebel Posts: 1,239
    edited 2005-08-14 04:16
    The servo really needs a pulse-train to move properly. A single pulse with a long pause duration will cause it to jerk and drift into a position. Your FOR-NEXT is a little cumbersome. A better way to step through would be to use a nested-loop.

    X var BYTE
    Value var WORD

    FOR Value = 500 to 1000 Step 50 ' Define range and steps
    DEBUG "Pulseout: ", DEC Value, CR
    FOR X = 1 to 20 ' send a pulse triain of 20 to hold for about 1/2 second (20 x (20mSec + pulse time ect))
    Pulsout 4, Value
    PAUSE 20
    NEXT
    NEXT ' go to next step

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Martin Hebel

    Electronic Systems Technologies
    Southern Illinois University Carbondale
    Personal Links - ·Lot of BASIC Stamp info
    and
    SelmaWare Solutions
    StampPlot Pro Version 3 Release 4
    Graphical Data Acquisition for your Micro and Imagination!
    Now allows additional controls to be added, or developed.
    ·
  • PalCPalC Posts: 5
    edited 2005-08-14 13:08
    Will try it, many thanks. I'll post back here if anything comes up.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    A jug of wine
    A loaf of bread
    And thou
  • PalCPalC Posts: 5
    edited 2005-08-14 14:16
    It seems that my unnecessary usage of a long pause was the problem with the code.· I reworked the code to the following and it seems to work perfectly, except for a little bit of jerking in the servomotor.· If I could fix the jerking problem, all would be fine

    I somehow get the impression that using such small pulsout increments so rapidly·is not good for the mechanics of the servomotor.
    'Every time the servo proceeds through the nested for-next loop, the value of pulsout increases by 25 in the manner of 500, 525, 550, 575...until it reaches 1000
     
    FOR counter = 0 TO 2 STEP 1
      FOR value = 0 TO 40 STEP 2
           PULSOUT 4, (500+((value/2)*25))
           DEBUG CR, "Interval: "
           DEBUG DEC value
           DEBUG CR, "Pulsout: "
           DEBUG DEC (500+((value/2)*25))
      NEXT
    NEXT
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    A jug of wine
    A loaf of bread
    And thou
  • Martin HebelMartin Hebel Posts: 1,239
    edited 2005-08-14 17:32
    The servo wants the same signal train that is sent by an RC Controller, which has to be fairly fast to control flight of a RC plane. A normal pulse train is a 1.0mSec to 2.0mSec pulse (500 to 1000 using PULSOUT), with a 20 mSec pause between them. The closer you can replicate that, the happier the servo will be.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Martin Hebel

    Electronic Systems Technologies
    Southern Illinois University Carbondale
    Personal Links - ·Lot of BASIC Stamp info
    and
    SelmaWare Solutions
    StampPlot Pro Version 3 Release 4
    Graphical Data Acquisition for your Micro and Imagination!
    Now allows additional controls to be added, or developed.
    ·
  • Ryan ClarkeRyan Clarke Posts: 738
    edited 2005-08-15 15:10
    PalC,

    Check out page 103 of "What is a Microcontroller" (http://www.parallax.com/dl/docs/books/edu/wamv2_2.pdf)

    Ryan

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Ryan Clarke

    Parallax Tech Support
    rclarke@parallax.com
Sign In or Register to comment.