Reputation: 73
I want to make smooth move with servo motor from 0 to 180 degrees and vice versa. I only know three values: 2.5 duty cycles for 0 degrees,7.5 duty cycles for 90 degrees and 12.5 duty cycles for 180 degrees. I want to make smooth move between all angles so i want some sort of function that return the duty cycle for every angle. I found this function Dc(d)=d/10+2.5, but it doesn't work.
I use these command to set a pwm pin
GPIO.setup(servo,GPIO.OUT)
pwm2 = GPIO.PWM(servo,50)
Upvotes: 1
Views: 5766
Reputation: 556
You can use the following function
def get_pwm(angle):
return (angle/18.0) + 2.5
This function will give you the required PWM given an angle. Your question tells that for 0 degrees -> PWM is 2.5, 90 degrees -> PWM is 7.5 and 180 degrees -> PWM is 12.5
. This shows that the PWM and angle have a linear relation. However, the starting value of PWM is 2.5 when angle is 0 degrees.
Upvotes: 1