Control Servo Speed

Discussion in 'Programmer's Corner' started by wk7au, Jun 26, 2013.

  1. wk7au

    Thread Starter New Member

    Apr 16, 2013
    15
    0
    How do I control the speed of the servo ??

    As an example , it took 2 seconds for my servo to moved from 0.5ms position to 1.5ms AND NOW I wanted to make it only spend 4 seconds to move.

    I tried to add delays for it, it is some sort looks like this...-->

    RB5=1;
    DelayUs(1.3);

    RB5=0;
    DelayUS(18.7);

    RB5=1;
    DelayUs(1.4);

    RB5=0;
    DelayUS(18.6);

    RB5=1;
    DelayUs(1.5);

    RB5=0;
    DelayUS(18.5);

    With this program, it isn't moving smoothly and yeah not nice
    SO any suggestion for me to control the time taken for the servos to move or can I just say the rotation speed of the servos ?

    THANK YOU :)
     
  2. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    increase the granularity of your commands (provided it is still within the ability for the RC servo's control system to decipher) and increase the number of points it moves to.
     
  3. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    It would be nice to have a function that you can just pass speed and target position to, and then it would calculate the intermediate positions for you.
    Also why have you called the millisecond delay DelayUS? Surely Delayms would make more sense.
     
  4. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    Since the RC servo is controlled via a pulse width between 1ms and 2ms, sub-millisecond delays are appropriate.
     
  5. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    With it being called DelayUs, I'd have expected :
    DelayUs(1300), etc
    or
    Delayms(1.3)
    Maybe it's just me....
     
  6. wk7au

    Thread Starter New Member

    Apr 16, 2013
    15
    0

    ya it was ms, typo anyway.
     
  7. wk7au

    Thread Starter New Member

    Apr 16, 2013
    15
    0
    sorry i don't really understand.My program just some sort looks like this..
    for(i=0;i<50;i++)
    {
    RB5=1;
    DelayMs(1.5);

    RB5=0;
    DelayMs(18.5);
    }

    I did modified this for(i=0;i<50;i++) to i<10 or watever but it doesn't worked well too.
     
  8. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,388
    1,605
    Passing a float to a routine that expects an integer is not a good idea. If it compiles at all it will give you unintended results.
     
Loading...