12 #include <cm730/read_thread.h>
13 #include <cm730/dynamixel.h>
14 #include <config_server/parameter.h>
15 #include <plot_msgs/plot_manager.h>
29 BRData() { std::memset(
this, 0,
sizeof(BRData)); position = -1; }
44 BRBoard() { std::memset(
this, 0,
sizeof(BRBoard)); }
53 unsigned char ledPanel;
54 unsigned short rgbled5;
55 unsigned short rgbled6;
57 unsigned char voltage;
95 DYNPOW_ON_NODXLTX = 2,
96 DYNPOW_ON_MPACKET = 3,
97 DYNPOW_MIN = DYNPOW_OFF,
98 DYNPOW_MAX = DYNPOW_ON_MPACKET
107 int ping(
int id,
struct timespec* abstime = NULL);
108 void suspend(
double suspendTime);
112 int sendInstruction(
int id,
int inst);
115 int readByte(
int id,
int address,
int* value,
struct timespec* abstime = NULL);
116 int readWord(
int id,
int address,
int* value,
struct timespec* abstime = NULL);
117 int readData(
int id,
int address,
void* data,
size_t size,
struct timespec* abstime = NULL);
120 int readCM730(BRBoard* cm730Data);
121 int bulkRead(std::vector<BRData>* servoData, BRBoard* cm730Data);
122 int updateTxBRPacket(
const std::vector<int>& servos);
123 bool gotCM730Data()
const {
return m_gotCM730Data; }
126 int writeByte(
int id,
int address,
int value);
127 int writeWord(
int id,
int address,
int value);
128 int writeData(
int id,
int address,
void* data,
size_t size);
129 int syncWrite(
int address,
size_t numDataBytes,
size_t numDevices,
const uint8_t* data);
132 int setDynamixelPower(
int value);
133 int getDynamixelPower(DynPowState& state,
struct timespec* abstime = NULL);
134 int getButtonState(
int& value,
struct timespec* abstime = NULL);
135 int beep(
float duration,
int freq);
136 int sound(
int musicIndex);
137 int stopBeep() {
return stopSound(); }
138 int stopSound() {
return writeByte(ID_CM730, P_BUZZER_PLAY_LENGTH, 0); }
141 inline bool isSuspended() {
if(m_isSuspended && !m_unsuspendTime.isZero() && (ros::Time::now() >= m_unsuspendTime)) { unsuspend(); }
return m_isSuspended; }
142 inline int lastFailedID()
const {
return m_lastFailedID; }
143 inline int servoFailCount(
int id)
const {
return ((
id >= 0) && (
id < MAX_DEVICES) ? m_failCount[
id] : -1); }
147 static const char* PATH;
148 static const int BAUDRATE = 1000000;
149 static const int MAX_TX_BYTES = 256;
150 static const int MAX_RX_BYTES = 1024;
151 static const int MAX_DEVICES = 256;
154 inline void pauseSuspend() { m_wasSuspended = m_isSuspended; m_isSuspended =
false; }
155 inline void resumeSuspend() { m_isSuspended = m_wasSuspended; }
158 int txPacket(
unsigned char* txp);
159 int rxPacket(
unsigned char* rxp,
int size,
struct timespec* abstime = NULL);
163 bool parseBRPacket(
unsigned char* rxp,
int size, std::vector<BRData>* servoData, BRBoard* cm730Data);
164 bool parseCM730Data(
unsigned char* data,
int size, BRBoard* cm730Data);
165 int syncRxPacket(
unsigned char* rxp,
int* readSize);
166 unsigned char checksum(
unsigned char* packet);
169 plot_msgs::PlotManagerFS m_PM;
172 config_server::Parameter<bool> m_useBulkReadShortcut;
177 io::ReadThread m_readThread;
178 pthread_t m_readThread_thread;
179 unsigned char m_TxBulkRead[MAX_TX_BYTES];
181 ros::Time m_lastFullBRPacket;
182 int m_failCount[MAX_DEVICES];
185 ros::Time m_unsuspendTime;
187 int m_lastSeenDynPow;
219 INST_REG_WRITE = 0x04,
222 INST_DIGITAL_RESET = 0x07,
223 INST_SYSTEM_READ = 0x0C,
224 INST_SYSTEM_WRITE = 0x0D,
225 INST_REPEAT_BULK = 0x0F,
226 INST_MEGA_CONFIG = 0x68,
227 INST_MEGA_WRITE = 0x69,
228 INST_MEGA_READ = 0x6A,
229 INST_SYNC_WRITE = 0x83,
230 INST_SYNC_REG_WRITE = 0x84,
231 INST_BULK_READ = 0x92
237 ERRBIT_VOLTAGE = 0x01,
238 ERRBIT_ANGLE_LIMIT = 0x02,
239 ERRBIT_OVERHEATING = 0x04,
241 ERRBIT_CHECKSUM = 0x10,
242 ERRBIT_OVERLOAD = 0x20,
243 ERRBIT_INSTRUCTION = 0x40
249 P_MODEL_NUMBER_L = 0,
250 P_MODEL_NUMBER_H = 1,
254 P_RETURN_DELAY_TIME = 5,
255 P_VOLTAGE_LOWER_LIMIT = 12,
256 P_VOLTAGE_UPPER_LIMIT = 13,
259 P_DYNAMIXEL_POWER = 24,
266 P_BATTERY_VOLTAGE = 31,
286 P_ADC0_BATTERY_L = 51,
287 P_ADC0_BATTERY_H = 52,
318 P_BUZZER_PLAY_LENGTH = 83,
320 P_DXLRX_PACKET_CNT_L = 91,
321 P_DXLRX_PACKET_CNT_H = 92,
322 P_DXLRX_OVERFLOW_CNT_L = 93,
323 P_DXLRX_OVERFLOW_CNT_H = 94,
324 P_DXLRX_BUFERROR_CNT_L = 95,
325 P_DXLRX_BUFERROR_CNT_H = 96,
326 P_DXLRX_CHKERROR_CNT_L = 97,
327 P_DXLRX_CHKERROR_CNT_H = 98,
328 P_DXLRX_ORE_CNT_L = 99,
329 P_DXLRX_ORE_CNT_H = 100,
330 P_DXLTX_PACKET_CNT_L = 101,
331 P_DXLTX_PACKET_CNT_H = 102,
332 P_DXLTX_OVERFLOW_CNT_L = 103,
333 P_DXLTX_OVERFLOW_CNT_H = 104,
334 P_DXLTX_BUFERROR_CNT_L = 105,
335 P_DXLTX_BUFERROR_CNT_H = 106,
336 P_PCRX_PACKET_CNT_L = 107,
337 P_PCRX_PACKET_CNT_H = 108,
338 P_PCRX_OVERFLOW_CNT_L = 109,
339 P_PCRX_OVERFLOW_CNT_H = 110,
340 P_PCRX_BUFERROR_CNT_L = 111,
341 P_PCRX_BUFERROR_CNT_H = 112,
342 P_PCRX_CHKERROR_CNT_L = 113,
343 P_PCRX_CHKERROR_CNT_H = 114,
344 P_PCRX_ORE_CNT_L = 115,
345 P_PCRX_ORE_CNT_H = 116,
346 P_PCTX_PACKET_CNT_L = 117,
347 P_PCTX_PACKET_CNT_H = 118,
348 P_PCTX_OVERFLOW_CNT_L = 119,
349 P_PCTX_OVERFLOW_CNT_H = 120,
350 P_PCTX_BUFERROR_CNT_L = 121,
351 P_PCTX_BUFERROR_CNT_H = 122,
362 READ_CM730_ADDRESS = CM730::P_DYNAMIXEL_POWER,
363 READ_CM730_LENGTH = CM730::P_TEMPERATURE - READ_CM730_ADDRESS + 1,
364 READ_SERVO_ADDRESS = DynamixelMX::P_PRESENT_POSITION_L,
365 READ_SERVO_LENGTH = DynamixelMX::P_PRESENT_POSITION_H - READ_SERVO_ADDRESS + 1