Skip to content

Commit 5405e0d

Browse files
committed
individual running alerts for ESC
1 parent 891c8cf commit 5405e0d

File tree

4 files changed

+102
-37
lines changed

4 files changed

+102
-37
lines changed

inc/sp140/esc.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ bool hasCriticalRunningError(uint16_t errorCode);
3737
bool hasWarningRunningError(uint16_t errorCode);
3838
bool hasCriticalSelfCheckError(uint16_t errorCode);
3939

40+
// Individual error bit checkers
41+
bool hasOverCurrentError(uint16_t errorCode);
42+
bool hasLockedRotorError(uint16_t errorCode);
43+
bool hasOverTempError(uint16_t errorCode);
44+
bool hasOverVoltError(uint16_t errorCode);
45+
bool hasVoltagDropError(uint16_t errorCode);
46+
bool hasThrottleSatWarning(uint16_t errorCode);
47+
4048
// for debugging
4149
void dumpThrottleResponse(const sine_esc_SetThrottleSettings2Response *res);
4250
void dumpESCMessages(); // dumps all messages to USBSerial

inc/sp140/simple_monitor.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,15 @@ enum class SensorID {
1313
ESC_MCU_Temp,
1414
ESC_CAP_Temp,
1515
Motor_Temp,
16-
ESC_Running_Error,
17-
ESC_Running_Warning,
16+
// ESC Running Errors (Critical - High Priority)
17+
ESC_OverCurrent_Error, // Bit 0: over_current_protect
18+
ESC_LockedRotor_Error, // Bit 1: locked_rotor_protect
19+
ESC_OverTemp_Error, // Bit 2: over_temp_protect
20+
ESC_OverVolt_Error, // Bit 6: over_volt_protect
21+
ESC_VoltageDrop_Error, // Bit 7: voltage_drop
22+
// ESC Running Warnings (Middle Priority)
23+
ESC_ThrottleSat_Warning, // Bit 5: throttle_saturation
24+
// ESC Self-Check Errors (All Critical)
1825
ESC_SelfCheck_Error,
1926

2027
// BMS

src/sp140/esc.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,3 +498,28 @@ bool hasWarningRunningError(uint16_t errorCode) {
498498
bool hasCriticalSelfCheckError(uint16_t errorCode) {
499499
return errorCode != 0; // All self-check errors are critical
500500
}
501+
502+
// Individual error bit checkers for specific monitoring
503+
bool hasOverCurrentError(uint16_t errorCode) {
504+
return (errorCode & 0x0001) != 0; // Bit 0
505+
}
506+
507+
bool hasLockedRotorError(uint16_t errorCode) {
508+
return (errorCode & 0x0002) != 0; // Bit 1
509+
}
510+
511+
bool hasOverTempError(uint16_t errorCode) {
512+
return (errorCode & 0x0004) != 0; // Bit 2
513+
}
514+
515+
bool hasOverVoltError(uint16_t errorCode) {
516+
return (errorCode & 0x0040) != 0; // Bit 6
517+
}
518+
519+
bool hasVoltagDropError(uint16_t errorCode) {
520+
return (errorCode & 0x0080) != 0; // Bit 7
521+
}
522+
523+
bool hasThrottleSatWarning(uint16_t errorCode) {
524+
return (errorCode & 0x0020) != 0; // Bit 5
525+
}

src/sp140/simple_monitor.cpp

Lines changed: 60 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -34,26 +34,17 @@ void SerialLogger::log(SensorID id, AlertLevel lvl, float v) {
3434
void SerialLogger::log(SensorID id, AlertLevel lvl, bool v) {
3535
const char* levelNames[] = {"OK", "WARN_LOW", "WARN_HIGH", "CRIT_LOW", "CRIT_HIGH", "INFO"};
3636

37-
// Enhanced logging for ESC errors - show decoded error details
38-
if (id == SensorID::ESC_Running_Error) {
37+
// Enhanced logging for ESC errors - show decoded error details
38+
if (id == SensorID::ESC_OverCurrent_Error || id == SensorID::ESC_LockedRotor_Error ||
39+
id == SensorID::ESC_OverTemp_Error || id == SensorID::ESC_OverVolt_Error ||
40+
id == SensorID::ESC_VoltageDrop_Error || id == SensorID::ESC_ThrottleSat_Warning) {
3941
if (v) {
4042
USBSerial.printf("[%lu] [%s] %s = %s (0x%04X: %s)\n",
4143
millis(), levelNames[(int)lvl], sensorIDToString(id),
4244
v ? "ON" : "OFF", monitoringEscData.running_error,
4345
decodeRunningError(monitoringEscData.running_error).c_str());
4446
} else {
45-
USBSerial.printf("[%lu] [%s] %s = %s (critical errors cleared)\n",
46-
millis(), levelNames[(int)lvl], sensorIDToString(id),
47-
v ? "ON" : "OFF");
48-
}
49-
} else if (id == SensorID::ESC_Running_Warning) {
50-
if (v) {
51-
USBSerial.printf("[%lu] [%s] %s = %s (0x%04X: %s)\n",
52-
millis(), levelNames[(int)lvl], sensorIDToString(id),
53-
v ? "ON" : "OFF", monitoringEscData.running_error,
54-
decodeRunningError(monitoringEscData.running_error).c_str());
55-
} else {
56-
USBSerial.printf("[%lu] [%s] %s = %s (warnings cleared)\n",
47+
USBSerial.printf("[%lu] [%s] %s = %s (cleared)\n",
5748
millis(), levelNames[(int)lvl], sensorIDToString(id),
5849
v ? "ON" : "OFF");
5950
}
@@ -81,8 +72,15 @@ const char* sensorIDToString(SensorID id) {
8172
case SensorID::ESC_MCU_Temp: return "ESC_MCU_Temp";
8273
case SensorID::ESC_CAP_Temp: return "ESC_CAP_Temp";
8374
case SensorID::Motor_Temp: return "Motor_Temp";
84-
case SensorID::ESC_Running_Error: return "ESC_Run_Err";
85-
case SensorID::ESC_Running_Warning: return "ESC_Run_Warn";
75+
// ESC Running Errors (Critical)
76+
case SensorID::ESC_OverCurrent_Error: return "ESC_OverCurrent_Error";
77+
case SensorID::ESC_LockedRotor_Error: return "ESC_LockedRotor_Error";
78+
case SensorID::ESC_OverTemp_Error: return "ESC_OverTemp_Error";
79+
case SensorID::ESC_OverVolt_Error: return "ESC_OverVolt_Error";
80+
case SensorID::ESC_VoltageDrop_Error: return "ESC_VoltageDrop_Error";
81+
// ESC Running Warnings
82+
case SensorID::ESC_ThrottleSat_Warning: return "ESC_ThrottleSat_Warning";
83+
// ESC Self-Check Errors
8684
case SensorID::ESC_SelfCheck_Error: return "ESC_Boot_Err";
8785

8886
// BMS
@@ -118,8 +116,15 @@ const char* sensorIDToAbbreviation(SensorID id) {
118116
case SensorID::ESC_MCU_Temp: return "ESC-C"; // Controller temp
119117
case SensorID::ESC_CAP_Temp: return "ESC-P"; // Capacitor temp
120118
case SensorID::Motor_Temp: return "MTR-T"; // Motor temp
121-
case SensorID::ESC_Running_Error: return "ESC-RE"; // Running error
122-
case SensorID::ESC_Running_Warning: return "ESC-RW"; // Running warning
119+
// ESC Running Errors (Critical) - with bit numbers
120+
case SensorID::ESC_OverCurrent_Error: return "ESC-RE-0"; // Bit 0
121+
case SensorID::ESC_LockedRotor_Error: return "ESC-RE-1"; // Bit 1
122+
case SensorID::ESC_OverTemp_Error: return "ESC-RE-2"; // Bit 2
123+
case SensorID::ESC_OverVolt_Error: return "ESC-RE-6"; // Bit 6
124+
case SensorID::ESC_VoltageDrop_Error: return "ESC-RE-7"; // Bit 7
125+
// ESC Running Warnings - with bit numbers
126+
case SensorID::ESC_ThrottleSat_Warning: return "ESC-RW-5"; // Bit 5
127+
// ESC Self-Check Errors
123128
case SensorID::ESC_SelfCheck_Error: return "ESC-SE"; // Self-check error
124129

125130
// BMS (Battery Management System)
@@ -216,23 +221,43 @@ void addESCMonitors() {
216221
&multiLogger);
217222
monitors.push_back(motorTemp);
218223

219-
// ESC Running Error Monitor
220-
static BooleanMonitor* escRunningError = new BooleanMonitor(
221-
SensorID::ESC_Running_Error,
222-
[]() { return hasCriticalRunningError(monitoringEscData.running_error); },
223-
true, // Alert when true (when errors are present)
224-
AlertLevel::CRIT_HIGH,
225-
&multiLogger);
226-
monitors.push_back(escRunningError);
227-
228-
// ESC Running Warning Monitor (for throttle saturation, etc.)
229-
static BooleanMonitor* escRunningWarning = new BooleanMonitor(
230-
SensorID::ESC_Running_Warning,
231-
[]() { return hasWarningRunningError(monitoringEscData.running_error); },
232-
true, // Alert when true (when warnings are present)
233-
AlertLevel::WARN_HIGH,
234-
&multiLogger);
235-
monitors.push_back(escRunningWarning);
224+
// Individual ESC Running Error Monitors (Critical)
225+
static BooleanMonitor* escOverCurrentError = new BooleanMonitor(
226+
SensorID::ESC_OverCurrent_Error,
227+
[]() { return hasOverCurrentError(monitoringEscData.running_error); },
228+
true, AlertLevel::CRIT_HIGH, &multiLogger);
229+
monitors.push_back(escOverCurrentError);
230+
231+
static BooleanMonitor* escLockedRotorError = new BooleanMonitor(
232+
SensorID::ESC_LockedRotor_Error,
233+
[]() { return hasLockedRotorError(monitoringEscData.running_error); },
234+
true, AlertLevel::CRIT_HIGH, &multiLogger);
235+
monitors.push_back(escLockedRotorError);
236+
237+
static BooleanMonitor* escOverTempError = new BooleanMonitor(
238+
SensorID::ESC_OverTemp_Error,
239+
[]() { return hasOverTempError(monitoringEscData.running_error); },
240+
true, AlertLevel::CRIT_HIGH, &multiLogger);
241+
monitors.push_back(escOverTempError);
242+
243+
static BooleanMonitor* escOverVoltError = new BooleanMonitor(
244+
SensorID::ESC_OverVolt_Error,
245+
[]() { return hasOverVoltError(monitoringEscData.running_error); },
246+
true, AlertLevel::CRIT_HIGH, &multiLogger);
247+
monitors.push_back(escOverVoltError);
248+
249+
static BooleanMonitor* escVoltageDropError = new BooleanMonitor(
250+
SensorID::ESC_VoltageDrop_Error,
251+
[]() { return hasVoltagDropError(monitoringEscData.running_error); },
252+
true, AlertLevel::CRIT_HIGH, &multiLogger);
253+
monitors.push_back(escVoltageDropError);
254+
255+
// Individual ESC Running Warning Monitors
256+
static BooleanMonitor* escThrottleSatWarning = new BooleanMonitor(
257+
SensorID::ESC_ThrottleSat_Warning,
258+
[]() { return hasThrottleSatWarning(monitoringEscData.running_error); },
259+
true, AlertLevel::WARN_HIGH, &multiLogger);
260+
monitors.push_back(escThrottleSatWarning);
236261

237262
// ESC Self-Check Error Monitor
238263
static BooleanMonitor* escSelfCheckError = new BooleanMonitor(

0 commit comments

Comments
 (0)