Kallums Fork

Fork of SteeringServo by James Batchelar

SteeringServo.cpp

Committer:
batchee7
Date:
2017-06-23
Revision:
0:5141c5e51f39
Child:
1:88fe796b4c2e

File content as of revision 0:5141c5e51f39:

#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_);
    }