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:
Sat Jan 04 14:47:41 2014 +0000
Revision:
0:5c8cc5bd6403
Child:
1:c14b79e3f39b
initial commit

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 #ifndef MAESTRO
kochansky 0:5c8cc5bd6403 11 #define MAESTRO
kochansky 0:5c8cc5bd6403 12
kochansky 0:5c8cc5bd6403 13 #include "mbed.h"
kochansky 0:5c8cc5bd6403 14
kochansky 0:5c8cc5bd6403 15 /**
kochansky 0:5c8cc5bd6403 16 * Compact Protocol Command Bytes
kochansky 0:5c8cc5bd6403 17 */
kochansky 0:5c8cc5bd6403 18 #define SET_TARGET 0x84;
kochansky 0:5c8cc5bd6403 19 #define SER_MULTUPLE_TARGETS 0x9F;
kochansky 0:5c8cc5bd6403 20 #define SET_SPEED 0x87;
kochansky 0:5c8cc5bd6403 21 #define SET_ACCELERATION 0x89;
kochansky 0:5c8cc5bd6403 22 #define SET_PWM 0x8A;
kochansky 0:5c8cc5bd6403 23 #define GET_POSITION 0x90;
kochansky 0:5c8cc5bd6403 24 #define GET_MOVING_STATE 0x93;
kochansky 0:5c8cc5bd6403 25 #define GET_ERRORS 0xA1;
kochansky 0:5c8cc5bd6403 26 #define GO_HOME 0xA2;
kochansky 0:5c8cc5bd6403 27
kochansky 0:5c8cc5bd6403 28 /**
kochansky 0:5c8cc5bd6403 29 * Pololu Maestro Servo Controller
kochansky 0:5c8cc5bd6403 30 */
kochansky 0:5c8cc5bd6403 31 class Maestro
kochansky 0:5c8cc5bd6403 32 {
kochansky 0:5c8cc5bd6403 33
kochansky 0:5c8cc5bd6403 34 Public:
kochansky 0:5c8cc5bd6403 35
kochansky 0:5c8cc5bd6403 36 /**
kochansky 0:5c8cc5bd6403 37 * Constructor
kochansky 0:5c8cc5bd6403 38 *
kochansky 0:5c8cc5bd6403 39 * @param tx - mbed pin to use for TX serial line
kochansky 0:5c8cc5bd6403 40 * @param rx - mbed pin to use for RX serial line
kochansky 0:5c8cc5bd6403 41 */
kochansky 0:5c8cc5bd6403 42 Maestro(PinName tx, PinName rx);
kochansky 0:5c8cc5bd6403 43
kochansky 0:5c8cc5bd6403 44 /**
kochansky 0:5c8cc5bd6403 45 * Sets the target of a channel to a specified value
kochansky 0:5c8cc5bd6403 46 *
kochansky 0:5c8cc5bd6403 47 * @param channel - number a servo channel
kochansky 0:5c8cc5bd6403 48 * @param target - the pulse width to transmit in units of quarter-microseconds
kochansky 0:5c8cc5bd6403 49 */
kochansky 0:5c8cc5bd6403 50 void setTarget(int channel, int target);
kochansky 0:5c8cc5bd6403 51
kochansky 0:5c8cc5bd6403 52 //void setMultipleTargets(int* channels, int* targets);
kochansky 0:5c8cc5bd6403 53
kochansky 0:5c8cc5bd6403 54 /**
kochansky 0:5c8cc5bd6403 55 * Limits the speed at which a servo channel’s output value changes
kochansky 0:5c8cc5bd6403 56 *
kochansky 0:5c8cc5bd6403 57 * @param channel - number of a servo channel
kochansky 0:5c8cc5bd6403 58 * @param speed - speed of the servo in units of 0.25 μs / (10 ms)
kochansky 0:5c8cc5bd6403 59 */
kochansky 0:5c8cc5bd6403 60 void setSpeed(int channel, int speed);
kochansky 0:5c8cc5bd6403 61
kochansky 0:5c8cc5bd6403 62 /**
kochansky 0:5c8cc5bd6403 63 * Limits the acceleration of a servo channel’s output
kochansky 0:5c8cc5bd6403 64 *
kochansky 0:5c8cc5bd6403 65 * @param channel - number of a servo channel
kochansky 0:5c8cc5bd6403 66 * @param acceleration - acceleration of the servo in units of (0.25 μs) / (10 ms) / (80 ms)
kochansky 0:5c8cc5bd6403 67 */
kochansky 0:5c8cc5bd6403 68 void setAcceleration(int channel, int acceleration);
kochansky 0:5c8cc5bd6403 69 }
kochansky 0:5c8cc5bd6403 70
kochansky 0:5c8cc5bd6403 71 #endif // Maestro