Kallums Fork
Fork of SteeringServo by
Diff: SteeringServo.cpp
- Revision:
- 0:5141c5e51f39
- Child:
- 1:88fe796b4c2e
diff -r 000000000000 -r 5141c5e51f39 SteeringServo.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SteeringServo.cpp Fri Jun 23 23:36:13 2017 +0000 @@ -0,0 +1,30 @@ +#include "SteeringServo.h" + +// -- Constructor Function, Need to Initilise PWM Object +SteeringServo::SteeringServo(PinName pin, int centrePW, int minPW, int maxPW) : servo_(pin) + { + servo_.period_us(20000); // -- Set PWM time period (20 ms) + servo_.pulsewidth_us(centrePW); // -- Default Set Steering to Straight Position + minimumPulseWidth_ = minPW; + maximumPulseWidth_ = maxPW; + centrePulseWidth_ = centrePW; + } + +// -- Go to position +void SteeringServo::goToAngle(int pulseWidth){ + // -- Ensure that pulse width doesn't exceed limits + if (pulseWidth < minimumPulseWidth_){ + servo_.pulsewidth_us(minimumPulseWidth_); + } + else if (pulseWidth < minimumPulseWidth_){ + servo_.pulsewidth_us(minimumPulseWidth_); + } + else{ + servo_.pulsewidth_us(pulseWidth); + } + } + +// -- Go to centre (generally used for debugging) +void SteeringServo::goStraight(void){ + servo_.pulsewidth_us(centrePulseWidth_); + } \ No newline at end of file