Help with servo vibration!
Hey guys.
So I am starting to work on a project, and right now I am working on getting my servo to be controlled by a 2 axis joystick. I will post the code below and a picture of the setup. The problem I am having is sometimes in the middle of its rotation the servo will start to oscillate rather fast. I'm not sure if this is due to some argument in the code, or if I programmed something incorrectly. These vibrations would be quite devastating to the project and I need to get rid of them. I don't know if I need to post more information or not. I could probably get a video of what it is doing if I haven't made it clear enough. Any help would be great.
' {$STAMP BS2}
'{$PBASIC 2.5}
UDPin CON 8
LRPIn CON 9
LR VAR Word
UD VAR Word
position VAR Word
DO
HIGH LRPin
PAUSE 2
RCTIME LRPin, 1, UD
HIGH UDPin
PAUSE 2
RCTIME UDPin, 1, LR
DEBUG HOME, "UD = ", DEC UD, ", LR = ", DEC LR, CLREOL
IF UD < 20 AND UD > 10 THEN
position = position +5
ELSEIF UD < 10 THEN
position = position +10
ELSEIF UD > 36 AND UD < 45 THEN
position = position -5
ELSEIF UD > 45 THEN
position = position -10
END IF
IF position < 200 THEN
position = 200
ELSEIF position > 1210 THEN
position = 1210
ENDIF
PULSOUT 14, position
LOOP
So I am starting to work on a project, and right now I am working on getting my servo to be controlled by a 2 axis joystick. I will post the code below and a picture of the setup. The problem I am having is sometimes in the middle of its rotation the servo will start to oscillate rather fast. I'm not sure if this is due to some argument in the code, or if I programmed something incorrectly. These vibrations would be quite devastating to the project and I need to get rid of them. I don't know if I need to post more information or not. I could probably get a video of what it is doing if I haven't made it clear enough. Any help would be great.
' {$STAMP BS2}
'{$PBASIC 2.5}
UDPin CON 8
LRPIn CON 9
LR VAR Word
UD VAR Word
position VAR Word
DO
HIGH LRPin
PAUSE 2
RCTIME LRPin, 1, UD
HIGH UDPin
PAUSE 2
RCTIME UDPin, 1, LR
DEBUG HOME, "UD = ", DEC UD, ", LR = ", DEC LR, CLREOL
IF UD < 20 AND UD > 10 THEN
position = position +5
ELSEIF UD < 10 THEN
position = position +10
ELSEIF UD > 36 AND UD < 45 THEN
position = position -5
ELSEIF UD > 45 THEN
position = position -10
END IF
IF position < 200 THEN
position = 200
ELSEIF position > 1210 THEN
position = 1210
ENDIF
PULSOUT 14, position
LOOP
Comments
Try commenting out the DEBUG portion of your code.
Look up MIN/MAX, you could use that rather than the last two IF statements.
See if you can change the PAUSE 2 to PAUSE 1.
I don't understand what that means or how to do it.
Sorry, I am still pretty new to this stuff.
When you write a program it is a good idea to include some notes in plain english so that when you or someone else looks at it, they can understand what is going on.
Below I have added some comments to your code. The comments I added will not change the way your code executes in any way.
To "comment out" the DEBUG line of your code all you need to do it put an apostrophe before it - and it will not execute, the program will skip right over it as if it weren't there.
I commented out the DEBUG line and changed the Pause 2's to Pause 1's and it works so much better!! It's completely smooth!!!!! You rock!!!
Plus, how did you get the code to be entered into your reply so nicely? With a scroll bar and everything.Thats sweet!
[noparse] [/noparse]
... to make it look like this;