Skip to content

Commit 9ba58cf

Browse files
committed
refactor: Standardize error message formatting in Dynamixel implementation for improved readability
1 parent 156b962 commit 9ba58cf

File tree

1 file changed

+22
-17
lines changed

1 file changed

+22
-17
lines changed

src/dynamixel/dynamixel.cpp

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,13 @@ DxlError Dynamixel::InitTorqueStates(
147147
if (disable_torque) {
148148
fprintf(
149149
stderr,
150-
"[InitTorqueStates][comm_id:%03d][ID:%03d] Torque is enabled, disabling torque\n",
151-
it_comm, it_id);
150+
"[InitTorqueStates][comm_id:%03d][ID:%03d] Torque is enabled, disabling torque\n",
151+
it_comm, it_id);
152152
result = WriteItem(it_comm, it_id, "Torque Enable", TORQUE_OFF);
153153
if (result != DxlError::OK) {
154-
fprintf(stderr, "[InitTorqueStates][comm_id:%03d][ID:%03d] Error disabling torque\n",
155-
it_comm, it_id);
154+
fprintf(
155+
stderr, "[InitTorqueStates][comm_id:%03d][ID:%03d] Error disabling torque\n",
156+
it_comm, it_id);
156157
return result;
157158
}
158159
torque_state_[{it_comm, it_id}] = TORQUE_OFF;
@@ -170,13 +171,13 @@ DxlError Dynamixel::InitTorqueStates(
170171

171172
fprintf(
172173
stderr, "[InitTorqueStates][comm_id:%03d][ID:%03d] Current torque state: %s\n", it_comm,
173-
it_id,
174+
it_id,
174175
torque_state_[{it_comm, it_id}] ? "ON" : "OFF");
175176
}
176177
} catch (const std::exception & e) {
177178
fprintf(
178179
stderr, "[InitTorqueStates][comm_id:%03d][ID:%03d] Error checking control item: %s\n",
179-
it_comm, it_id,
180+
it_comm, it_id,
180181
e.what());
181182
return DxlError::CANNOT_FIND_CONTROL_ITEM;
182183
}
@@ -263,8 +264,9 @@ DxlError Dynamixel::InitDxlComm(uint8_t comm_id, uint8_t id)
263264
try {
264265
dxl_info_.ReadDxlModelFile(comm_id, id, dxl_model_number);
265266
} catch (const std::exception & e) {
266-
fprintf(stderr, "[InitDxlComm][comm_id:%03d][ID:%03d] Error reading model file: %s\n", comm_id,
267-
id, e.what());
267+
fprintf(
268+
stderr, "[InitDxlComm][comm_id:%03d][ID:%03d] Error reading model file: %s\n", comm_id,
269+
id, e.what());
268270
return DxlError::CANNOT_FIND_CONTROL_ITEM;
269271
}
270272

@@ -341,8 +343,9 @@ DxlError Dynamixel::InitDxlComm(uint8_t comm_id, uint8_t id)
341343
try {
342344
dxl_info_.ReadDxlModelFile(comm_id, id, dxl_model_number);
343345
} catch (const std::exception & e) {
344-
fprintf(stderr, "[InitDxlComm][comm_id:%03d][ID:%03d] Error reading model file: %s\n", comm_id,
345-
id, e.what());
346+
fprintf(
347+
stderr, "[InitDxlComm][comm_id:%03d][ID:%03d] Error reading model file: %s\n", comm_id,
348+
id, e.what());
346349
return DxlError::CANNOT_FIND_CONTROL_ITEM;
347350
}
348351

@@ -354,7 +357,7 @@ DxlError Dynamixel::InitDxlComm(uint8_t comm_id, uint8_t id)
354357
} catch (const std::exception & e) {
355358
fprintf(
356359
stderr,
357-
"[InitDxlComm][comm_id:%03d][ID:%03d] Error reading firmware-specific model file: %s\n",
360+
"[InitDxlComm][comm_id:%03d][ID:%03d] Error reading firmware-specific model file: %s\n",
358361
comm_id, id, e.what());
359362
}
360363
}
@@ -422,7 +425,7 @@ DxlError Dynamixel::SetDxlReadItems(
422425
if (dxl_info_.GetDxlControlItem(comm_id, id, it_name, ITEM_ADDR, ITEM_SIZE) == false) {
423426
fprintf(
424427
stderr, "[comm_id:%03d][ID:%03d] Cannot find control item in model file : %s\n", comm_id,
425-
id,
428+
id,
426429
it_name.c_str());
427430
return DxlError::CANNOT_FIND_CONTROL_ITEM;
428431
}
@@ -531,7 +534,7 @@ DxlError Dynamixel::SetDxlWriteItems(
531534
if (dxl_info_.GetDxlControlItem(comm_id, id, it_name, ITEM_ADDR, ITEM_SIZE) == false) {
532535
fprintf(
533536
stderr, "[comm_id:%03d][ID:%03d] Cannot find control item in model file : %s\n", comm_id,
534-
id,
537+
id,
535538
it_name.c_str());
536539
return DxlError::CANNOT_FIND_CONTROL_ITEM;
537540
}
@@ -621,8 +624,9 @@ DxlError Dynamixel::DynamixelEnable(const std::vector<std::pair<uint8_t, uint8_t
621624
}
622625
if (torque_state_[{comm_id, id}] == TORQUE_OFF) {
623626
if (WriteItem(comm_id, id, "Torque Enable", TORQUE_ON) < 0) {
624-
fprintf(stderr, "[comm_id:%03d][ID:%03d] Cannot write \"Torque On\" command!\n", comm_id,
625-
id);
627+
fprintf(
628+
stderr, "[comm_id:%03d][ID:%03d] Cannot write \"Torque On\" command!\n", comm_id,
629+
id);
626630
return DxlError::ITEM_WRITE_FAIL;
627631
}
628632
torque_state_[{comm_id, id}] = TORQUE_ON;
@@ -645,8 +649,9 @@ DxlError Dynamixel::DynamixelDisable(
645649
}
646650
if (torque_state_[{comm_id, id}] == TORQUE_ON) {
647651
if (WriteItem(comm_id, id, "Torque Enable", TORQUE_OFF) < 0) {
648-
fprintf(stderr, "[comm_id:%03d][ID:%03d] Cannot write \"Torque Off\" command!\n", comm_id,
649-
id);
652+
fprintf(
653+
stderr, "[comm_id:%03d][ID:%03d] Cannot write \"Torque Off\" command!\n", comm_id,
654+
id);
650655
result = DxlError::ITEM_WRITE_FAIL;
651656
} else {
652657
torque_state_[{comm_id, id}] = TORQUE_OFF;

0 commit comments

Comments
 (0)