00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00047 #ifndef _AX12_H_
00048 #define _AX12_H_
00049
00050 #include <aversive.h>
00051 #include <stdlib.h>
00052
00053 #include "ax12_address.h"
00054 #include "ax12_config.h"
00055
00056
00057
00058
00059 #define AX12_STATE_READ 0
00060 #define AX12_STATE_WRITE 1
00061
00062
00063 #define AX12_ERROR_BIT_VOLTAGE 0
00064 #define AX12_ERROR_BIT_ANGLE_LIMIT 1
00065 #define AX12_ERROR_BIT_OVERHEAT 2
00066 #define AX12_ERROR_BIT_RANGE 3
00067 #define AX12_ERROR_BIT_CHECKSUM 4
00068 #define AX12_ERROR_BIT_OVERLOAD 5
00069 #define AX12_ERROR_BIT_INSTRUCTION 6
00070
00071
00072 #define AX12_ERROR_TYPE_NO_ANSWER 0xff
00073 #define AX12_ERROR_TYPE_TIMEOUT 0xfe
00074 #define AX12_ERROR_TYPE_INVALID_PACKET 0xfd
00075 #define AX12_ERROR_TYPE_XMIT_FAILED 0xfc
00076 #define AX12_ERROR_TYPE_BAD_CKSUM 0xfb
00077
00078
00079 #define AX12_BROADCAST_ID 0xFE
00080
00081
00082 #define AX12_PING 0x01
00083 #define AX12_READ 0x02
00084 #define AX12_WRITE 0x03
00085 #define AX12_REG_WRITE 0x04
00086 #define AX12_ACTION 0x05
00087 #define AX12_RESET 0x06
00088 #define AX12_SYNC_WRITE 0x83
00089
00090
00091
00092 typedef struct AX12
00093 {
00094
00095
00096 int8_t (*hardware_send)(uint8_t);
00097
00098
00099
00100 int16_t (*hardware_recv)(void);
00101
00102
00103 void (*hardware_switch)(uint8_t);
00104 } AX12;
00105
00106 typedef struct AX12_Packet
00107 {
00108 uint8_t id;
00109 uint8_t instruction;
00110
00111
00112 uint8_t nparams;
00113 uint8_t params[AX12_MAX_PARAMS];
00114
00115
00116 uint8_t error;
00117
00118 } AX12_Packet;
00119
00120
00121
00122 void AX12_init(AX12 *);
00123
00124
00125
00127 void AX12_set_hardware_send(AX12 *, int8_t(*)(uint8_t));
00128
00130 void AX12_set_hardware_recv(AX12 *, int16_t(*)(void));
00131
00133 void AX12_set_hardware_switch(AX12 *, void(*)(uint8_t));
00134
00135
00136
00138 uint8_t AX12_checksum(AX12_Packet *packet);
00139
00142 uint8_t AX12_send(AX12 *, AX12_Packet *packet);
00143
00144
00145
00146 uint8_t AX12_recv(AX12 *, AX12_Packet *packet);
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00160 uint8_t AX12_write_byte(AX12 *, uint8_t id, AX12_ADDRESS address,
00161 uint8_t data);
00162
00169 uint8_t AX12_write_int(AX12 *, uint8_t id, AX12_ADDRESS address,
00170 uint16_t data);
00171
00174 uint8_t AX12_read_byte(AX12 *, uint8_t id, AX12_ADDRESS address,
00175 uint8_t *val);
00176
00179 uint8_t AX12_read_int(AX12 *, uint8_t id, AX12_ADDRESS address,
00180 uint16_t *val);
00181
00182
00183
00185 uint8_t AX12_set_position(AX12 *,uint8_t id, uint16_t position);
00186
00188 uint8_t AX12_set_position2(AX12 *, uint8_t id, uint16_t position,
00189 uint16_t speed);
00190
00192 uint8_t AX12_set_position3(AX12 *, uint8_t id, uint16_t position,
00193 uint16_t speed, uint16_t torque);
00194
00196 uint8_t AX12_get_position(AX12 *s, uint8_t id, uint16_t *pos);
00197
00199 uint8_t AX12_get_speed(AX12 *s, uint8_t id, uint16_t *speed);
00200
00202 uint8_t AX12_get_load(AX12 *s, uint8_t id, uint16_t *load);
00203
00204
00206 uint8_t AX12_ping(AX12 *, uint8_t id);
00207
00209 uint8_t AX12_reset(AX12 *, uint8_t id);
00210
00211 #endif