Skip to content

Commit 8a28ff2

Browse files
committed
Fix ESC test functions
1 parent b4c0b4b commit 8a28ff2

File tree

6 files changed

+42
-20
lines changed

6 files changed

+42
-20
lines changed

robots/include/sabo_robot.hpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "robot.hpp"
88

99
using namespace xbot::driver::ui;
10+
using namespace xbot::driver::motor;
1011

1112
class SaboRobot : public MowerRobot {
1213
public:
@@ -40,10 +41,23 @@ class SaboRobot : public MowerRobot {
4041
return 7.0f * 3.0;
4142
}
4243

44+
// ----- Some driver Test* functions used by Boot-Screen -----
45+
4346
CHARGER_STATUS GetChargerStatus() {
4447
return charger_.getChargerStatus();
4548
}
4649

50+
bool TestESC(VescDriver& motor_driver);
51+
bool TestLeftESC() {
52+
return TestESC(left_motor_driver_);
53+
}
54+
bool TestRightESC() {
55+
return TestESC(right_motor_driver_);
56+
}
57+
bool TestMowerESC() {
58+
return TestESC(mower_motor_driver_);
59+
}
60+
4761
private:
4862
BQ2576 charger_{};
4963
SaboCoverUIController cover_ui_{};

robots/src/sabo_robot.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,15 @@ 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+
}

src/drivers/motor/motor_driver.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,15 @@ class MotorDriver {
5555
state_callback_ = function;
5656
}
5757

58-
protected:
5958
bool IsStarted() {
6059
return started_;
6160
}
6261

62+
ESCState GetLatestState() const {
63+
return latest_state_;
64+
}
65+
66+
protected:
6367
void NotifyCallback() {
6468
chDbgAssert(started_, "Notify can only be called after driver started.");
6569
if (state_callback_) {

src/drivers/ui/SaboCoverUI/sabo_cover_ui_controller.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <services.hpp>
99

1010
#include "chprintf.h"
11+
#include "globals.hpp"
1112
#include "hal.h"
1213
#include "robots/include/sabo_robot.hpp"
1314
#include "sabo_cover_ui_display.hpp"
@@ -220,18 +221,21 @@ bool SaboCoverUIController::TestGPS() {
220221
}
221222

222223
bool SaboCoverUIController::TestLeftESC() {
223-
auto esc_state = diff_drive.GetLeftESCState();
224-
return esc_state.status == MotorDriver::ESCState::ESCStatus::ESC_STATUS_OK;
224+
if (!robot) return false;
225+
auto* sabo = static_cast<SaboRobot*>(robot);
226+
return sabo->TestLeftESC();
225227
}
226228

227229
bool SaboCoverUIController::TestRightESC() {
228-
auto esc_state = diff_drive.GetRightESCState();
229-
return esc_state.status == MotorDriver::ESCState::ESCStatus::ESC_STATUS_OK;
230+
if (!robot) return false;
231+
auto* sabo = static_cast<SaboRobot*>(robot);
232+
return sabo->TestRightESC();
230233
}
231234

232235
bool SaboCoverUIController::TestMowerESC() {
233-
auto esc_state = mower_service.GetESCState();
234-
return esc_state.status == MotorDriver::ESCState::ESCStatus::ESC_STATUS_OK;
236+
if (!robot) return false;
237+
auto* sabo = static_cast<SaboRobot*>(robot);
238+
return sabo->TestMowerESC();
235239
}
236240

237241
void SaboCoverUIController::ThreadFunc() {

src/drivers/ui/SaboCoverUI/sabo_cover_ui_controller.hpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,14 @@ class SaboCoverUIController {
4444
BootStepState state = BootStepState::WAIT;
4545
systime_t last_action_time = 0;
4646
};
47-
static constexpr size_t BOOT_STEP_COUNT_ = 7;
47+
static constexpr size_t BOOT_STEP_COUNT_ = 6;
4848
etl::array<SaboCoverUIController::BootStep, BOOT_STEP_COUNT_> boot_steps_ = {{
4949
{"Motion Sensor", &TestIMU},
5050
{"Charger", &TestCharger},
5151
{"GPS", &TestGPS},
5252
{"Left Motor", &TestLeftESC},
5353
{"Right Motor", &TestRightESC},
5454
{"Mower Motor", &TestMowerESC},
55-
{"Flux Compensator", &TestFluxCompensator},
5655
}};
5756
size_t current_boot_step_ = 0;
5857
static constexpr size_t BOOT_STEP_RETRIES = 3;
@@ -66,9 +65,6 @@ class SaboCoverUIController {
6665
static bool TestLeftESC();
6766
static bool TestRightESC();
6867
static bool TestMowerESC();
69-
static bool TestFluxCompensator() {
70-
return false; // Placeholder for a non-existent service
71-
}
7268

7369
static void ThreadHelper(void* instance);
7470
void ThreadFunc();

src/services/diff_drive_service/diff_drive_service.hpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,6 @@ class DiffDriveService : public DiffDriveServiceBase {
4343

4444
void OnEmergencyChangedEvent();
4545

46-
MotorDriver::ESCState GetLeftESCState() const {
47-
return left_esc_state_;
48-
}
49-
50-
MotorDriver::ESCState GetRightESCState() const {
51-
return right_esc_state_;
52-
}
53-
5446
void SetDrivers(MotorDriver *left_driver, MotorDriver *right_driver);
5547

5648
protected:

0 commit comments

Comments
 (0)