PM2_Lib
Dependencies: LSM9DS1 RangeFinder FastPWM
Diff: Servo.cpp
- Revision:
- 16:69911e81dfd4
- Parent:
- 10:fe74e8909d3f
- Child:
- 18:21c0a669d6ef
--- a/Servo.cpp Mon Mar 21 13:31:15 2022 +0000 +++ b/Servo.cpp Mon Mar 21 13:47:46 2022 +0000 @@ -3,12 +3,12 @@ Servo::Servo(PinName Pin) : ServoPin(Pin) {} /** - * Sets the desired position. - * @Pos desired position in mus (position/period). + * Sets the desired angle. + * @_Input a value between 0...1. */ -void Servo::SetPosition(int Pos) +void Servo::SetPosition(float _Input) { - Position = Pos; + Position = static_cast<int>(_Input * static_cast<float>(Period)); } void Servo::StartPulse() @@ -23,13 +23,14 @@ } /** - * Enables the servo with start position and period. - * @StartPos start position in mus. - * @Period period in mus. + * Enables the servo with start angle and period. + * @_StartInput a value between 0...1. + * @_Period period in mus. */ -void Servo::Enable(int StartPos, int Period) +void Servo::Enable(float _StartInput, int _Period) { - Position = StartPos; + Period = _Period; + Position = static_cast<int>(_StartInput * static_cast<float>(Period)); Pulse.attach(callback(this, &Servo::StartPulse), std::chrono::microseconds{static_cast<long int>(Period)}); }