A class to control a model R/C servo, using a PwmOut
Fork of Servo by
Revision 4:fc2e5d57af37, committed 2016-07-07
- Comitter:
- yruiewyrui3
- Date:
- Thu Jul 07 12:55:07 2016 +0000
- Parent:
- 3:36b69a7ced07
- Commit message:
- .
Changed in this revision
Servo.cpp | Show annotated file Show diff for this revision Revisions of this file |
Servo.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r 36b69a7ced07 -r fc2e5d57af37 Servo.cpp --- a/Servo.cpp Thu Sep 02 17:34:43 2010 +0000 +++ b/Servo.cpp Thu Jul 07 12:55:07 2016 +0000 @@ -43,11 +43,31 @@ float offset = _range * 2.0 * (percent - 0.5); _pwm.pulsewidth(0.0015 + clamp(offset, -_range, _range)); _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)); + // float offset = _range * (degrees / _degrees); + if(degrees>0){ + + kat= 0.00145+ fabs(degrees)*0.00001111; + _pwm.pulsewidth(kat); + + } + + else if (degrees==0){ + kat=0.00145; + _pwm.pulsewidth(kat); + } + + else { + kat= 0.00145- fabs(degrees)*0.00001111; + _pwm.pulsewidth(kat); + } + + //_pwm.pulsewidth(0.00245); + //k=(0.0015 + clamp(offset, -_range, 0.002 +_range)); + } void Servo::calibrate(float range, float degrees) {
diff -r 36b69a7ced07 -r fc2e5d57af37 Servo.h --- a/Servo.h Thu Sep 02 17:34:43 2010 +0000 +++ b/Servo.h Thu Jul 07 12:55:07 2016 +0000 @@ -1,4 +1,4 @@ -/* mbed R/C Servo Library + /* mbed R/C Servo Library * Copyright (c) 2007-2010 sford, cstyles * * Permission is hereby granted, free of charge, to any person obtaining a copy @@ -81,18 +81,19 @@ * @param range Pulsewidth range from center (1.5ms) to maximum/minimum position in seconds * @param degrees Angle from centre to maximum/minimum position in degrees */ - void calibrate(float range = 0.0005, float degrees = 45.0); + void calibrate(float range = 0.0005, float degrees = 90); /** Shorthand for the write and read functions */ Servo& operator= (float percent); Servo& operator= (Servo& rhs); operator float(); -protected: +public: PwmOut _pwm; float _range; float _degrees; float _p; + float kat; }; #endif