MRD Lab / MX12

Dependents:   SpindleBot_1_5b Utilisatio_MX12_V4

Embed: (wiki syntax)

« Back to documentation index

MX12 Class Reference

MX12 Class Reference

Dynamixel servo control class. More...

#include <MX12.h>

Public Member Functions

 MX12 (PinName tx, PinName rx, PinName tx_enable_pin, PinName rx_enable_pin, int ID, int baud_rate=1000000)
 Create an MX12 servo object connected to the specified serial port, with the specified ID.
float Get_CW_Angle_Limit (void)
 clockwise Angle Limit
float Get_CCW_Angle_Limit (void)
 counterclockwise Angle Limit
float Get_Max_Torque (void)
 Max.
float Get_Multi_Turn_Offset (void)
 et least significant byte (LSB)
float Get_Goal_Position (void)
 Goal Position.
float Get_Moving_Speed (void)
 Moving Speed.
float Get_Torque_Limit (void)
 Torque Limit.
float Get_Punch (void)
 Punch.
float Get_ID (void)
 ID of Dynamixel.
float Get_Baud_Rate (void)
 Baud Rate of Dynamixel.
float Get_Return_Delay_Time (void)
 Return Delay Time.
float Get_the_Highest_Limit_Temperature (void)
 Internal Limit Temperature.
float Get_the_Lowest_Limit_Voltage (void)
 Lowest Limit Voltage.
float Get_the_Highest_Limit_Voltage (void)
 Highest Limit Voltage.
float Get_Status_Return_Level (void)
 Status Return Level.
float Get_Alarm_LED (void)
 LED for Alarm.
float Get_Alarm_Shutdown (void)
 Shutdown for Alarm.
float Get_Resolution_Divider (void)
 Resolution divider.
float Get_Torque_Enable (void)
 Torque On/Off.
float Get_LED (void)
 LED On/Off.
float Get_D_Gain (void)
 Derivative Gain.
float Get_I_Gain (void)
 Integral Gain.
float Get_P_Gain (void)
 Proportional Gain.
float Get_Lock (void)
 Locking EEPROM.
float Get_Goal_Acceleration (void)
 Goal Acceleration.
float Get_Model_Number (void)
 model number
float Get_Present_Position (void)
 Current Position.
float Get_Present_Speed (void)
 Current Speed.
float Get_Present_Load (void)
 Current Load.
float Get_Version_of_Firmware (void)
 Information on the version of firmware.
float Get_Present_Voltage (void)
 Current Voltage.
float Get_Present_Temperature (void)
 Current Temperature.
float Get_Registered (void)
 Means if Instruction is registered.
float Get_Moving (void)
 Means if there is any movement.
void Set_CW_Angle_Limit (float val)
 clockwise Angle Limit
void Set_CCW_Angle_Limit (float val)
 counterclockwise Angle Limit
void Set_Max_Torque (float val)
 Max.
void Set_Multi_Turn_Offset (float val)
 et least significant byte (LSB)
void Set_Goal_Position (float val)
 Goal Position.
void Set_Moving_Speed (float val)
 Moving Speed.
void Set_Torque_Limit (float val)
 Torque Limit.
void Set_Punch (float val)
 Punch.
void Set_ID (float val)
 ID of Dynamixel.
void Set_Baud_Rate (float val)
 Baud Rate of Dynamixel.
void Set_Return_Delay_Time (float val)
 Return Delay Time.
void Set_the_Highest_Limit_Temperature (float val)
 Internal Limit Temperature.
void Set_the_Lowest_Limit_Voltage (float val)
 Lowest Limit Voltage.
void Set_the_Highest_Limit_Voltage (float val)
 Highest Limit Voltage.
void Set_Status_Return_Level (float val)
 Status Return Level.
void Set_Alarm_LED (float val)
 LED for Alarm.
void Set_Alarm_Shutdown (float val)
 Shutdown for Alarm.
void Set_Resolution_Divider (float val)
 Resolution divider.
void Set_Torque_Enable (float val)
 Torque On/Off.
void Set_LED (float val)
 LED On/Off.
void Set_D_Gain (float val)
 Derivative Gain.
void Set_I_Gain (float val)
 Integral Gain.
void Set_P_Gain (float val)
 Proportional Gain.
void Set_Lock (float val)
 Locking EEPROM.
void Set_Goal_Acceleration (float val)
 Goal Acceleration.
int SetBaud (int target_baud)
 Change the Baud Rate of a servo.
void ChangeUARTBaud (int target_baud=1000000)
 Change the Baud Rate of the UART serial port.
short GetRawPosition (void)
 Read the current angle of the servo.
void Dump_OD_to_Serial (Serial &serialObject)
 Dump everything we know about the servo to serial.
