Library for Pololu Maestro Servo Controller http://www.pololu.com/docs/0J40

Library for Pololu Maestro Servo Controller

Library docs: https://developer.mbed.org/users/kochansky/code/Maestro/docs/f374c7b60318/classMaestro.html

Example usage:

#include "mbed.h"
#include "Maestro.h"

Maestro maestro(PTC4,PTC3);

int main()
{
    maestro.setBaudRate(9600);

    // limit speed for each servo
    for (uint8_t i = 0; i < 17; i++) {
        maestro.setSpeed(i, 10);
    }

    while (true) {
       // set servo on channel 0 to 90 degrees
       maestro.setServoAngle(0, 90);
       wait(2);

        // set servo on channel 0 to 45 degrees
       maestro.setServoAngle(0, 45);
       wait(2);
    }
}

Serial commands based on manual: http://www.pololu.com/docs/0J40/5.e

Device pinout:

/media/uploads/kochansky/maestro.jpg

Committer:
kochansky
Date:
Sun Jan 05 16:46:14 2014 +0000
Revision:
3:1c654893354d
Parent:
1:c14b79e3f39b
Child:
4:ef4d23c023ea
working

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kochansky 0:5c8cc5bd6403 1 /**
kochansky 0:5c8cc5bd6403 2 * @author Przemysław Kochański
kochansky 0:5c8cc5bd6403 3 *
kochansky 0:5c8cc5bd6403 4 * @section DESCRIPTION
kochansky 0:5c8cc5bd6403 5 *
kochansky 0:5c8cc5bd6403 6 * Library for Pololu Maestro Servo Controller
kochansky 0:5c8cc5bd6403 7 * Serial Servo Commands: http://www.pololu.com/docs/0J40/5.e
kochansky 0:5c8cc5bd6403 8 */
kochansky 0:5c8cc5bd6403 9
kochansky 0:5c8cc5bd6403 10 #include "Maestro.h"
kochansky 0:5c8cc5bd6403 11
kochansky 3:1c654893354d 12 Maestro::Maestro(PinName tx, PinName rx) : serial(tx, rx), pc(USBTX, USBRX)
kochansky 0:5c8cc5bd6403 13 {
kochansky 1:c14b79e3f39b 14 serial.baud(9600);
kochansky 1:c14b79e3f39b 15 serial.format(8, SerialBase::None, 1); //8N1
kochansky 3:1c654893354d 16 }
kochansky 3:1c654893354d 17
kochansky 3:1c654893354d 18 void Maestro::init()
kochansky 3:1c654893354d 19 {
kochansky 3:1c654893354d 20 serial.putc(BAUD_RATE_IDICATION);
kochansky 1:c14b79e3f39b 21 }
kochansky 0:5c8cc5bd6403 22
kochansky 3:1c654893354d 23 void Maestro::setTarget(uint8_t channel, uint16_t target)
kochansky 1:c14b79e3f39b 24 {
kochansky 3:1c654893354d 25 serial.putc(SET_TARGET);
kochansky 3:1c654893354d 26 serial.putc(channel);
kochansky 3:1c654893354d 27 serial.putc(target & 0x7F);
kochansky 3:1c654893354d 28 serial.putc((target >> 7) & 0x7F);
kochansky 0:5c8cc5bd6403 29 }