herkulex servo control library
Dependents: HerkuleX-HelloWorld
This herkulex library is based on DongBu Robot documentation and protocol.
http://dasarobot.com/guide/herkulexeng.pdf
Diff: herkulex.h
- Revision:
- 6:1dacff31b77a
- Parent:
- 5:f737e5c70115
--- a/herkulex.h Mon Jan 14 16:24:05 2013 +0000 +++ b/herkulex.h Mon Jan 14 21:03:43 2013 +0000 @@ -144,8 +144,7 @@ //------------------------------------------------------------------------------ // ACK Packet [To Controller(ACK)] -#define CMD_ACK_MASK 0x40 // ACK Packet CMD is Request Packet CMD + 0x40 - +#define CMD_ACK_MASK 0x40 // ACK Packet CMD is Request Packet CMD + 0x40 #define CMD_EEP_WRITE_ACK (CMD_EEP_WRITE|CMD_ACK_MASK) #define CMD_EEP_READ_ACK (CMD_EEP_READ|CMD_ACK_MASK) #define CMD_RAM_WRITE_ACK (CMD_RAM_WRITE|CMD_ACK_MASK) @@ -157,6 +156,27 @@ #define CMD_REBOOT_ACK (CMD_REBOOT|CMD_ACK_MASK) //------------------------------------------------------------------------------ +// Status Error +#define STATUS_OK = 0x00; +#define ERROR_EXCEED_INPUT_VOLTAGE = 0x01; +#define ERROR_EXCEED_POT_LIMIT = 0x02; +#define ERROR_EXCEED_TEMPERATURE_LIMIT = 0x04; +#define ERROR_INVALID_PACKET = 0x08; +#define ERROR_OVERLOAD = 0x10; +#define ERROR_DRIVER_FAULT = 0x20; +#define ERROR_EEP_REG_DISTORT = 0x40; + +//------------------------------------------------------------------------------ +// Status Detail +#define MOVING_FLAG = 0x01; +#define INPOSITION_FLAG = 0x02; +#define CHECKSUM_ERROR = 0x04; // Invalid packet`s detailed information +#define UNKNOWN_COMMAND = 0x08; // Invalid packet`s detailed information +#define EXCEED_REG_RANGE = 0x10; // Invalid packet`s detailed information +#define GARBAGE_DETECTED = 0x20; // Invalid packet`s detailed information +#define MOTOR_ON_FLAG = 0x40; + +//------------------------------------------------------------------------------ // Header #define HEADER 0xFF @@ -245,6 +265,13 @@ */ void txPacket(uint8_t packetSize, uint8_t* data); + /** Receive packet datas + * + * @param packetSize The packet size. + * @param data The receive packet data array. + */ + void rxPacket(uint8_t packetSize, uint8_t* data); + /** Clear error status * * @param id The herkulex servo ID. @@ -254,27 +281,40 @@ /** Set torque setting * * @param id The herkulex servo ID. - * @param cmdTorue The Command for setting of torque (TORQUE_FREE 0x00,BREAK_ON 0x40, TORQUE_ON 0x60) + * @param cmdTorue The Command for setting of torque (TORQUE_FREE 0x00, BREAK_ON 0x40, TORQUE_ON 0x60) */ void setTorque(uint8_t id, uint8_t cmdTorue); - /** move position + /** Position Control * * @param id The herkulex servo ID. * @param position The goal position of herkulex servo. * @param playtime Time to target position. - * @param setLED Select LED and on/off controll (SET_LED_GREEN_ON 0x00,SET_LED_BLUE_ON 0x08, SET_LED_RED_ON 0x10) + * @param setLED Select LED and on/off controll (GLED_ON 0x00,BLED_ON 0x08, RLED_ON 0x10) */ - void movePos(uint8_t id, uint16_t position, uint8_t playtime, uint8_t setLED); + void positionControl(uint8_t id, uint16_t position, uint8_t playtime, uint8_t setLED); - /** turn + /** Velocity Control * * @param id The herkulex servo ID. * @param speed The goal position of herkulex servo. - * @param setLED Select LED and on/off controll (SET_LED_GREEN_ON 0x00,SET_LED_BLUE_ON 0x08, SET_LED_RED_ON 0x10) + * @param setLED Select LED and on/off controll (GLED_ON 0x00,BLED_ON 0x08, RLED_ON 0x10) */ - void turn(uint8_t id, int16_t speed,uint8_t setLED); + void velocityControl(uint8_t id, int16_t speed,uint8_t setLED); + /** Get Status + * + * @param id The herkulex servo ID. + * @return -1 is getStatus failed. other is servo`s status error value. + */ + int8_t getStatus(uint8_t id); + + /** Get Position + * + * @param id The herkulex servo ID. + * @return -1 is getPos failed. other is servo's current position. + */ + int16_t getPos(uint8_t id); private :