void Scan_For_Dynamixels (bool scan_all_baud_rates=false, int max_id=0xFC)
 Search for all responsive Dynamixels.
int write_short (MX12ODIndex OD, short value)
 Write a raw value to the servo.
short read_short (MX12ODIndex OD)
 Read a raw value from the servo.
void coordinated_move (char id0, short pos0, short vel0, char id1, short pos1, short vel1)
 Perform a coordinated move.
void trigger (void)
 Send the broadcast "trigger" command, to activate any outstanding registered commands.
bool ping (char ID_Num=0xFF)
 Send a ping to a servo.

Detailed Description

Dynamixel servo control class.

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);
   }
 }

Definition at line 123 of file MX12.h.


Constructor & Destructor Documentation

MX12 ( PinName  tx,
PinName  rx,
PinName  tx_enable_pin,
PinName  rx_enable_pin,
int  ID,
int  baud_rate = 1000000 
)

Create an MX12 servo object connected to the specified serial port, with the specified ID.

Parameters:
pintx pin
pinrx pin
intID, the Bus ID of the servo 1-255

Definition at line 11 of file MX12.cpp.


Member Function Documentation

void ChangeUARTBaud ( int  target_baud = 1000000 )

Change the Baud Rate of the UART serial port.

Parameters:
baud_rateThe desired rate in bits per second (Default 1Mbps)
Note:
This doesn't broadcast anything

Definition at line 209 of file MX12.cpp.

void coordinated_move ( char  id0,
short  pos0,
short  vel0,
char  id1,
short  pos1,
short  vel1 
)

Perform a coordinated move.

Right now, it commands two servos with position and velocity, but the code should be extendable to more servos/parameters as needed.

Parameters:
ODObject Dictionary ID from the Enum
valueThe raw value to be written. If the Bytes of the OD is 1, only the lower 8 bits are written.
Returns:
status int

< Hardcoded for now, 2 bytes for pos, 2 bytes for vel

Definition at line 549 of file MX12.cpp.

void Dump_OD_to_Serial ( Serial &  serialObject )

Dump everything we know about the servo to serial.

Warning! This will take a while! At 1Mbps, it will probably take at least 250 ms, so only do this if you have lots of time to spare!

Parameters:
serialObjectWhichever serial object you want to print to, probably pc but maybe bluetooth

Definition at line 112 of file MX12.cpp.

float Get_Alarm_LED ( void   )

LED for Alarm.

Return values:
AlarmLED in Bitmap

Definition at line 154 of file MX12.h.

float Get_Alarm_Shutdown ( void   )

Shutdown for Alarm.

Return values:
AlarmShutdown in Bitmap

Definition at line 155 of file MX12.h.

float Get_Baud_Rate ( void   )

Baud Rate of Dynamixel.

Return values:
BaudRate in Lookup

Definition at line 148 of file MX12.h.

float Get_CCW_Angle_Limit ( void   )

counterclockwise Angle Limit

Return values:
CCWAngle Limit in Degrees

Definition at line 140 of file MX12.h.

float Get_CW_Angle_Limit ( void   )

clockwise Angle Limit

Return values:
CWAngle Limit in Degrees

Definition at line 139 of file MX12.h.

float Get_D_Gain ( void   )

Derivative Gain.

Return values:
DGain in Kd

Definition at line 159 of file MX12.h.

float Get_Goal_Acceleration ( void   )

Goal Acceleration.

Return values:
GoalAcceleration in Degrees

Definition at line 163 of file MX12.h.

float Get_Goal_Position ( void   )

Goal Position.

Return values:
GoalPosition in Degrees

Definition at line 143 of file MX12.h.

float Get_I_Gain ( void   )

Integral Gain.

Return values:
IGain in Ki

Definition at line 160 of file MX12.h.

float Get_ID ( void   )

ID of Dynamixel.

Return values:
IDin int

Definition at line 147 of file MX12.h.

float Get_LED ( void   )

LED On/Off.

Return values:
LEDin Bitmap

Definition at line 158 of file MX12.h.

float Get_Lock ( void   )

Locking EEPROM.

Return values:
Lockin bool

Definition at line 162 of file MX12.h.

float Get_Max_Torque ( void   )

Max.

Torque

Return values:
MaxTorque in Percent

Definition at line 141 of file MX12.h.

float Get_Model_Number ( void   )

model number

Return values:
ModelNumber in Bitmap

Definition at line 164 of file MX12.h.

float Get_Moving ( void   )

Means if there is any movement.

Return values:
Movingin bool

Definition at line 172 of file MX12.h.

float Get_Moving_Speed ( void   )

Moving Speed.

Return values:
MovingSpeed in Degrees/Second

Definition at line 144 of file MX12.h.

float Get_Multi_Turn_Offset ( void   )

