Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Servo library for more standard default pulse widths #3

Open
agdl opened this issue Jul 12, 2016 · 7 comments
Open

Update Servo library for more standard default pulse widths #3

agdl opened this issue Jul 12, 2016 · 7 comments
Assignees
Labels
topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project

Comments

@agdl
Copy link
Member

agdl commented Jul 12, 2016

From @bhuang10000 on December 23, 2014 19:33

The Servo library uses a default pulse width of 544 uS to 2400 uS -- with a zero/neutral position at 1472 uS?

This does not coincide with any standard servos that I've seen. Most servos (like HiTech or other generic ones) operate on a rage from 900 uS to 2100 uS with a neutral position (90 deg) at 1500 uS. The "default pulse width" is set to 1500, but this is not the same as 90 degrees on the servo.

Suggest changing the default settings to align with 900 uS and 2100 uS --

# define MIN_PULSE_WIDTH       900     // the shortest pulse sent to a servo
# define MAX_PULSE_WIDTH      2100     // the longest pulse sent to a servo
# define DEFAULT_PULSE_WIDTH  1500     // default pulse width when servo is attached

Copied from original issue: arduino/Arduino#2509

rileyjshaw added a commit to rileyjshaw/Servo that referenced this issue Apr 5, 2019
R/C servos have a standard pulse width range of 1000 to 2000µs<sup name="a1">[1](#f1)</sup>, with the zero point between the two at 1500µs. Currently, Arduino's Servo library sets:

- [`#define MIN_PULSE_WIDTH 544`](https://github.com/arduino-libraries/Servo/blob/4970d615a13f4c0d08026ee361cc8a01974924a2/src/Servo.h#L80)
- [`#define MAX_PULSE_WIDTH 2400`](https://github.com/arduino-libraries/Servo/blob/4970d615a13f4c0d08026ee361cc8a01974924a2/src/Servo.h#L81)
- [`#define DEFAULT_PULSE_WIDTH 1500`](https://github.com/arduino-libraries/Servo/blob/4970d615a13f4c0d08026ee361cc8a01974924a2/src/Servo.h#L82)

This causes a lot of confusion<sup name="a2">[2](#f2)</sup>, especially since [the docs say `write(90)` should correspond to the mid-point] (https://www.arduino.cc/en/Reference/ServoWrite); in actuality, it results in a call to `writeMicroseconds(1472)`<sup name="a3">[3](#f3)</sup>.

This change adjusts the defaults to align with R/C standards. Specifically,

- `write(0)` now corresponds to the standard min pulse width of 1000µs.
- `write(90)` now corresponds to the standard zero point pulse width, and aligns with the library's `DEFAULT_PULSE_WIDTH` variable.
- `write(180)` now corresponds to the standard max pulse width of 2000µs.

Tested on an Arduino Uno with a [Tower Pro Micro Servo SG90](http://www.ee.ic.ac.uk/pcheung/teaching/DE1_EE/stores/sg90_datasheet.pdf), and a [Parallax Feedback 360° High-Speed Servo](https://parallax.com/sites/default/files/downloads/900-00360-Feedback-360-HS-Servo-v1.2.pdf).

---

<a name="f1" href="#a1">1</a>: For example, http://www.ee.ic.ac.uk/pcheung/teaching/DE1_EE/stores/sg90_datasheet.pdf

<a name="f2" href="#a2">2</a>: For instance:

 - julianduque/beaglebone-io#54
 - arduino-libraries#3
 - https://toolguyd.com/oscilloscope-arduino-servo-pwm-signal-mistakes/
 - https://makezine.com/2014/04/23/arduinos-servo-library-angles-microseconds-and-optional-command-parameters/

I also see a _lot_ of posts on https://forum.arduino.cc about this.

<a name="f3" href="#a3">3</a>: There is actually no way to set a standard servo to the zero-point using `write(angle)`; the closest you can get is `write(92)`, for a pulse of 1504µs.
@dok-net
Copy link

dok-net commented Jan 21, 2020

It could be obvious from the namings, MAX_xxx on the hand side, DEFAULT_xxx on the other, that there is an issue with outer boundaries of the SW implementation and what should be safe (as in don't catch fire) defaults min and max.
In my case, I have had a brand manufacturer servo (Tower Pro SG90) destroyed by the default's timings used here, and none of the servos I own does really well - as in healthy - with the defaults in the full sweep example.

So, please fix the library to allow whatever MIN/MAX is deemed to be in use "out there", but set the DEFAULTs for the 0° and 180° timings in µs to either the specification's 1000µs/2000µs, 900µs/2100µs from this issue's author, or my 800µs/2190µs empirically determined on 5 servos.

On second look, reading the source, I find that here there's no outer limits, one can down to 0µs timings and whatever max they come up with. I come from the ESP8266 servo implementation that enforces absolute outer limits.

@dok-net
Copy link

dok-net commented Jan 21, 2020

About 1500µs and 90°, it would seem to be a general agreement that manufacturers share, despite their use of varying timings for 0° and 180°.

@dok-net
Copy link

dok-net commented Jan 21, 2020

Dear @cmaglie, I am kindly asking you to revisit this issue and read what happened to me (on ESP8266). This issue obviously exists across all platforms. For standard timing servos, 1000/1500/2000µs is the specified timing, for highspeed servos, the center at DEFAULT_PULSE_WIDTH 1500 is completely different (1/2, 1/4), so I can reasonably say that the current defaults, somewhat confusingly called MIN/MAX, are not a great service to anyone.
The change that I am suggesting would be to substitute:

#define MIN_PULSE_WIDTH       544     // the shortest pulse sent to a servo  
#define MAX_PULSE_WIDTH      2400     // the longest pulse sent to a servo 

by

#define DEFAULT_MIN_PULSE_WIDTH       1000     // the shortest pulse sent to a servo  
#define DEFAULT_MAX_PULSE_WIDTH      2000     // the longest pulse sent to a servo 

across the library.
If you consider this appropriate (please do so :-) ), I'd make available a PR to that effect.
Otherwise, I am also fine with the values 900/2100 suggested by this issues original author, whereas I maintain my personal measurements gave 800µs/2190µs for a full sweep that is safe, in that it does not force any of the servos I tried outside their mechanical range of operation (0° - 90° - 180°)

@rileyjshaw
Copy link

Dear @cmaglie, I am kindly asking you to revisit this issue and read what happened to me (on ESP8266). This issue obviously exists across all platforms. For standard timing servos, 1000/1500/2000µs is the specified timing, for highspeed servos, the center at DEFAULT_PULSE_WIDTH 1500 is completely different (1/2, 1/4), so I can reasonably say that the current defaults, somewhat confusingly called MIN/MAX, are not a great service to anyone.
The change that I am suggesting would be to substitute:

#define MIN_PULSE_WIDTH       544     // the shortest pulse sent to a servo  
#define MAX_PULSE_WIDTH      2400     // the longest pulse sent to a servo 

by

#define DEFAULT_MIN_PULSE_WIDTH       1000     // the shortest pulse sent to a servo  
#define DEFAULT_MAX_PULSE_WIDTH      2000     // the longest pulse sent to a servo 

across the library.
If you consider this appropriate (please do so :-) ), I'd make available a PR to that effect.
Otherwise, I am also fine with the values 900/2100 suggested by this issues original author, whereas I maintain my personal measurements gave 800µs/2190µs for a full sweep that is safe, in that it does not force any of the servos I tried outside their mechanical range of operation (0° - 90° - 180°)

@dok-net just to add a cross-reference, there's already a PR open with your proposed changes #24. Sadly there's been no response on the PR over the past 1.5 years, but I'm keeping my fingers crossed :)

@d-a-v
Copy link

d-a-v commented Oct 27, 2020

@rileyjshaw just in case you have not noticed, your proposed changes have conflicts.

@rileyjshaw
Copy link

@d-a-v that's because it's been sitting unreviewed for 1.5 years. As I mention in the PR comments I'm happy to fix the conflicts, but I'd like some input from a maintainer before spending more time on it.

@per1234 per1234 added type: imperfection Perceived defect in any part of project and removed Library: Servo labels Jan 9, 2021
@vdneut
Copy link

vdneut commented Dec 13, 2021

Fully support the above. Additionally, please add a feature to set DEFAULT_PULSE_WIDTH.
Currently it is set to 1500 (approx 90dgr), but that leaves -90/+90 from home position at Arduino startup.
While sometimes you need 0dgr from startup (don't want sudden change from 0dgr to 90dgr) up to 180dgr.

@per1234 per1234 added the topic: code Related to content of the project itself label Jul 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project
Projects
None yet
Development

No branches or pull requests

7 participants