Skip to content

Commit

Permalink
Rsm final touch ups (#1258)
Browse files Browse the repository at this point in the history
### Changelist 
- heartbeat monitor tests (VC with FSM checked in & FSM with VC checked
in)
- sensor transfer functions (load cell and coolant pressure)
  • Loading branch information
shayana18 authored Jun 2, 2024
1 parent 97add01 commit 1dce97a
Show file tree
Hide file tree
Showing 12 changed files with 305 additions and 206 deletions.
16 changes: 9 additions & 7 deletions can_bus/quadruna/RSM/RSM_alerts.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,15 @@
"id": 452,
"description": "VC Missing Heart beat"
},
"MissingBMSHeartbeat": {
"id": 452,
"description": "BMS Missing Heart beat"
},
"MissingFSMHeartbeat": {
"id": 453,
"description": "FSM Missing Heartbeat"
}
"id" :453,
"description" : "FSM Missing Heart beat"
},
"MissingBMSHeartbeat": {
"id" :454,
"description" : "BMS Missing Heart beat"


}
}
}
263 changes: 137 additions & 126 deletions can_bus/quadruna/RSM/RSM_tx.json
Original file line number Diff line number Diff line change
@@ -1,128 +1,139 @@
{
"AlertsContext": {
"msg_id": 414,
"cycle_time": 1000,
"signals": {
"WatchdogTimeoutTaskName": {
"enum": "RtosTaskName"
},
"TxOverflowCount": {
"bits": 8
},
"RxOverflowCount": {
"bits": 8
}
}
},
"Vitals": {
"msg_id": 415,
"cycle_time": 100,
"description": "RSM vitals message.",
"signals": {
"Heartbeat": {
"bits": 1
},
"State": {
"enum": "RsmStates"
}
}
},
"Coolant": {
"msg_id": 416,
"cycle_time": 100,
"signals": {
"CoolantFlowRate": {
"resolution": 0.1,
"min": 0,
"max": 100,
"unit": "L/min"
},
"CoolantTemperatureA": {
"resolution": 0.1,
"min": 0,
"max": 100,
"unit": "°C"
},
"CoolantTemperatureB": {
"resolution": 0.1,
"min": 0,
"max": 100,
"unit": "°C"
},
"CoolantPressureA": {
"resolution": 0.1,
"min": 0,
"max": 100,
"unit": "psi"
},
"CoolantPressureB": {
"resolution": 0.1,
"min": 0,
"max": 100,
"unit": "psi"
}
}
},
"Suspension": {
"msg_id": 417,
"cycle_time": 100,
"description": "Suspension travel.",
"signals": {
"RearLeftSuspensionTravel": {
"resolution": 0.1,
"min": 0,
"max": 1000,
"unit": "cm"
},
"RearRightSuspensionTravel": {
"resolution": 0.1,
"min": 0,
"max": 1000,
"unit": "cm"
}
}
},
"LoadCell": {
"msg_id": 418,
"cycle_time": 100,
"description": "Mechanical load on load cell",
"signals": {
"LoadCell3": {
"resolution": 0.1,
"min": 0,
"max": 1000
},
"LoadCell4": {
"resolution": 0.1,
"min": 0,
"max": 1000
}
}
},
"CommitInfo": {
"msg_id": 419,
"cycle_time": 100,
"description": "RSM Current Running Git Commit Info",
"signals": {
"Hash": {
"bits": 32
},
"Clean": {
"bits": 1
}
}
},
"Fans": {
"msg_id": 420,
"cycle_time": 100,
"description": "Fan Status",
"signals": {
"AccumulatorFan": {
"bits": 1
},
"RadiatorFan": {
"bits": 1
}
}
}
"AlertsContext": {
"msg_id": 414,
"cycle_time": 1000,
"signals": {
"WatchdogTimeoutTaskName": {
"enum": "RtosTaskName"
},
"TxOverflowCount": {
"bits": 8
},
"RxOverflowCount": {
"bits": 8
}
}
},
"Vitals": {
"msg_id": 415,
"cycle_time": 100,
"description": "RSM vitals message.",
"signals": {
"Heartbeat": {
"bits": 1
},
"State": {
"enum": "RsmStates"
}
}
},
"Coolant": {
"msg_id": 416,
"cycle_time": 1000,
"signals": {
"CoolantFlowRate": {
"resolution": 0.1,
"min": 0,
"max": 100,
"unit": "L/min"
},
"CoolantTemperatureA": {
"resolution": 0.1,
"min": 0,
"max": 100,
"unit": "°C"
},
"CoolantTemperatureB": {
"resolution": 0.1,
"min": 0,
"max": 100,
"unit": "°C"
},
"CoolantPressureA": {
"resolution": 0.1,
"min": 0,
"max": 100,
"unit": "psi"
},
"CoolantPressureB": {
"resolution": 0.1,
"min": 0,
"max": 100,
"unit": "psi"
}
}
},
"Suspension": {
"msg_id": 417,
"cycle_time": 100,
"description": "Suspension travel.",
"signals": {
"RearLeftSuspensionTravel": {
"resolution": 0.1,
"min": 0,
"max": 1000,
"unit": "cm"
},
"RearRightSuspensionTravel": {
"resolution": 0.1,
"min": 0,
"max": 1000,
"unit": "cm"
}
}
},
"LoadCell":{
"msg_id" : 418,
"cycle_time": 100,
"description" : "Mechanical load on load cell",
"signals" : {
"LoadCell3" : {
"resolution": 0.1,
"min" : 0,
"max" : 1000
},
"LoadCell4" : {
"resolution": 0.1,
"min" : 0,
"max" : 1000
}
}
},
"CommitInfo": {
"msg_id": 419,
"cycle_time": 100,
"description": "RSM Current Running Git Commit Info",
"signals": {
"Hash": {
"bits": 32
},
"Clean": {
"bits": 1
}
}
},
"BrakeLight":{
"msg_id": 420,
"cycle_time": 100,
"description": "BrakeLight",
"signals":{
"BrakeLight":{
"bits": 1
}
}
},
"Fans":{
"msg_id": 421,
"cycle_time":100,
"description": "Accumulator and Radiator fan",
"signals":{
"AccumulatorFan":{
"bits": 1
},
"RadiatorFan":{
"bits": 1
}

}
}
}
4 changes: 4 additions & 0 deletions firmware/quadruna/RSM/src/io/io_brake_light.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "io_brake_light.h"
#include "app_canTx.h"

