-
Notifications
You must be signed in to change notification settings - Fork 263
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
Comments
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.
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. 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. |
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°. |
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.
by
across the library. |
@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 :) |
@rileyjshaw just in case you have not noticed, your proposed changes have conflicts. |
@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. |
Fully support the above. Additionally, please add a feature to set DEFAULT_PULSE_WIDTH. |
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 --
Copied from original issue: arduino/Arduino#2509
The text was updated successfully, but these errors were encountered: