Kallums Fork

Fork of SteeringServo by James Batchelar

Committer:
batchee7
Date:
Wed Sep 06 23:45:13 2017 +0000
Revision:
2:80a7bb0d71af
Parent:
1:88fe796b4c2e
Corrections

Who changed what in which revision?

UserRevisionLine numberNew contents of line
batchee7 0:5141c5e51f39 1 #include "SteeringServo.h"
batchee7 0:5141c5e51f39 2
batchee7 0:5141c5e51f39 3 // -- Constructor Function, Need to Initilise PWM Object
batchee7 0:5141c5e51f39 4 SteeringServo::SteeringServo(PinName pin, int centrePW, int minPW, int maxPW) : servo_(pin)
batchee7 0:5141c5e51f39 5 {
batchee7 0:5141c5e51f39 6 servo_.period_us(20000); // -- Set PWM time period (20 ms)
batchee7 0:5141c5e51f39 7 servo_.pulsewidth_us(centrePW); // -- Default Set Steering to Straight Position
batchee7 0:5141c5e51f39 8 minimumPulseWidth_ = minPW;
batchee7 0:5141c5e51f39 9 maximumPulseWidth_ = maxPW;
batchee7 0:5141c5e51f39 10 centrePulseWidth_ = centrePW;
batchee7 0:5141c5e51f39 11 }
batchee7 0:5141c5e51f39 12
batchee7 0:5141c5e51f39 13 // -- Go to position
Kallum 1:88fe796b4c2e 14 void SteeringServo::goToAngle(int pulseWidth)
Kallum 1:88fe796b4c2e 15 {
Kallum 1:88fe796b4c2e 16 // -- Ensure that pulse width doesn't exceed limits
Kallum 1:88fe796b4c2e 17 if (pulseWidth < minimumPulseWidth_)
Kallum 1:88fe796b4c2e 18 {
batchee7 2:80a7bb0d71af 19 pulseWidth = minimumPulseWidth_;
batchee7 0:5141c5e51f39 20 }
Kallum 1:88fe796b4c2e 21 else if (pulseWidth > maximumPulseWidth_)
Kallum 1:88fe796b4c2e 22 {
Kallum 1:88fe796b4c2e 23 pulseWidth = maximumPulseWidth_;
Kallum 1:88fe796b4c2e 24 }
Kallum 1:88fe796b4c2e 25
Kallum 1:88fe796b4c2e 26 servo_.pulsewidth_us(currentPulseWidth_ = pulseWidth); // -- set servo to pulse width and also store it in currentPulseWidth
Kallum 1:88fe796b4c2e 27 }
batchee7 0:5141c5e51f39 28
batchee7 0:5141c5e51f39 29 // -- Go to centre (generally used for debugging)
Kallum 1:88fe796b4c2e 30 void SteeringServo::goStraight(void)
Kallum 1:88fe796b4c2e 31 {
Kallum 1:88fe796b4c2e 32 servo_.pulsewidth_us(currentPulseWidth_ = centrePulseWidth_);
Kallum 1:88fe796b4c2e 33 }
Kallum 1:88fe796b4c2e 34
Kallum 1:88fe796b4c2e 35 //-- return the current Pulse Width
Kallum 1:88fe796b4c2e 36 int SteeringServo::getPulseWidth(void)
Kallum 1:88fe796b4c2e 37 {
batchee7 2:80a7bb0d71af 38 return(0);
Kallum 1:88fe796b4c2e 39 }
Kallum 1:88fe796b4c2e 40