@@ -199,7 +199,17 @@ DxlError Dynamixel::InitDxlComm(
199
199
if (dxl_comm_result != COMM_SUCCESS) {
200
200
fprintf (stderr, " - COMM_ERROR : %s\n " , packet_handler_->getTxRxResult (dxl_comm_result));
201
201
return DxlError::CANNOT_FIND_CONTROL_ITEM;
202
- } else if (dxl_error != 0 ) {
202
+ }
203
+
204
+ // First, read the model file to get the control table structure
205
+ try {
206
+ dxl_info_.ReadDxlModelFile (it_id, dxl_model_number);
207
+ } catch (const std::exception & e) {
208
+ fprintf (stderr, " [InitDxlComm][ID:%03d] Error reading model file: %s\n " , it_id, e.what ());
209
+ return DxlError::CANNOT_FIND_CONTROL_ITEM;
210
+ }
211
+
212
+ if (dxl_error != 0 ) {
203
213
fprintf (stderr, " - RX_PACKET_ERROR : %s\n " , packet_handler_->getRxPacketError (dxl_error));
204
214
205
215
// Check if Hardware Error Status control item exists
@@ -214,46 +224,38 @@ DxlError Dynamixel::InitDxlComm(
214
224
uint32_t hw_error_status = 0 ;
215
225
DxlError hw_error_result = ReadItem (it_id, " Hardware Error Status" , hw_error_status);
216
226
217
- if (hw_error_result == DxlError::OK) {
218
- fprintf (stderr, " [ID:%03d] Read Hardware Error Status : 0x%x\n " , it_id, hw_error_status);
219
-
220
- std::string error_string = " " ;
221
- uint8_t hw_error_byte = static_cast <uint8_t >(hw_error_status);
222
-
223
- for (int bit = 0 ; bit < 8 ; ++bit) {
224
- if (hw_error_byte & (1 << bit)) {
225
- const HardwareErrorStatusBitInfo * bit_info = get_hardware_error_status_bit_info (bit);
226
- if (bit_info) {
227
- error_string += bit_info->label ;
228
- error_string += " (" + std::string (bit_info->description ) + " )/ " ;
229
- } else {
230
- error_string += " Unknown Error Bit " + std::to_string (bit) + " / " ;
231
- }
227
+ std::string error_string = " " ;
228
+ uint8_t hw_error_byte = static_cast <uint8_t >(hw_error_status);
229
+
230
+ for (int bit = 0 ; bit < 8 ; ++bit) {
231
+ if (hw_error_byte & (1 << bit)) {
232
+ const HardwareErrorStatusBitInfo * bit_info = get_hardware_error_status_bit_info (bit);
233
+ if (bit_info) {
234
+ error_string += bit_info->label ;
235
+ error_string += " (" + std::string (bit_info->description ) + " )/ " ;
236
+ } else {
237
+ error_string += " Unknown Error Bit " + std::to_string (bit) + " / " ;
232
238
}
233
239
}
240
+ }
234
241
235
- if (!error_string.empty ()) {
236
- fprintf (stderr, " [ID:%03d] Hardware Error Details: 0x%x (%d): %s\n " ,
237
- it_id, hw_error_byte, hw_error_byte, error_string.c_str ());
238
- }
242
+ if (!error_string.empty ()) {
243
+ fprintf (stderr, " [ID:%03d] Hardware Error Details: 0x%x (%d): %s\n " ,
244
+ it_id, hw_error_byte, hw_error_byte, error_string.c_str ());
239
245
}
240
246
} else if (error_code_exists) {
241
247
uint32_t error_code = 0 ;
242
248
DxlError error_code_result = ReadItem (it_id, " Error Code" , error_code);
243
249
244
- if (error_code_result == DxlError::OK) {
245
- fprintf (stderr, " [ID:%03d] Read Error Code : 0x%x\n " , it_id, error_code);
246
-
247
- uint8_t error_code_byte = static_cast <uint8_t >(error_code);
248
- if (error_code_byte != 0x00 ) {
249
- const ErrorCodeInfo * error_info = get_error_code_info (error_code_byte);
250
- if (error_info) {
251
- fprintf (stderr, " [ID:%03d] Error Code Details: 0x%x (%s): %s\n " ,
252
- it_id, error_code_byte, error_info->label , error_info->description );
253
- } else {
254
- fprintf (stderr, " [ID:%03d] Error Code Details: 0x%x (Unknown Error Code)\n " ,
255
- it_id, error_code_byte);
256
- }
250
+ uint8_t error_code_byte = static_cast <uint8_t >(error_code);
251
+ if (error_code_byte != 0x00 ) {
252
+ const ErrorCodeInfo * error_info = get_error_code_info (error_code_byte);
253
+ if (error_info) {
254
+ fprintf (stderr, " [ID:%03d] Error Code Details: 0x%x (%s): %s\n " ,
255
+ it_id, error_code_byte, error_info->label , error_info->description );
256
+ } else {
257
+ fprintf (stderr, " [ID:%03d] Error Code Details: 0x%x (Unknown Error Code)\n " ,
258
+ it_id, error_code_byte);
257
259
}
258
260
}
259
261
} else {
@@ -264,7 +266,6 @@ DxlError Dynamixel::InitDxlComm(
264
266
);
265
267
}
266
268
267
- fprintf (stderr, " [ID:%03d] Hardware Error detected, rebooting...\n " , it_id);
268
269
Reboot (it_id);
269
270
return DxlError::DXL_HARDWARE_ERROR;
270
271
} else {
@@ -274,14 +275,6 @@ DxlError Dynamixel::InitDxlComm(
274
275
model_name.c_str ());
275
276
}
276
277
277
- // First, read the model file to get the control table structure
278
- try {
279
- dxl_info_.ReadDxlModelFile (it_id, dxl_model_number);
280
- } catch (const std::exception & e) {
281
- fprintf (stderr, " [InitDxlComm][ID:%03d] Error reading model file: %s\n " , it_id, e.what ());
282
- return DxlError::CANNOT_FIND_CONTROL_ITEM;
283
- }
284
-
285
278
// Read firmware version and reload model file with firmware-specific version if available
286
279
uint8_t firmware_version = 0 ;
287
280
DxlError fw_result = ReadFirmwareVersion (it_id, firmware_version);
@@ -784,6 +777,16 @@ DxlError Dynamixel::ReadItem(uint8_t id, std::string item_name, uint32_t & data)
784
777
return DxlError::ITEM_READ_FAIL;
785
778
}
786
779
} else if (dxl_error != 0 ) {
780
+ bool is_alert = dxl_error & 0x80 ;
781
+ if (is_alert) {
782
+ fprintf (
783
+ stderr,
784
+ " [ReadItem][ID:%03d][comm_id:%03d] RX_PACKET_ERROR : %s\n " ,
785
+ id,
786
+ comm_id,
787
+ packet_handler_->getRxPacketError (dxl_error));
788
+ return DxlError::OK;
789
+ }
787
790
fprintf (
788
791
stderr,
789
792
" [ReadItem][ID:%03d][comm_id:%03d] RX_PACKET_ERROR : %s (retry %d/%d)\n " ,
0 commit comments