Public Member Functions | Protected Attributes | List of all members
Servo Class Reference

#include <Servo.h>

Public Member Functions

void calibrate (float range=0.0005, float degrees=45.0)
 
 operator float ()
 
Servooperator= (float percent)
 
Servooperator= (Servo &rhs)
 
void position (float degrees)
 
float read ()
 
 Servo (PinName pin)
 
void write (float percent)
 

Protected Attributes

float _degrees
 
float _p
 
PwmOut _pwm
 
float _range
 

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

Definition at line 52 of file Servo.h.

Constructor & Destructor Documentation

Servo::Servo ( PinName  pin)

Create a servo object connected to the specified PwmOut pin

Parameters
pinPwmOut pin to connect to

Member Function Documentation

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

Allows calibration of the range and angles for a particular servo

Parameters
rangePulsewidth range from center (1.5ms) to maximum/minimum position in seconds
degreesAngle from centre to maximum/minimum position in degrees
Servo::operator float ( )
Servo& Servo::operator= ( float  percent)

Shorthand for the write and read functions

Servo& Servo::operator= ( Servo rhs)
void Servo::position ( float  degrees)

Set the servo position

Parameters
degreesServo position in degrees
float Servo::read ( )

Read the servo motors current position

Parameters
returnsA normalised number 0.0-1.0 representing the full range.
void Servo::write ( float  percent)

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

Parameters
percentA normalised number 0.0-1.0 to represent the full range.

Member Data Documentation

float Servo::_degrees
protected

Definition at line 94 of file Servo.h.

float Servo::_p
protected

Definition at line 95 of file Servo.h.

PwmOut Servo::_pwm
protected

Definition at line 92 of file Servo.h.

float Servo::_range
protected

Definition at line 93 of file Servo.h.


The documentation for this class was generated from the following file:


rosserial_mbed
Author(s): Gary Servin
autogenerated on Mon Jun 10 2019 14:53:26