Skip to content

Commit f6268a5

Browse files
committed
♻️ refactor TestESC to template and cleanup formatting
1 parent cacca0f commit f6268a5

File tree

2 files changed

+9
-13
lines changed

2 files changed

+9
-13
lines changed

robots/include/sabo_robot.hpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,15 @@ class SaboRobot : public MowerRobot {
4747
return charger_.getChargerStatus();
4848
}
4949

50-
bool TestESC(VescDriver& motor_driver);
50+
template <typename EscDriver>
51+
bool TestESC(EscDriver& motor_driver) {
52+
if (!motor_driver.IsStarted()) return false;
53+
if (motor_driver.GetLatestState().status == MotorDriver::ESCState::ESCStatus::ESC_STATUS_DISCONNECTED) {
54+
motor_driver.RequestStatus();
55+
chThdSleepMilliseconds(100); // give it a chance to respond
56+
}
57+
return motor_driver.GetLatestState().status == MotorDriver::ESCState::ESCStatus::ESC_STATUS_OK;
58+
}
5159
bool TestLeftESC() {
5260
return TestESC(left_motor_driver_);
5361
}

robots/src/sabo_robot.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,3 @@ bool SaboRobot::IsHardwareSupported() {
4444

4545
return false;
4646
}
47-
48-
bool SaboRobot::TestESC(VescDriver& motor_driver) {
49-
if (!motor_driver.IsStarted()) return false;
50-
51-
if (motor_driver.GetLatestState().status == MotorDriver::ESCState::ESCStatus::ESC_STATUS_DISCONNECTED) {
52-
motor_driver.RequestStatus();
53-
// Give ESC driver some time to respond so that callee don't need to go into retry loop
54-
chThdSleepMilliseconds(100);
55-
}
56-
57-
return motor_driver.GetLatestState().status == MotorDriver::ESCState::ESCStatus::ESC_STATUS_OK;
58-
}

0 commit comments

Comments
 (0)