et least significant byte (LSB)

Return values:
MultiTurn Offset in Degrees

Definition at line 142 of file MX12.h.

float Get_P_Gain ( void   )

Proportional Gain.

Return values:
PGain in Kp

Definition at line 161 of file MX12.h.

float Get_Present_Load ( void   )

Current Load.

Return values:
PresentLoad in Percent

Definition at line 167 of file MX12.h.

float Get_Present_Position ( void   )

Current Position.

Return values:
PresentPosition in Degrees

Definition at line 165 of file MX12.h.

float Get_Present_Speed ( void   )

Current Speed.

Return values:
PresentSpeed in Degrees/Second

Definition at line 166 of file MX12.h.

float Get_Present_Temperature ( void   )

Current Temperature.

Return values:
PresentTemperature in Celsius

Definition at line 170 of file MX12.h.

float Get_Present_Voltage ( void   )

Current Voltage.

Return values:
PresentVoltage in Volts

Definition at line 169 of file MX12.h.

float Get_Punch ( void   )

Punch.

Return values:
Punchin Percent

Definition at line 146 of file MX12.h.

float Get_Registered ( void   )

Means if Instruction is registered.

Return values:
Registeredin bool

Definition at line 171 of file MX12.h.

float Get_Resolution_Divider ( void   )

Resolution divider.

Return values:
ResolutionDivider in Ratio

Definition at line 156 of file MX12.h.

float Get_Return_Delay_Time ( void   )

Return Delay Time.

Return values:
ReturnDelay Time in milliseconds

Definition at line 149 of file MX12.h.

float Get_Status_Return_Level ( void   )

Status Return Level.

Return values:
StatusReturn Level in int

Definition at line 153 of file MX12.h.

float Get_the_Highest_Limit_Temperature ( void   )

Internal Limit Temperature.

Return values:
theHighest Limit Temperature in Celsius

Definition at line 150 of file MX12.h.

float Get_the_Highest_Limit_Voltage ( void   )

Highest Limit Voltage.

Return values:
theHighest Limit Voltage in Volts

Definition at line 152 of file MX12.h.

float Get_the_Lowest_Limit_Voltage ( void   )

Lowest Limit Voltage.

Return values:
theLowest Limit Voltage in Volts

Definition at line 151 of file MX12.h.

float Get_Torque_Enable ( void   )

Torque On/Off.

Return values:
TorqueEnable in bool

Definition at line 157 of file MX12.h.

float Get_Torque_Limit ( void   )

Torque Limit.

Return values:
TorqueLimit in Percent

Definition at line 145 of file MX12.h.

float Get_Version_of_Firmware ( void   )

Information on the version of firmware.

Return values:
Versionof Firmware in int

Definition at line 168 of file MX12.h.

short GetRawPosition ( void   )

Read the current angle of the servo.

Returns:
short in the range 0-4095

Definition at line 214 of file MX12.cpp.

bool ping ( char  ID_Num = 0xFF )

Send a ping to a servo.

No matter what it should respond. Use this to see if a servo exists.

Parameters:
ID_Numthe ID of the servo in question, 0 to 252 (0xFC) can be used, defaults to current object ID
Returns:
true if any response received, otherwise false

Definition at line 740 of file MX12.cpp.

short read_short ( MX12ODIndex  OD )

Read a raw value from the servo.

Parameters:
ODObject Dictionary ID from the Enum
Returns:
The raw value to be read. If the Bytes of the OD is 1, only the lower 8 bits are used.

Definition at line 244 of file MX12.cpp.

void Scan_For_Dynamixels ( bool  scan_all_baud_rates = false,
int  max_id = 0xFC 
)

Search for all responsive Dynamixels.

Warning! This will take a considerable amount of time if scanning the whole range! I haven't tried it, but off the top of my head it should take at least 3 seconds, probably more.

Parameters:
scan_all_baud_ratesif true, scan all 12 known Dynamixel baud rates. Default false, scans only current UART baud rate.
max_idscan from zero to this value, defaults to 0xFC which is the max possible for a Dynamixel.

Definition at line 149 of file MX12.cpp.

void Set_Alarm_LED ( float  val )

LED for Alarm.

Parameters:
valAlarm LED in Bitmap

Definition at line 189 of file MX12.h.

void Set_Alarm_Shutdown ( float  val )

Shutdown for Alarm.

Parameters:
valAlarm Shutdown in Bitmap

Definition at line 190 of file MX12.h.

void Set_Baud_Rate ( float  val )

Baud Rate of Dynamixel.

Parameters:
valBaud Rate in Lookup

Definition at line 183 of file MX12.h.

void Set_CCW_Angle_Limit ( float  val )

counterclockwise Angle Limit

Parameters:
valCCW Angle Limit in Degrees

