According to the AngularServo documentation in the Gpiozero, one can set an angle for a servo (which of course in fact sets a pulse-width), or a value (where 0 is one end of a range and and 1 is the other, but again, in fact it's setting a pulse-width).

The Servo base class for AngularServo does the same, abstracting from actual pulse-widths and only allowing you to set a nominal value.

I need to be able to set actual pulse-widths - is this possible, using Gpiozero?

I do it with the Python interface from pigpio, but would rather use Gpiozero.

  • What range of pulse widths? – joan Sep 1 '19 at 16:17
  • You must be the joan of pigpio fame. Thank you, I love using pigpio, it's the most accurate way I've found of controlling servos from a Pi. Using Gpiozero as an interface to pigpiod will allow me to mock the interface for development. In answer to your question, I'd like to have the full 500-2500 µS range available in the pigpiod. – Daniele Procida Sep 1 '19 at 16:40
  • Can't you make 0.0 to 1.0 map to 500 to 2500 using the Servo class itself? – joan Sep 1 '19 at 17:02
  • E.g. s=Servo(5, min_pulse_width=0.5/1000.0, max_pulse_width=2.5/1000.0) gives s.min() of 500 and s.max() of 2500. – joan Sep 1 '19 at 17:11
  • I guess I could, but it would introduce an unwanted level of abstraction, as it's partly for educational purposes. I use numpy.polyfit() to produce a polynomial function that maps desired angles to pulse-widths (to account for non-linearity in and differences between motors) and it's desirable in this case for users to work with the concept of actual pulse-width values. – Daniele Procida Sep 1 '19 at 17:11

Your Answer

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

Browse other questions tagged or ask your own question.