Servo

Driver for PWM controlled servo motors. More...

Protected Attributes

Type

Name

PwmOut

float

float

float

Public Functions

Type

Name

void

float

void

void

Detailed Description

Servo control class, based on a PwmOut Example:

// Continuously sweep the servo through it's full range
#include "mbed.h"
#include "Servo.h"

Servo myservo(p21);

int main() {
    while(1) {
        for(int i=0; i<100; i++) {
            myservo = i/100.0;
            wait(0.01);
        }
        for(int i=100; i>0; i--) {
            myservo = i/100.0;
            wait(0.01);
        }
    }
}

Protected Attributes Documentation

variable _pwm

PwmOut Servo::_pwm;

variable _range

float Servo::_range;

variable _degrees

float Servo::_degrees;

variable _p

float Servo::_p;

Public Functions Documentation

function Servo

Servo::Servo (
    PinName pin
)

Create a servo object connected to the specified PwmOut pin

Parameters:

  • pin PwmOut pin to connect to

function write

void Servo::write (
    float percent
)

Set the servo position, normalised to it's full range

Parameters:

  • percent A normalised number 0.0-1.0 to represent the full range.

function read

float Servo::read ()

Read the servo motors current position

Parameters:

  • returns A normalised number 0.0-1.0 representing the full range.

function position

void Servo::position (
    float degrees
)

Set the servo position

Parameters:

  • degrees Servo position in degrees

function calibrate

void Servo::calibrate (
    float range = 0.0005,
    float degrees = 45.0
)

Allows calibration of the range and angles for a particular servo

Parameters:

  • range Pulsewidth range from center (1.5ms) to maximum/minimum position in seconds

  • degrees Angle from centre to maximum/minimum position in degrees

function operator=

Servo & Servo::operator= (
    float percent
)

Shorthand for the write and read functions

function operator=

Servo & Servo::operator= (
    Servo & rhs
)

Servo::operator float ()

The documentation for this class was generated from the following file: D:/w/hw-libs/\_libs\_/libraries/Servo.h

Last updated