static const BinaryLed *brake_light = NULL;

Expand All @@ -7,7 +8,10 @@ void io_brake_light_init(const BinaryLed *brake_light_in)
brake_light = brake_light_in;
}

// tests on the can signal sending 1 when true and 0 when false were failing (can signal always set to 0) thus
// explicitly sending the desired input
void io_brake_light_set(bool val)
{
io_led_enable(brake_light, val);
app_canTx_RSM_BrakeLight_set(val);
}
54 changes: 35 additions & 19 deletions firmware/quadruna/RSM/src/io/io_coolant.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,25 @@
// source: https://www.adafruit.com/product/828#:~:text=7.5%20*%20Flow%20rate%20(L/min)
#define FLOW_RATE_CONVERSION_FACTOR (7.5f)

// from the schematic we see that the voltage value coming is passes through a voltage dividor before it is read at the
// ADC PIN.
#define PRESSURE_VOLTAGE_DIVIDOR (PRESSURE_BOT_RESISTOR / (PRESSURE_BOT_RESISTOR + PRESSURE_TOP_RESISTOR))
#define PRESSURE_VOLTAGE_MIN (0.5f * PRESSURE_VOLTAGE_DIVIDOR)
#define PRESSURE_VOLTAGE_MAX (4.5f * PRESSURE_VOLTAGE_DIVIDOR)
#define PRESSURE_PSI_MAX (100.0f)
// min pressure is 0 PSI
#define VOLTAGE_PRESSURE_CONVERSION(voltage) \
(((voltage)-PRESSURE_VOLTAGE_MIN) * (PRESSURE_PSI_MAX / (PRESSURE_VOLTAGE_MAX - PRESSURE_VOLTAGE_MIN)))

// source: https://www.tdk-electronics.tdk.com/inf/50/db/ntc/NTC_Probe_ass_K301_A003.pdf
#define TEMPERATURE_VOLTAGE_MIN (0.0f)
#define TEMPERATURE_VOLTAGE_MAX (4.0f)
#define PRESSURE_TOP_RESISTOR (28.0f)
#define PRESSURE_BOT_RESISTOR (56.0f)

