Servo control issue

I’m having issues with a servo that’s behaving very strangely. It’s a servo for an R/C car, HPI SF-1. I haven’t been able to find any spec sheets for it.

when I wired it to port 11 and use the following code

[code]
sweep:
servo p11, range

range = range + speed
counter = counter + increment

if range = 1500 then

range = 0
speed = -500

endif

if range = -1500 then

range = 0
speed = 500

endif

goto sweep:[/code]

the servo starts centered, moves slightly left, then slightly more left. Then it moves to the middle, then it moves to the far left and starts jamming as its over range. This code is horribly inneficient but its like iteration number 7 of trying to fix this problem. it used to look more like

if range is more than max or less then min, speed = (-1)*speed

but that had the same problem. I also tried to set a peice of code that just moved it when it hit far left. When I told it to move to center from far left, it moved. when I told it to move to -200, it went the wrong way again. Any thoughts? It seems to me it’s trying to take the shortest route to the other side, even though it can’t actually go that direction.

missing a pause of some sort in the middle of that loop to allow the servo to actually move?

added a pause 1000 after the servo command, didn’t help. I’ve had it in and out a few times, doesn’t seem to change anything. should I pause later in the loop? thinking about it, it does go to center properly after two jogs left, so I don’t think it’s timing based, but I can’t see where else It could be off.

another note… I was using pulse out with 2700 as center, 1200 as left and 4700 as right, and this code worked fairly well. I was using a speed of 125 with a pause of 40. The servo just moved really slowly, too slow to detect collisions as was planned. When I jumped the speed to 500 the servo just started flicking left to right about 15 degrees instead of the full range.

Malformed pulses or noise/bad connection on the servo control wire can make a servo move in only one direction until it hits the hard stop.

what contoller are you using again please?

Is this an excerpt from the code?

There seems to be a couple of issues I can’t explain.

The first time through the loop, what are the values of range and speed? They don’t seem to be initialized anywhere. That’s why I suspected the posted code was a segment.

The resultant values for range in the pulse command in this code are -1500, -1000, -500, 0, 500, 1000, 1500… Don’t we want them to be in the range of 750 - 2250 (est.)? Hence, most of the values are out of range (and the servo hits the stop), while two of them will send the servo in one direction only.

He must be using either an Atom or an Atom Pro. They have the “servo” command. The servo command is really not very useful for controlling servos. It can do a good job for controlling servo like devices. But there are better ways to control servos from Atoms. If I were going to use the servo command I would it it like this.

[code]position var sword
direction var bit

position = 0
direction = 1 '1 is clockwise and 0 is counterclockwise.

main:
servo p11, position, 5

if direction = 1 then
position = (position +100) max 1500
endif

if position = 1500 then
direction = 0
endif

if direction = 0 then
position = (position -100) min -1500
endif

if position = -1500 then
direction = 1
endif

goto main[/code]

You must use the repeat argument in order to get smooth operation. The code you posted, sorry, but it’s gibberish. :frowning:

The servo command actually produces the pulse and the delay. It’s not able to do anything else when it’s making pulses. I’ve found the repeat argument needs to be used in order for it to work at all and it’s still sort of jerky.

Thanks, it was the repeat that was needed. got it moving properly now! It’s good too because when using the IR sensors I found it reads better when sitting still than when moving, so the jerkyness actually helps the readings. I’m getting almost 5V up close, whereas before it was only like 2V.

edited as I realized I’m stuck in PLC programming thinking…so hard to go between the two