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

Revision:
0:5c8cc5bd6403
Child:
1:c14b79e3f39b
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Maestro.h	Sat Jan 04 14:47:41 2014 +0000
@@ -0,0 +1,71 @@
+/**
+ * @author Przemysław Kochański
+ *
+ * @section DESCRIPTION
+ *
+ * Library for Pololu Maestro Servo Controller
+ * Serial Servo Commands: http://www.pololu.com/docs/0J40/5.e
+ */
+
+#ifndef MAESTRO
+#define MAESTRO
+
+#include "mbed.h"
+
+/**
+ * Compact Protocol Command Bytes
+ */
+#define SET_TARGET 0x84;
+#define SER_MULTUPLE_TARGETS 0x9F;
+#define SET_SPEED 0x87;
+#define SET_ACCELERATION 0x89;
+#define SET_PWM 0x8A;
+#define GET_POSITION 0x90;
+#define GET_MOVING_STATE 0x93;
+#define GET_ERRORS 0xA1;
+#define GO_HOME 0xA2;
+
+/**
+ * Pololu Maestro Servo Controller
+ */
+class Maestro
+{
+
+Public:
+
+    /**
+     * Constructor
+     *
+     * @param tx - mbed pin to use for TX serial line
+     * @param rx - mbed pin to use for RX serial line
+     */
+    Maestro(PinName tx, PinName rx);
+
+    /**
+     * Sets the target of a channel to a specified value
+     *
+     * @param channel - number a servo channel
+     * @param target - the pulse width to transmit in units of quarter-microseconds
+     */
+    void setTarget(int channel, int target);
+
+    //void setMultipleTargets(int* channels, int* targets);
+
+    /**
+     * Limits the speed at which a servo channel’s output value changes
+     *
+     * @param channel - number of a servo channel
+     * @param speed - speed of the servo in units of 0.25 μs / (10 ms)
+     */
+    void setSpeed(int channel, int speed);
+
+    /**
+     * Limits the acceleration of a servo channel’s output
+     *
+     * @param channel - number of a servo channel
+     * @param acceleration - acceleration of the servo in units of (0.25 μs) / (10 ms) / (80 ms)
+     */
+    void setAcceleration(int channel, int acceleration);
+}
+
+#endif // Maestro
\ No newline at end of file