2

Despite searching I was not able to find an answer to this question. I have a servo attached to a pin that moves an arm back and forth. The problem is that it moves too quickly. Is there a way within pigpio or some other method to slow down the movement?

(There was an answer posted ~3 years ago that basically said it can't be done here. I was hoping things have advanced since then.)

This is some sample python code that reproduces the problem. Servo is connected to pin 4.

import time
import pigpio
pi = pigpio.pi()

pi.set_servo_pulsewidth(4, 1500)
time.sleep(0.4)
pi.set_servo_pulsewidth(4, 500)

Thanks!

  • 1
    move to intermediate positions – jsotola Aug 19 '19 at 23:25
  • upvote for a clearly presented question – jsotola Aug 19 '19 at 23:26
  • 1
    I will be pedantic and point out that pigpio only uses Broadcom GPIO numbers so that 4 is GPIO 4 (pin 7). – joan Aug 20 '19 at 4:20
2

This may work as an example, give it a start and end position, and the time(seconds) you want it to take to move there. It will break the movement up into 100 incremental moves this will slow down the movement

func moveServo(start,end,delta):  #move from start to end, using delta number of seconds
     incMove=(end-start)/100.0
     incTime=delta/100.0
     for x in range(100):
          pi.set_servo_pulsewidth(4, int(start+x*incMove))
          time.sleep(incTime)
  • I had to modify your first line to "def moveServo(start,end,delta):" – Monk Aug 20 '19 at 20:53
  • Thanks for all your input. I did try the above code on my servo but the movement is still very jerky. I modified it a few different ways to try to smooth it out but no luck. Looks like we'll have to wait a bit longer. :) – Monk Aug 20 '19 at 20:54
  • what do you do to smooth it out? did you try breaking it into more segments? – Chad G Aug 21 '19 at 15:21
  • Yes, I tried to break it into more segments. It's still very jittery though. – Monk Aug 21 '19 at 17:44
  • What if you break it down into increments of 1, find the delta between start and end, break the time into that many segments, and see where you are. Servo quality also plays a factor here, if its sensor can not accurately determine its location, it wont matter how "smooth" the software side is. – Chad G Aug 21 '19 at 18:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.