Definition at line 175 of file MX12.h.

void Set_CW_Angle_Limit ( float  val )

clockwise Angle Limit

Parameters:
valCW Angle Limit in Degrees

Definition at line 174 of file MX12.h.

void Set_D_Gain ( float  val )

Derivative Gain.

Parameters:
valD Gain in Kd

Definition at line 194 of file MX12.h.

void Set_Goal_Acceleration ( float  val )

Goal Acceleration.

Parameters:
valGoal Acceleration in Degrees

Definition at line 198 of file MX12.h.

void Set_Goal_Position ( float  val )

Goal Position.

Parameters:
valGoal Position in Degrees

Definition at line 178 of file MX12.h.

void Set_I_Gain ( float  val )

Integral Gain.

Parameters:
valI Gain in Ki

Definition at line 195 of file MX12.h.

void Set_ID ( float  val )

ID of Dynamixel.

Parameters:
valID in int

Definition at line 182 of file MX12.h.

void Set_LED ( float  val )

LED On/Off.

Parameters:
valLED in Bitmap

Definition at line 193 of file MX12.h.

void Set_Lock ( float  val )

Locking EEPROM.

Parameters:
valLock in bool

Definition at line 197 of file MX12.h.

void Set_Max_Torque ( float  val )

Max.

Torque

Parameters:
valMax Torque in Percent

Definition at line 176 of file MX12.h.

void Set_Moving_Speed ( float  val )

Moving Speed.

Parameters:
valMoving Speed in Degrees/Second

Definition at line 179 of file MX12.h.

void Set_Multi_Turn_Offset ( float  val )

et least significant byte (LSB)

Parameters:
valMulti Turn Offset in Degrees

Definition at line 177 of file MX12.h.

void Set_P_Gain ( float  val )

Proportional Gain.

Parameters:
valP Gain in Kp

Definition at line 196 of file MX12.h.

void Set_Punch ( float  val )

Punch.

Parameters:
valPunch in Percent

Definition at line 181 of file MX12.h.

void Set_Resolution_Divider ( float  val )

Resolution divider.

Parameters:
valResolution Divider in Ratio

Definition at line 191 of file MX12.h.

void Set_Return_Delay_Time ( float  val )

Return Delay Time.

Parameters:
valReturn Delay Time in milliseconds

Definition at line 184 of file MX12.h.

void Set_Status_Return_Level ( float  val )

Status Return Level.

Parameters:
valStatus Return Level in int

Definition at line 188 of file MX12.h.

void Set_the_Highest_Limit_Temperature ( float  val )

Internal Limit Temperature.

Parameters:
valthe Highest Limit Temperature in Celsius

Definition at line 185 of file MX12.h.

void Set_the_Highest_Limit_Voltage ( float  val )

Highest Limit Voltage.

Parameters:
valthe Highest Limit Voltage in Volts

Definition at line 187 of file MX12.h.

void Set_the_Lowest_Limit_Voltage ( float  val )

Lowest Limit Voltage.

Parameters:
valthe Lowest Limit Voltage in Volts

Definition at line 186 of file MX12.h.

void Set_Torque_Enable ( float  val )

Torque On/Off.

Parameters:
valTorque Enable in bool

Definition at line 192 of file MX12.h.

void Set_Torque_Limit ( float  val )

Torque Limit.

Parameters:
valTorque Limit in Percent

Definition at line 180 of file MX12.h.

int SetBaud ( int  target_baud )

Change the Baud Rate of a servo.

Parameters:
baud_rateThe desired rate in bits per second.
Note:
Not all baud rates will be met exactly!

The maths for this function are a bit odd, see here: http://support.robotis.com/en/product/dynamixel/mx_series/mx-12w.htm#Actuator_Address_04

TABLE OF VALID BAUD RATES: Data Set BPS Target Tolerance 1 1000000 1000000  0.000 3 500000 500000  0.000 4 400000 400000  0.000 7 250000 250000  0.000 9 200000 200000  0.000 16 117647.1 115200 -2.124 34 57142.9 57600  0.794 103 19230.8 19200 -0.160 207 9615.4 9600 -0.160 250 2250000 2250000  0.000 251 2500000 2500000  0.000 252 3000000 3000000  0.000

Definition at line 179 of file MX12.cpp.

void trigger ( void   )

Send the broadcast "trigger" command, to activate any outstanding registered commands.

Definition at line 679 of file MX12.cpp.

int write_short ( MX12ODIndex  OD,
short  value 
)

Write a raw value to the servo.

Parameters:
ODObject Dictionary ID from the Enum
valueThe raw value to be written. If the Bytes of the OD is 1, only the lower 8 bits are written.
Returns:
status int

Definition at line 221 of file MX12.cpp.