Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 5:410179b2719d, committed 2021-09-14
- Comitter:
- anfontanelli
- Date:
- Tue Sep 14 12:09:58 2021 +0000
- Parent:
- 4:9db86f8b4688
- Commit message:
- A
Changed in this revision
| Servo.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/Servo.cpp Wed Nov 06 10:57:46 2019 +0000
+++ b/Servo.cpp Tue Sep 14 12:09:58 2021 +0000
@@ -35,21 +35,21 @@
}
Servo::Servo(PinName pin) : _pwm(pin) {
- _pwm.period_us(20000);
- calibrate();
+ _pwm.period_us(5000);
+ calibrate(0.00054,13.5); //0.00054 = (1440-900)*10^-6 s (range da datasheet between maximum and medium pulse)
write(0.5);
}
void Servo::write(float percent) {
float offset = _range * 2.0 * (percent - 0.5);
- _pwm.pulsewidth(0.0015 + clamp(offset, -_range, _range));
+ //_pwm.pulsewidth(0.001440 + clamp(offset, -_range, _range)); //0.001440 s = pulse at center
_p = clamp(percent, 0.0, 1.0);
}
void Servo::position(float degrees) {
float offset = _range * (degrees / _degrees);
- _pwm.pulsewidth(0.0015 + clamp(offset, -_range, _range));
+ _pwm.pulsewidth(0.001440 + clamp(offset, -_range, _range));
}
void Servo::calibrate(float range, float degrees) {