Shop OBEX P1 Docs P2 Docs Learn Events
Help with Ping code — Parallax Forums

Help with Ping code

mikedivmikediv Posts: 825
edited 2010-01-30 02:23 in Propeller 1
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

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2010-01-29 17:37
    Start with a basic description of what servos need ...

    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.
  • hover1hover1 Posts: 1,929
    edited 2010-01-29 17:53
    @Mike
    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
  • mikedivmikediv Posts: 825
    edited 2010-01-30 01:25
    Thanks Mike that makes sense, Hover I agree with you but I had already built my boe bot setup and when I figured out how to get it to work this far I got pretty excited. I have the right servo for my other ping on my BS2 boe bot but when I tried that with my program on my prop boe bot it does the exact same thing , moves 1/4 inch in each direction so its just wasn't the "right servo" my coding was not working I understand I can just leave the pulses on with that servo since it only moves so far then hits the stopper but I really wanted to understand how to move servos any distance I choose then I can apply this not only to this servo but to any other servo ,, using Mikes description I can get a continuous servo to move exactly as far as I want (well almost) so my prop ping is now doing what I want more or less.. Mike I have applied what you said but I still my be missing somehting becuase while it works its rather jerky its almost like it moves right then moves right again before my reverse code is run. ..... Mike didn't you do a write up on how you could use a standard servo and actually read where its position was in a feedback loop I tried to search for it but no luck.
  • hover1hover1 Posts: 1,929
    edited 2010-01-30 01:41
    I think it was Beau that did that one:

    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
    mikediv said...
    Thanks Mike that makes sense, Hover I agree with you but I had already built my boe bot setup and when I figured out how to get it to work this far I got pretty excited. I have the right servo for my other ping on my BS2 boe bot but when I tried that with my program on my prop boe bot it does the exact same thing , moves 1/4 inch in each direction so its just wasn't the "right servo" my coding was not working I understand I can just leave the pulses on with that servo since it only moves so far then hits the stopper but I really wanted to understand how to move servos any distance I choose then I can apply this not only to this servo but to any other servo ,, using Mikes description I can get a continuous servo to move exactly as far as I want (well almost) so my prop ping is now doing what I want more or less.. Mike I have applied what you said but I still my be missing somehting becuase while it works its rather jerky its almost like it moves right then moves right again before my reverse code is run. ..... Mike didn't you do a write up on how you could use a standard servo and actually read where its position was in a feedback loop I tried to search for it but no luck.
  • mikedivmikediv Posts: 825
    edited 2010-01-30 02:23
    Hover at the end of the day I am just going to use the standard servo while I got this to work Thanks Mike its erratic and jerky and your right why re-invent the wheel I ned to spend more time on my programing skills , but at least now I can move servos with some accuracy.

    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.
Sign In or Register to comment.