A lot of people use the RPi.GPIO servo but one thing about it is that the pulse are made by software.
This mean that when the kernel need to do something it will stop your application , do its stuff and then return to your application.
This is why when you set the servo at a specific position without changing it sometimes it just moves for a brief moment.
On pizero use pigpio.https://abyz.me.uk/rpi/pigpio/python.html
check the PWM! pigpio use dma to set the pulse. This is way more precise.
On your code you are using a threshold. I suppose is when it is on center.
It is wrongly made!
Think about it! your a/d read far left and suddently it read center but since it read center you didn' send the command to go center.
Just get ridd of your theshold!
To smooth it out you could add a small summator and average the A/D for a period of 20ms minimum.
sum A/D value = Factor * old A/D value + (1-Factor) * new A/D value
old A/D value = sum A/D value
use sum A/D value for your servo
Try a factor of 0.6 first! Lower the factor faster the response!
This mean that when the kernel need to do something it will stop your application , do its stuff and then return to your application.
This is why when you set the servo at a specific position without changing it sometimes it just moves for a brief moment.
On pizero use pigpio.https://abyz.me.uk/rpi/pigpio/python.html
check the PWM! pigpio use dma to set the pulse. This is way more precise.
On your code you are using a threshold. I suppose is when it is on center.
It is wrongly made!
Think about it! your a/d read far left and suddently it read center but since it read center you didn' send the command to go center.
Just get ridd of your theshold!
To smooth it out you could add a small summator and average the A/D for a period of 20ms minimum.
sum A/D value = Factor * old A/D value + (1-Factor) * new A/D value
old A/D value = sum A/D value
use sum A/D value for your servo
Try a factor of 0.6 first! Lower the factor faster the response!
Statistics: Posted by danjperron — Thu Feb 01, 2024 2:14 pm