PM2_Lib
Dependencies: LSM9DS1 RangeFinder FastPWM
Diff: Servo.cpp
- Revision:
- 18:21c0a669d6ef
- Parent:
- 16:69911e81dfd4
- Child:
- 19:518ed284d98b
--- a/Servo.cpp Mon Mar 21 14:03:28 2022 +0000 +++ b/Servo.cpp Tue Mar 22 08:33:25 2022 +0000 @@ -1,5 +1,8 @@ #include "Servo.h" +const float Servo::MIN_INPUT = 0.01f; +const float Servo::MAX_INPUT = 0.99f; + Servo::Servo(PinName Pin) : ServoPin(Pin) {} /** @@ -8,7 +11,10 @@ */ void Servo::SetPosition(float _Input) { + if (_Input < MIN_INPUT) _Input = MIN_INPUT; + if (_Input > MAX_INPUT) _Input = MAX_INPUT; Position = static_cast<int>(_Input * static_cast<float>(Period)); + printf("Position: %d\r\n", Position); } void Servo::StartPulse() @@ -29,8 +35,11 @@ */ void Servo::Enable(float _StartInput, int _Period) { + if (_StartInput < MIN_INPUT) _StartInput = MIN_INPUT; + if (_StartInput > MAX_INPUT) _StartInput = MAX_INPUT; Period = _Period; Position = static_cast<int>(_StartInput * static_cast<float>(Period)); + printf("Position: %d\r\n", Position); Pulse.attach(callback(this, &Servo::StartPulse), std::chrono::microseconds{static_cast<long int>(Period)}); }