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 17:24:40 2014 +0000
Revision:
4:ef4d23c023ea
Parent:
3:1c654893354d
Child:
5:0fd491357750
setServoAngle

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 4:ef4d23c023ea 45 /**
kochansky 4:ef4d23c023ea 46 * Sets baud rate
kochansky 4:ef4d23c023ea 47 *
kochansky 4:ef4d23c023ea 48 * @param baud - Baud Rate to be set
kochansky 4:ef4d23c023ea 49 */
kochansky 4:ef4d23c023ea 50 void setBaudRate(uint16_t baud);
kochansky 3:1c654893354d 51
kochansky 0:5c8cc5bd6403 52 /**
kochansky 0:5c8cc5bd6403 53 * Sets the target of a channel to a specified value
kochansky 0:5c8cc5bd6403 54 *
kochansky 0:5c8cc5bd6403 55 * @param channel - number a servo channel
kochansky 0:5c8cc5bd6403 56 * @param target - the pulse width to transmit in units of quarter-microseconds
kochansky 0:5c8cc5bd6403 57 */
kochansky 3:1c654893354d 58 void setTarget(uint8_t channel, uint16_t target);
kochansky 0:5c8cc5bd6403 59
kochansky 4:ef4d23c023ea 60 /**
kochansky 4:ef4d23c023ea 61 * Sets specified channel's servo to a specified angle
kochansky 4:ef4d23c023ea 62 *
kochansky 4:ef4d23c023ea 63 * @param channel - number a servo channel
kochansky 4:ef4d23c023ea 64 * @param angle - target angle of a servo
kochansky 4:ef4d23c023ea 65 */
kochansky 4:ef4d23c023ea 66 void setServoAngle(uint8_t channel, int8_t angle);
kochansky 4:ef4d23c023ea 67
kochansky 0:5c8cc5bd6403 68 //void setMultipleTargets(int* channels, int* targets);
kochansky 0:5c8cc5bd6403 69
kochansky 0:5c8cc5bd6403 70 /**
kochansky 2:39356b408262 71 * Limits the speed at which a servo channel's output value changes
kochansky 0:5c8cc5bd6403 72 *
kochansky 0:5c8cc5bd6403 73 * @param channel - number of a servo channel
kochansky 0:5c8cc5bd6403 74 * @param speed - speed of the servo in units of 0.25 μs / (10 ms)
kochansky 0:5c8cc5bd6403 75 */
kochansky 0:5c8cc5bd6403 76 void setSpeed(int channel, int speed);
kochansky 0:5c8cc5bd6403 77
kochansky 0:5c8cc5bd6403 78 /**
kochansky 2:39356b408262 79 * Limits the acceleration of a servo channel's output
kochansky 0:5c8cc5bd6403 80 *
kochansky 0:5c8cc5bd6403 81 * @param channel - number of a servo channel
kochansky 0:5c8cc5bd6403 82 * @param acceleration - acceleration of the servo in units of (0.25 μs) / (10 ms) / (80 ms)
kochansky 0:5c8cc5bd6403 83 */
kochansky 0:5c8cc5bd6403 84 void setAcceleration(int channel, int acceleration);
kochansky 1:c14b79e3f39b 85
kochansky 1:c14b79e3f39b 86 private:
kochansky 1:c14b79e3f39b 87
kochansky 1:c14b79e3f39b 88 Serial serial;
kochansky 3:1c654893354d 89 Serial pc;
kochansky 1:c14b79e3f39b 90 };
kochansky 0:5c8cc5bd6403 91
kochansky 0:5c8cc5bd6403 92 #endif // Maestro