Skip to content

Commit 0b30b21

Browse files
committed
safer motor enable/disable logic
1 parent d415716 commit 0b30b21

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

ETC/src/can_wrapper.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@ void CANWrapper::processCANRx() {
132132
ETCState state = this->etc.getState();
133133
state.ts_ready = rx.data[0] & 0x08;
134134
this->etc.updateStateFromCAN(state);
135+
if (!this->etc.getState().ts_ready) {
136+
this->etc.turnOffMotor();
137+
}
135138
break;
136139
}
137140
}

ETC/src/etc_controller.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ void ETCController::checkStartConditions() {
121121
// If the brake is pressed past the tolerance threshold and the tractive system is ready
122122
// then the motor can be enabled. The last condition for motor start is the cockpit switch
123123
// being set to the ON position, which is what calls this method.
124-
if(this->state.ts_ready && this->state.brakes_read >= ETCController::BRAKE_TOLERANCE) {
124+
if(this->state.ts_ready && this->state.brakes_read >= ETCController::BRAKE_TOLERANCE && this->state.pedal_travel <= 0.01) {
125125
this->state.motor_enabled = true;
126126
this->runRTDS();
127127
}
@@ -130,7 +130,7 @@ void ETCController::checkStartConditions() {
130130

131131
void ETCController::runRTDS() {
132132
this->rtdsOutput.write(true);
133-
this->rtdsTicker.attach(callback([this] {this->stopRTDS();}), 1s);
133+
this->rtdsTicker.attach(callback([this] {this->stopRTDS();}), 1000ms);
134134
}
135135

136136

0 commit comments

Comments
 (0)