PM2_Lib

Dependencies:   LSM9DS1 RangeFinder FastPWM

Committer:
pmic
Date:
Thu Feb 10 12:04:36 2022 +0000
Revision:
10:fe74e8909d3f
Parent:
4:9c003c402033
Child:
16:69911e81dfd4
Minor adjustments.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
pmic 0:86129f1b4a93 1 #include "Servo.h"
pmic 4:9c003c402033 2
pmic 4:9c003c402033 3 Servo::Servo(PinName Pin) : ServoPin(Pin) {}
pmic 0:86129f1b4a93 4
pmic 10:fe74e8909d3f 5 /**
pmic 10:fe74e8909d3f 6 * Sets the desired position.
pmic 10:fe74e8909d3f 7 * @Pos desired position in mus (position/period).
pmic 10:fe74e8909d3f 8 */
pmic 4:9c003c402033 9 void Servo::SetPosition(int Pos)
pmic 4:9c003c402033 10 {
pmic 4:9c003c402033 11 Position = Pos;
pmic 4:9c003c402033 12 }
pmic 0:86129f1b4a93 13
pmic 4:9c003c402033 14 void Servo::StartPulse()
pmic 4:9c003c402033 15 {
pmic 4:9c003c402033 16 ServoPin = 1;
pmic 10:fe74e8909d3f 17 PulseStop.attach(callback(this, &Servo::EndPulse), std::chrono::microseconds{static_cast<long int>(Position)});
pmic 4:9c003c402033 18 }
pmic 0:86129f1b4a93 19
pmic 4:9c003c402033 20 void Servo::EndPulse()
pmic 4:9c003c402033 21 {
pmic 4:9c003c402033 22 ServoPin = 0;
pmic 4:9c003c402033 23 }
pmic 0:86129f1b4a93 24
pmic 10:fe74e8909d3f 25 /**
pmic 10:fe74e8909d3f 26 * Enables the servo with start position and period.
pmic 10:fe74e8909d3f 27 * @StartPos start position in mus.
pmic 10:fe74e8909d3f 28 * @Period period in mus.
pmic 10:fe74e8909d3f 29 */
pmic 4:9c003c402033 30 void Servo::Enable(int StartPos, int Period)
pmic 4:9c003c402033 31 {
pmic 4:9c003c402033 32 Position = StartPos;
pmic 10:fe74e8909d3f 33 Pulse.attach(callback(this, &Servo::StartPulse), std::chrono::microseconds{static_cast<long int>(Period)});
pmic 4:9c003c402033 34 }
pmic 0:86129f1b4a93 35
pmic 10:fe74e8909d3f 36 /**
pmic 10:fe74e8909d3f 37 * Disables the servo.
pmic 10:fe74e8909d3f 38 */
pmic 4:9c003c402033 39 void Servo::Disable()
pmic 4:9c003c402033 40 {
pmic 4:9c003c402033 41 Pulse.detach();
pmic 4:9c003c402033 42 }