#define T0 (298.15f) // 25 degrees celsius is used for T0 in datasheet but for equation we do kelvin
#define R0 (10000.f) // resistance at T0
#define B_COEFFICIENT (3988.f) // source: https://www.tdk-electronics.tdk.com/inf/50/db/ntc/NTC_Probe_ass_K301_A003.pdf
#define B_COEFFIECENT (3988.f) // source: https://www.tdk-electronics.tdk.com/inf/50/db/ntc/NTC_Probe_ass_K301_A003.pdf
#define VIN (5.0f)
#define R2 (2200.f) // bottom resistor in the coolant temp sensor circuit
// the coolant temp sensor circuit is made of a voltage divider where the thermistor which we use for the temperature
Expand All @@ -25,16 +38,7 @@
// * R2)/ Vout ) - R2)
#define RTHERM(voltage_out) (VIN * R2 / voltage_out - R2)
// below are constants for Steinhart Hart EQN used to model temprature as a function of a resistor for a thermistor
#define BTERM_STEIN_EQN(rtherm) ((float)log((double)(rtherm / R0)) / B_COEFFICIENT)

// source:
// https://m.media-amazon.com/images/S/aplus-media-library-service-media/413eb684-16a6-4eca-8ea6-b5e5bb1c657e.__CR0,0,970,600_PT0_SX970_V1___.jpg
// NOTE: this assumes a linear relationship between voltage and temperature
#define PRESSURE_VOLTAGE_MIN (0.5f)
#define PRESSURE_VOLTAGE_MAX (4.5f)
#define MIN_PRESSURE_PSI (0.0f)
#define MAX_PRESSURE_PSI (200.0f)
#define PSI_PER_VOLT ((MAX_PRESSURE_PSI - MIN_PRESSURE_PSI) / (PRESSURE_VOLTAGE_MAX - PRESSURE_VOLTAGE_MIN))
#define BTERM_STEIN_EQN(rtherm) ((float)log((float)(rtherm / R0)) / B_COEFFIECENT)

static PwmInputFreqOnly flow_meter;

Expand Down Expand Up @@ -103,16 +107,28 @@ bool pressure_ocsc(float v)

float io_coolant_getPressureA(void)
{
const float v_read = hw_adc_getVoltage(ADC1_IN12_COOLANT_PRESSURE_1);
app_canTx_RSM_Warning_CoolantPressureAOCSC_set(pressure_ocsc(v_read));
const float press_a = (v_read - PRESSURE_VOLTAGE_MIN) * PSI_PER_VOLT + MIN_PRESSURE_PSI;
return press_a;
const float water_pressure_A = VOLTAGE_PRESSURE_CONVERSION(ADC1_IN12_COOLANT_PRESSURE_1);
app_canTx_RSM_Warning_CoolantPressureAOCSC_set(io_coolant_PressureAOCSC());

return CLAMP(water_pressure_A, 0.0f, PRESSURE_PSI_MAX);
}

bool io_coolant_PressureAOCSC(void)
{
return (
PRESSURE_VOLTAGE_MIN > (ADC1_IN12_COOLANT_PRESSURE_1) || PRESSURE_VOLTAGE_MAX < (ADC1_IN12_COOLANT_PRESSURE_1));
}

float io_coolant_getPressureB(void)
{
const float v_read = hw_adc_getVoltage(ADC1_IN11_COOLANT_PRESSURE_2);
app_canTx_RSM_Warning_CoolantPressureBOCSC_set(pressure_ocsc(v_read));
const float press_b = (v_read - PRESSURE_VOLTAGE_MIN) * PSI_PER_VOLT + MIN_PRESSURE_PSI;
return press_b;
const float water_pressure_B = VOLTAGE_PRESSURE_CONVERSION(ADC1_IN11_COOLANT_PRESSURE_2);
app_canTx_RSM_Warning_CoolantPressureBOCSC_set(io_coolant_PressureBOCSC());

return CLAMP(water_pressure_B, 0.0f, PRESSURE_PSI_MAX);
}

bool io_coolant_PressureBOCSC(void)
{
return (
PRESSURE_VOLTAGE_MIN > (ADC1_IN11_COOLANT_PRESSURE_2) || PRESSURE_VOLTAGE_MAX < (ADC1_IN12_COOLANT_PRESSURE_1));
}
Loading

0 comments on commit 1dce97a

Please sign in to comment.