Mickaël THEOT / AX12
Embed: (wiki syntax)

« Back to documentation index

AX12 Class Reference

AX12 Class Reference

Servo control class, based on a PwmOut. More...

#include <AX12.h>

Public Member Functions

 AX12 (PinName tx, PinName rx, int ID, int baud)
 Create an AX12 servo object connected to the specified serial port, with the specified ID.
int FactoryReset (void)
 Reset servo to factory settings.
int SetMode (int mode)
 Set the mode of the servo.
int SetGoal (int degrees, int flags=0)
 Set goal angle in integer degrees, in positional mode.
int SetCRSpeed (float speed)
 Set the speed of the servo in continuous rotation mode.
int SetCWLimit (int degrees)
 Set the clockwise limit of the servo.
int SetCCWLimit (int degrees)
 Set the counter-clockwise limit of the servo.
int SetTorque (bool state)
 Enable / disable the motor torque.
int SetMaxTorque (float percentage)
 Set the torque limit of the servo.
int SetBaud (int baud)
 Set baud rate of all attached servos.
int SetID (int CurrentID, int NewID)
 Change the ID of a servo.
int isMoving (void)
 Poll to see if the servo is moving.
void trigger (void)
 Send the broadcast "trigger" command, to activate any outstanding registered commands.
float GetPosition ()
 Read the current angle of the servo.
float GetTemp (void)
 Read the temperature of the servo.
float GetVolts (void)
 Read the supply voltage of the servo.
float GetLoad (void)
 Get the current load (torque) on the servo.

Detailed Description

Servo control class, based on a PwmOut.

Example:

 #include "mbed.h"
 #include "AX12.h"
 //AX12 VDD -> +12V
 //AX12 GND -> GND
 //AX12 Data -> shorted serial port pins (RX&TX connected together)
 
 //F446RE TEST PASSED
 #define TX PC_12
 #define RX PD_2
 #define ID 1
 #define BAUD 1000000
 
 AX12 myax12(TX, RX,ID,BAUD);

 int main() {
     float pos = -1.0;  
         
     while (true)
     {
         myax12.SetGoal(0);    // go to 0 degrees
         wait (2.5);
         pos = myax12.GetPosition();
         printf("Current position (0) : %f \n", pos);
         myax12.SetGoal(300);  // go to 300 degrees
         wait (2.5);
         pos = myax12.GetPosition();
         printf("Current position (300) : %f \n", pos); 
     }
 }

Definition at line 94 of file AX12.h.


Constructor & Destructor Documentation

AX12 ( PinName  tx,
PinName  rx,
int  ID,
int  baud 
)

Create an AX12 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 26 of file AX12.cpp.


Member Function Documentation

int FactoryReset ( void   )

Reset servo to factory settings.

Definition at line 34 of file AX12.cpp.

float GetLoad ( void   )

Get the current load (torque) on the servo.

Returns:
float load (percentage)
Attention:
not very accurate

Definition at line 314 of file AX12.cpp.

float GetPosition ( void   )

Read the current angle of the servo.

Returns:
float in the range 0.0-300.0

Definition at line 270 of file AX12.cpp.

float GetTemp ( void   )

Read the temperature of the servo.

Returns:
float temperature

Definition at line 286 of file AX12.cpp.

float GetVolts ( void   )

Read the supply voltage of the servo.

Returns:
float voltage

Definition at line 298 of file AX12.cpp.

int isMoving ( void   )

Poll to see if the servo is moving.

Returns:
true is the servo is moving

Definition at line 207 of file AX12.cpp.

int SetBaud ( int  baud )

Set baud rate of all attached servos.

Parameters:
mode0x01 = 1,000,000 bps 0x03 = 500,000 bps 0x04 = 400,000 bps 0x07 = 250,000 bps 0x09 = 200,000 bps 0x10 = 115,200 bps 0x22 = 57,600 bps 0x67 = 19,200 bps 0xCF = 9,600 bp

Definition at line 92 of file AX12.cpp.

int SetCCWLimit ( int  degrees )

Set the counter-clockwise limit of the servo.

Parameters:
degrees,0-300

Definition at line 148 of file AX12.cpp.

int SetCRSpeed ( float  speed )

Set the speed of the servo in continuous rotation mode.

Parameters:
speed,-1.0to 1.0 -1.0 = full speed counter clock wise 1.0 = full speed clock wise

Definition at line 106 of file AX12.cpp.

int SetCWLimit ( int  degrees )

Set the clockwise limit of the servo.

Parameters:
degrees,0-300

Definition at line 129 of file AX12.cpp.

int SetGoal ( int  degrees,
int  flags = 0 
)

Set goal angle in integer degrees, in positional mode.

Parameters:
degrees0-300
flags,defaultsto 0 flags[0] = blocking, return when goal position reached flags[1] = register, activate with a broadcast trigger

Definition at line 62 of file AX12.cpp.

int SetID ( int  CurrentID,
int  NewID 
)

Change the ID of a servo.

Parameters:
CurentID1-255
NewID1-255

If a servo ID is not know, the broadcast address of 0 can be used for CurrentID. In this situation, only one servo should be connected to the bus

Definition at line 194 of file AX12.cpp.

int SetMaxTorque ( float  percentage )

Set the torque limit of the servo.

Parameters:
percentage,0.0-1.0

Definition at line 178 of file AX12.cpp.

int SetMode ( int  mode )

Set the mode of the servo.

Parameters:
mode0 = Positional, default 1 = Continuous rotation

Definition at line 44 of file AX12.cpp.

int SetTorque ( bool  state )

Enable / disable the motor torque.

Parameters:
state,true= torque enable false = torque disable

Definition at line 167 of file AX12.cpp.

void trigger ( void   )

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

Definition at line 215 of file AX12.cpp.