Robotis Dynamixel MX-12W Servo Library
Dependents: SpindleBot_1_5b Utilisatio_MX12_V4

This is my attempt to adapt Chris Styles's AX12 library to work with my Dynamixel MX12 servos. This library is still very much a work in progress, and it may have some/many errors in it, but hopefully I will keep improving it to bring it up to snuff.
Dynamixel aficionados should also check out This MX28 library for a completely separate library that provides very similar functionality, and I wish I had known it existed before I started my work...
minimal example
#include "mbed.h"
#include "MX12.h"
int main() {
MX12 mymx12 (p9, p10, 1); // ID=1
while (1) {
mymx12.Set_Goal_Position(0); // go to 0 degrees
wait (2.0);
mymx12.Set_Goal_Position(300); // go to 300 degrees
wait (2.0);
}
}
Diff: MX12.h
- Revision:
- 5:4c118a827f11
- Parent:
- 3:624d04c390b8
--- a/MX12.h Thu Jan 29 22:24:13 2015 +0000
+++ b/MX12.h Tue Feb 10 21:52:40 2015 +0000
@@ -68,17 +68,28 @@
#define MX12_MODE_POSITION 0
#define MX12_MODE_ROTATION 1
+// For now we don't have a both option, since no
+// one should use that anyways.
+enum MX12_Direction {
+ MX12_DIR_IN,
+ MX12_DIR_OUT,
+ MX12_DIR_NONE
+};
+
#define MX12_CW 1
#define MX12_CCW 0
#define MX12_INSTRUCTION_HEADER 0xff
+#define MX12_ERROR_RETURN 255
+#define MX12_NORMAL_RETURN 1
+
// The max delay should be 508us according to:
// http://support.robotis.com/en/product/dynamixel/mx_series/mx-12w.htm#Actuator_Address_05
// And a max character should be 833 us according to:
// (1 byte) / (9600 (bits per second)) = 833 microseconds
// So 1000 should be a decent value, because 9600 bps is for chumps.
-#define MAX_DELAY_BETWEEN_CHARCTERS_IN_US 500
+#define MAX_DELAY_BETWEEN_CHARCTERS_IN_US 1500
#ifndef M_PI
#define M_PI 3.14159265358979323846 /* pi */
@@ -119,9 +130,11 @@
* @param pin rx pin
* @param int ID, the Bus ID of the servo 1-255
*/
- MX12(PinName tx, PinName rx, int ID, int baud_rate=1000000);
+ MX12(PinName tx, PinName rx, PinName tx_enable_pin, PinName rx_enable_pin, int ID, int baud_rate=1000000);
void Init(void);
+
+ void ChangeDir(MX12_Direction dir);
/** clockwise Angle Limit @retval CW Angle Limit in Degrees */ float Get_CW_Angle_Limit(void){return 0.087891*read_short(MX12_REG_CW_ANGLE_LIMIT);}
/** counterclockwise Angle Limit @retval CCW Angle Limit in Degrees */ float Get_CCW_Angle_Limit(void){return 0.087891*read_short(MX12_REG_CCW_ANGLE_LIMIT);}
@@ -289,10 +302,14 @@
//// Variables
Serial mx12_out;
Serial mx12_in;
+ DigitalOut tx_enable;
+ DigitalOut rx_enable;
DigitalOut profileOut;
int _ID;
+ int _baud;
//// Functions
+ int read_raw(char* Status, int bytes=0);
int read(int ID, int start, int length, char* data);
int write(int ID, int start, int length, char* data);