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:
2:39356b408262
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 #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 3:1c654893354d 18 #define SET_TARGET 0x84
kochansky 3:1c654893354d 19 #define SER_MULTUPLE_TARGETS 0x9F
kochansky 3:1c654893354d 20 #define SET_SPEED 0x87
kochansky 3:1c654893354d 21 #define SET_ACCELERATION 0x89
kochansky 3:1c654893354d 22 #define SET_PWM 0x8A
kochansky 3:1c654893354d 23 #define GET_POSITION 0x90
kochansky 3:1c654893354d 24 #define GET_MOVING_STATE 0x93
kochansky 3:1c654893354d 25 #define GET_ERRORS 0xA1
kochansky 3:1c654893354d 26 #define GO_HOME 0xA2
kochansky 3:1c654893354d 27 #define BAUD_RATE_IDICATION 0xAA
kochansky 0:5c8cc5bd6403 28
kochansky 0:5c8cc5bd6403 29 /**
kochansky 0:5c8cc5bd6403 30 * Pololu Maestro Servo Controller
kochansky 0:5c8cc5bd6403 31 */
kochansky 0:5c8cc5bd6403 32 class Maestro
kochansky 0:5c8cc5bd6403 33 {
kochansky 0:5c8cc5bd6403 34
kochansky 1:c14b79e3f39b 35 public:
kochansky 0:5c8cc5bd6403 36
kochansky 0:5c8cc5bd6403 37 /**
kochansky 0:5c8cc5bd6403 38 * Constructor
kochansky 0:5c8cc5bd6403 39 *
kochansky 0:5c8cc5bd6403 40 * @param tx - mbed pin to use for TX serial line
kochansky 0:5c8cc5bd6403 41 * @param rx - mbed pin to use for RX serial line
kochansky 0:5c8cc5bd6403 42 */
kochansky 0:5c8cc5bd6403 43 Maestro(PinName tx, PinName rx);
kochansky 0:5c8cc5bd6403 44
kochansky 3:1c654893354d 45 void init();
kochansky 3:1c654893354d 46
kochansky 0:5c8cc5bd6403 47 /**
kochansky 0:5c8cc5bd6403 48 * Sets the target of a channel to a specified value
kochansky 0:5c8cc5bd6403 49 *
kochansky 0:5c8cc5bd6403 50 * @param channel - number a servo channel
kochansky 0:5c8cc5bd6403 51 * @param target - the pulse width to transmit in units of quarter-microseconds
kochansky 0:5c8cc5bd6403 52 */
kochansky 3:1c654893354d 53 void setTarget(uint8_t channel, uint16_t target);
kochansky 0:5c8cc5bd6403 54
kochansky 0:5c8cc5bd6403 55 //void setMultipleTargets(int* channels, int* targets);
kochansky 0:5c8cc5bd6403 56
kochansky 0:5c8cc5bd6403 57 /**
kochansky 2:39356b408262 58 * Limits the speed at which a servo channel's output value changes
kochansky 0:5c8cc5bd6403 59 *
kochansky 0:5c8cc5bd6403 60 * @param channel - number of a servo channel
kochansky 0:5c8cc5bd6403 61 * @param speed - speed of the servo in units of 0.25 μs / (10 ms)
kochansky 0:5c8cc5bd6403 62 */
kochansky 0:5c8cc5bd6403 63 void setSpeed(int channel, int speed);
kochansky 0:5c8cc5bd6403 64
kochansky 0:5c8cc5bd6403 65 /**
kochansky 2:39356b408262 66 * Limits the acceleration of a servo channel's output
kochansky 0:5c8cc5bd6403 67 *
kochansky 0:5c8cc5bd6403 68 * @param channel - number of a servo channel
kochansky 0:5c8cc5bd6403 69 * @param acceleration - acceleration of the servo in units of (0.25 μs) / (10 ms) / (80 ms)
kochansky 0:5c8cc5bd6403 70 */
kochansky 0:5c8cc5bd6403 71 void setAcceleration(int channel, int acceleration);
kochansky 1:c14b79e3f39b 72
kochansky 1:c14b79e3f39b 73 private:
kochansky 1:c14b79e3f39b 74
kochansky 1:c14b79e3f39b 75 Serial serial;
kochansky 3:1c654893354d 76 Serial pc;
kochansky 1:c14b79e3f39b 77 };
kochansky 0:5c8cc5bd6403 78
kochansky 0:5c8cc5bd6403 79 #endif // Maestro