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:
Maestro.h@1:c14b79e3f39b, 2014-01-05 (annotated)
- Committer:
- kochansky
- Date:
- Sun Jan 05 10:40:26 2014 +0000
- Revision:
- 1:c14b79e3f39b
- Parent:
- 0:5c8cc5bd6403
- Child:
- 2:39356b408262
setTarget
Who changed what in which revision?
User | Revision | Line number | New 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 | 1:c14b79e3f39b | 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 | 0:5c8cc5bd6403 | 45 | /** |
kochansky | 0:5c8cc5bd6403 | 46 | * Sets the target of a channel to a specified value |
kochansky | 0:5c8cc5bd6403 | 47 | * |
kochansky | 0:5c8cc5bd6403 | 48 | * @param channel - number a servo channel |
kochansky | 0:5c8cc5bd6403 | 49 | * @param target - the pulse width to transmit in units of quarter-microseconds |
kochansky | 0:5c8cc5bd6403 | 50 | */ |
kochansky | 0:5c8cc5bd6403 | 51 | void setTarget(int channel, int target); |
kochansky | 0:5c8cc5bd6403 | 52 | |
kochansky | 0:5c8cc5bd6403 | 53 | //void setMultipleTargets(int* channels, int* targets); |
kochansky | 0:5c8cc5bd6403 | 54 | |
kochansky | 0:5c8cc5bd6403 | 55 | /** |
kochansky | 0:5c8cc5bd6403 | 56 | * Limits the speed at which a servo channel’s output value changes |
kochansky | 0:5c8cc5bd6403 | 57 | * |
kochansky | 0:5c8cc5bd6403 | 58 | * @param channel - number of a servo channel |
kochansky | 0:5c8cc5bd6403 | 59 | * @param speed - speed of the servo in units of 0.25 μs / (10 ms) |
kochansky | 0:5c8cc5bd6403 | 60 | */ |
kochansky | 0:5c8cc5bd6403 | 61 | void setSpeed(int channel, int speed); |
kochansky | 0:5c8cc5bd6403 | 62 | |
kochansky | 0:5c8cc5bd6403 | 63 | /** |
kochansky | 0:5c8cc5bd6403 | 64 | * Limits the acceleration of a servo channel’s output |
kochansky | 0:5c8cc5bd6403 | 65 | * |
kochansky | 0:5c8cc5bd6403 | 66 | * @param channel - number of a servo channel |
kochansky | 0:5c8cc5bd6403 | 67 | * @param acceleration - acceleration of the servo in units of (0.25 μs) / (10 ms) / (80 ms) |
kochansky | 0:5c8cc5bd6403 | 68 | */ |
kochansky | 0:5c8cc5bd6403 | 69 | void setAcceleration(int channel, int acceleration); |
kochansky | 1:c14b79e3f39b | 70 | |
kochansky | 1:c14b79e3f39b | 71 | private: |
kochansky | 1:c14b79e3f39b | 72 | |
kochansky | 1:c14b79e3f39b | 73 | Serial serial; |
kochansky | 1:c14b79e3f39b | 74 | }; |
kochansky | 0:5c8cc5bd6403 | 75 | |
kochansky | 0:5c8cc5bd6403 | 76 | #endif // Maestro |