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 10:40:26 2014 +0000
Revision:
1:c14b79e3f39b
Parent:
0:5c8cc5bd6403
Child:
3:1c654893354d
setTarget

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 1:c14b79e3f39b 12 Maestro::Maestro(PinName tx, PinName rx) : serial(tx, rx)
kochansky 0:5c8cc5bd6403 13 {
kochansky 1:c14b79e3f39b 14 serial.baud(9600);
kochansky 1:c14b79e3f39b 15 serial.format(8, SerialBase::None, 1); //8N1
kochansky 1:c14b79e3f39b 16 char command[1];
kochansky 1:c14b79e3f39b 17 command[0] = BAUD_RATE_IDICATION;
kochansky 1:c14b79e3f39b 18 serial.puts(command);
kochansky 1:c14b79e3f39b 19 }
kochansky 0:5c8cc5bd6403 20
kochansky 1:c14b79e3f39b 21 void Maestro::setTarget(int channel, int target)
kochansky 1:c14b79e3f39b 22 {
kochansky 1:c14b79e3f39b 23 char command[4];
kochansky 1:c14b79e3f39b 24 command[0] = SET_TARGET;
kochansky 1:c14b79e3f39b 25 command[1] = channel;
kochansky 1:c14b79e3f39b 26 command[2] = target & 0x7F;
kochansky 1:c14b79e3f39b 27 command[3] = (target >> 7) & 0x7F;
kochansky 1:c14b79e3f39b 28 serial.puts(command);
kochansky 0:5c8cc5bd6403 29 }