Kallums Fork
Fork of SteeringServo by
Embed:
(wiki syntax)
Show/hide line numbers
SteeringServo.cpp
00001 #include "SteeringServo.h" 00002 00003 // -- Constructor Function, Need to Initilise PWM Object 00004 SteeringServo::SteeringServo(PinName pin, int centrePW, int minPW, int maxPW) : servo_(pin) 00005 { 00006 servo_.period_us(20000); // -- Set PWM time period (20 ms) 00007 servo_.pulsewidth_us(centrePW); // -- Default Set Steering to Straight Position 00008 minimumPulseWidth_ = minPW; 00009 maximumPulseWidth_ = maxPW; 00010 centrePulseWidth_ = centrePW; 00011 } 00012 00013 // -- Go to position 00014 void SteeringServo::goToAngle(int pulseWidth) 00015 { 00016 // -- Ensure that pulse width doesn't exceed limits 00017 if (pulseWidth < minimumPulseWidth_) 00018 { 00019 pulseWidth = minimumPulseWidth_; 00020 } 00021 else if (pulseWidth > maximumPulseWidth_) 00022 { 00023 pulseWidth = maximumPulseWidth_; 00024 } 00025 00026 servo_.pulsewidth_us(currentPulseWidth_ = pulseWidth); // -- set servo to pulse width and also store it in currentPulseWidth 00027 } 00028 00029 // -- Go to centre (generally used for debugging) 00030 void SteeringServo::goStraight(void) 00031 { 00032 servo_.pulsewidth_us(currentPulseWidth_ = centrePulseWidth_); 00033 } 00034 00035 //-- return the current Pulse Width 00036 int SteeringServo::getPulseWidth(void) 00037 { 00038 return(currentPulseWidth_); 00039 } 00040
Generated on Wed Jul 13 2022 17:25:00 by
1.7.2
