Help with Ping code
mikediv
Posts: 825
Guys this is a little piece of my code for my prop boe bot It will make a continues servo go back and forth so I can scan with my ping the problem is I am not fully understanding this becuase no matter how hard I try the servo/ping will only move about a 1/4 inch in each direction I would like it to go a full inch in either direction but no matter what I set for a delay the ping/servo still only moves a 1/4 inch???? Any help would be appreciated or if someone could explain Thank you
spin
458B
Comments
R/C servos are fairly simple devices. They require a logic level control pulse about 50 times a second ranging from 1ms to 2ms in length. This will generally move a servo over about a 180 degree range with 1.5ms corresponding to the center of the range. Some servos will accept pulses from 0.5ms to 2.5ms in length. Continuous motion servos use the pulse to control the speed and direction of the servo with 1.5ms corresponding to a stopped servo and shorter pulses causing rotation in one direction and longer pulses causing rotation in the other direction.
It takes a little while for the servo to actually move and it has to continue to receive control pulses for the desired speed/direction until it reaches the desired position, then it has to receive pulses for stopping and holding that position. Your program doesn't do that. It puts out a single pulse. The motor moves for 20-30ms in that direction (probably about 1/4 inch), then it's told to move in the other direction. Even if you increase the time between pulses, the motor will only move for 20-30ms since it's not getting control pulses every 20ms or so. It will turn itself off until it gets the next control pulse.
Try sending two or more control pulses of the same width about every 20ms and see what happens as you increase the number of pulses.
He's trying to use a continuous rotation servo, which I tried to talk him out of in another thread. For ~$13.00, a standard servo would be much better, and there are plenty of exmples.
Jim
Edit
I see you covered that also.
Post Edited (hover1) : 1/29/2010 5:59:44 PM GMT
http://forums.parallax.com/showthread.php?p=582447
The Servo32 object in the OBEX has the ability to report servo positions after a servo position has been issued, but that is only for standard servos.
I'm glad you got your servo to work, but I don't recall anyone using a continuous servo in your application. I guess if that where the only servo I had on hand I would try it too. It's doable.
Jim
I thought I could stuff my ping/servo code into a cog and let it run just doing the sweep but I still have quite a way to go understanding how to use cogs.