Jonathan Cacace / Servo

Files at this revision

API Documentation at this revision

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) {