From 73c1e4e2fe0f6d1df0a639d63447b4d5b4534855 Mon Sep 17 00:00:00 2001 From: Alex Bailey Date: Sun, 8 Mar 2026 23:12:05 -0400 Subject: [PATCH 1/2] moved pedal system constants to VCFSystemConstants --- include/VCF_Constants.h | 13 ++++----- src/VCF_Tasks.cpp | 60 ++++++++++++++++++++--------------------- 2 files changed, 37 insertions(+), 36 deletions(-) diff --git a/include/VCF_Constants.h b/include/VCF_Constants.h index 86b903d..5938f04 100644 --- a/include/VCF_Constants.h +++ b/include/VCF_Constants.h @@ -101,6 +101,12 @@ namespace VCFInterfaceConstants { constexpr float BRAKE_PRESSURE_REAR_SCALE = 1.0; constexpr float BRAKE_PRESSURE_REAR_OFFSET = 0; +} + +// calibration and processing constants +namespace VCFSystemConstants { + constexpr float LBS_TO_NEWTONS = 4.4482216153; + // EEPROM addresses for min and max calibration values constexpr uint32_t ACCEL_1_MIN_ADDR = 0; constexpr uint32_t ACCEL_2_MIN_ADDR = 4; @@ -113,7 +119,7 @@ namespace VCFInterfaceConstants { constexpr uint32_t ACCEL_MAX_SENSOR_PEDAL_2 = 4000; constexpr float ACCEL_DEADZONE_MARGIN = 0.03f; constexpr float ACCEL_MECHANICAL_ACTIVATION_PERCENTAGE = 0.05f; - + constexpr uint32_t BRAKE_1_MIN_ADDR = 16; constexpr uint32_t BRAKE_2_MIN_ADDR = 20; constexpr uint32_t BRAKE_1_MAX_ADDR = 24; @@ -127,11 +133,6 @@ namespace VCFInterfaceConstants { constexpr float BRAKE_MECHANICAL_ACTIVATION_PERCENTAGE = 0.5f; } -// calibration and processing constants -namespace VCFSystemConstants { - constexpr float LBS_TO_NEWTONS = 4.4482216153; -} - // software configuration constants namespace VCFTaskConstants { const size_t SERIAL_BAUDRATE = 115200; diff --git a/src/VCF_Tasks.cpp b/src/VCF_Tasks.cpp index 15340a2..0e378d2 100644 --- a/src/VCF_Tasks.cpp +++ b/src/VCF_Tasks.cpp @@ -69,14 +69,14 @@ HT_TASK::TaskResponse update_pedals_calibration_task(const unsigned long& sysMic { // PedalsSystemInstance::instance().recalibrate_min_max(VCFData_sInstance::instance().interface_data.pedal_sensor_data); PedalsSystemInstance::instance().recalibrate_min_max(PedalsSystemInstance::instance().get_pedals_sensor_data()); - EEPROMUtilities::write_eeprom_32bit(VCFInterfaceConstants::ACCEL_1_MIN_ADDR, PedalsSystemInstance::instance().get_accel_params().min_pedal_1); - EEPROMUtilities::write_eeprom_32bit(VCFInterfaceConstants::ACCEL_1_MAX_ADDR, PedalsSystemInstance::instance().get_accel_params().max_pedal_1); - EEPROMUtilities::write_eeprom_32bit(VCFInterfaceConstants::ACCEL_2_MIN_ADDR, PedalsSystemInstance::instance().get_accel_params().min_pedal_2); - EEPROMUtilities::write_eeprom_32bit(VCFInterfaceConstants::ACCEL_2_MAX_ADDR, PedalsSystemInstance::instance().get_accel_params().max_pedal_2); - EEPROMUtilities::write_eeprom_32bit(VCFInterfaceConstants::BRAKE_1_MIN_ADDR, PedalsSystemInstance::instance().get_brake_params().min_pedal_1); - EEPROMUtilities::write_eeprom_32bit(VCFInterfaceConstants::BRAKE_1_MAX_ADDR, PedalsSystemInstance::instance().get_brake_params().max_pedal_1); - EEPROMUtilities::write_eeprom_32bit(VCFInterfaceConstants::BRAKE_2_MIN_ADDR, PedalsSystemInstance::instance().get_brake_params().min_pedal_2); - EEPROMUtilities::write_eeprom_32bit(VCFInterfaceConstants::BRAKE_2_MAX_ADDR, PedalsSystemInstance::instance().get_brake_params().max_pedal_2); + EEPROMUtilities::write_eeprom_32bit(VCFSystemConstants::ACCEL_1_MIN_ADDR, PedalsSystemInstance::instance().get_accel_params().min_pedal_1); + EEPROMUtilities::write_eeprom_32bit(VCFSystemConstants::ACCEL_1_MAX_ADDR, PedalsSystemInstance::instance().get_accel_params().max_pedal_1); + EEPROMUtilities::write_eeprom_32bit(VCFSystemConstants::ACCEL_2_MIN_ADDR, PedalsSystemInstance::instance().get_accel_params().min_pedal_2); + EEPROMUtilities::write_eeprom_32bit(VCFSystemConstants::ACCEL_2_MAX_ADDR, PedalsSystemInstance::instance().get_accel_params().max_pedal_2); + EEPROMUtilities::write_eeprom_32bit(VCFSystemConstants::BRAKE_1_MIN_ADDR, PedalsSystemInstance::instance().get_brake_params().min_pedal_1); + EEPROMUtilities::write_eeprom_32bit(VCFSystemConstants::BRAKE_1_MAX_ADDR, PedalsSystemInstance::instance().get_brake_params().max_pedal_1); + EEPROMUtilities::write_eeprom_32bit(VCFSystemConstants::BRAKE_2_MIN_ADDR, PedalsSystemInstance::instance().get_brake_params().min_pedal_2); + EEPROMUtilities::write_eeprom_32bit(VCFSystemConstants::BRAKE_2_MAX_ADDR, PedalsSystemInstance::instance().get_brake_params().max_pedal_2); } return HT_TASK::TaskResponse::YIELD; @@ -535,33 +535,33 @@ void setup_all_interfaces() { // Create pedals singleton PedalsParams accel_params = { - .min_pedal_1 = EEPROMUtilities::read_eeprom_32bit(VCFInterfaceConstants::ACCEL_1_MIN_ADDR), - .min_pedal_2 = EEPROMUtilities::read_eeprom_32bit(VCFInterfaceConstants::ACCEL_2_MIN_ADDR), - .max_pedal_1 = EEPROMUtilities::read_eeprom_32bit(VCFInterfaceConstants::ACCEL_1_MAX_ADDR), - .max_pedal_2 = EEPROMUtilities::read_eeprom_32bit(VCFInterfaceConstants::ACCEL_2_MAX_ADDR), - .activation_percentage = VCFInterfaceConstants::ACCEL_ACTIVATION_PERCENTAGE, - .min_sensor_pedal_1 = VCFInterfaceConstants::ACCEL_MIN_SENSOR_PEDAL_1, - .min_sensor_pedal_2 = VCFInterfaceConstants::ACCEL_MIN_SENSOR_PEDAL_2, - .max_sensor_pedal_1 = VCFInterfaceConstants::ACCEL_MAX_SENSOR_PEDAL_1, - .max_sensor_pedal_2 = VCFInterfaceConstants::ACCEL_MAX_SENSOR_PEDAL_2, - .deadzone_margin = VCFInterfaceConstants::ACCEL_DEADZONE_MARGIN, + .min_pedal_1 = EEPROMUtilities::read_eeprom_32bit(VCFSystemConstants::ACCEL_1_MIN_ADDR), + .min_pedal_2 = EEPROMUtilities::read_eeprom_32bit(VCFSystemConstants::ACCEL_2_MIN_ADDR), + .max_pedal_1 = EEPROMUtilities::read_eeprom_32bit(VCFSystemConstants::ACCEL_1_MAX_ADDR), + .max_pedal_2 = EEPROMUtilities::read_eeprom_32bit(VCFSystemConstants::ACCEL_2_MAX_ADDR), + .activation_percentage = VCFSystemConstants::ACCEL_ACTIVATION_PERCENTAGE, + .min_sensor_pedal_1 = VCFSystemConstants::ACCEL_MIN_SENSOR_PEDAL_1, + .min_sensor_pedal_2 = VCFSystemConstants::ACCEL_MIN_SENSOR_PEDAL_2, + .max_sensor_pedal_1 = VCFSystemConstants::ACCEL_MAX_SENSOR_PEDAL_1, + .max_sensor_pedal_2 = VCFSystemConstants::ACCEL_MAX_SENSOR_PEDAL_2, + .deadzone_margin = VCFSystemConstants::ACCEL_DEADZONE_MARGIN, .implausibility_margin = IMPLAUSIBILITY_PERCENT, - .mechanical_activation_percentage = VCFInterfaceConstants::ACCEL_MECHANICAL_ACTIVATION_PERCENTAGE + .mechanical_activation_percentage = VCFSystemConstants::ACCEL_MECHANICAL_ACTIVATION_PERCENTAGE }; PedalsParams brake_params = { - .min_pedal_1 = EEPROMUtilities::read_eeprom_32bit(VCFInterfaceConstants::BRAKE_1_MIN_ADDR), - .min_pedal_2 = EEPROMUtilities::read_eeprom_32bit(VCFInterfaceConstants::BRAKE_2_MIN_ADDR), - .max_pedal_1 = EEPROMUtilities::read_eeprom_32bit(VCFInterfaceConstants::BRAKE_1_MAX_ADDR), - .max_pedal_2 = EEPROMUtilities::read_eeprom_32bit(VCFInterfaceConstants::BRAKE_2_MAX_ADDR), - .activation_percentage = VCFInterfaceConstants::BRAKE_ACTIVATION_PERCENTAGE, - .min_sensor_pedal_1 = VCFInterfaceConstants::BRAKE_MIN_SENSOR_PEDAL_1, - .min_sensor_pedal_2 = VCFInterfaceConstants::BRAKE_MIN_SENSOR_PEDAL_2, - .max_sensor_pedal_1 = VCFInterfaceConstants::BRAKE_MAX_SENSOR_PEDAL_1, - .max_sensor_pedal_2 = VCFInterfaceConstants::BRAKE_MAX_SENSOR_PEDAL_2, - .deadzone_margin = VCFInterfaceConstants::BRAKE_DEADZONE_MARGIN, + .min_pedal_1 = EEPROMUtilities::read_eeprom_32bit(VCFSystemConstants::BRAKE_1_MIN_ADDR), + .min_pedal_2 = EEPROMUtilities::read_eeprom_32bit(VCFSystemConstants::BRAKE_2_MIN_ADDR), + .max_pedal_1 = EEPROMUtilities::read_eeprom_32bit(VCFSystemConstants::BRAKE_1_MAX_ADDR), + .max_pedal_2 = EEPROMUtilities::read_eeprom_32bit(VCFSystemConstants::BRAKE_2_MAX_ADDR), + .activation_percentage = VCFSystemConstants::BRAKE_ACTIVATION_PERCENTAGE, + .min_sensor_pedal_1 = VCFSystemConstants::BRAKE_MIN_SENSOR_PEDAL_1, + .min_sensor_pedal_2 = VCFSystemConstants::BRAKE_MIN_SENSOR_PEDAL_2, + .max_sensor_pedal_1 = VCFSystemConstants::BRAKE_MAX_SENSOR_PEDAL_1, + .max_sensor_pedal_2 = VCFSystemConstants::BRAKE_MAX_SENSOR_PEDAL_2, + .deadzone_margin = VCFSystemConstants::BRAKE_DEADZONE_MARGIN, .implausibility_margin = IMPLAUSIBILITY_PERCENT, - .mechanical_activation_percentage = VCFInterfaceConstants::BRAKE_MECHANICAL_ACTIVATION_PERCENTAGE + .mechanical_activation_percentage = VCFSystemConstants::BRAKE_MECHANICAL_ACTIVATION_PERCENTAGE }; PedalsSystemInstance::create(accel_params, brake_params); //pass in the two different params From da864164cb49664d51d0c2bb667cb54fbaa7f0dd Mon Sep 17 00:00:00 2001 From: Alex Bailey Date: Mon, 9 Mar 2026 00:03:41 -0400 Subject: [PATCH 2/2] added support for both brake pressure sensors --- lib/systems/include/PedalsSystem.h | 3 ++- lib/systems/src/PedalsSystem.cpp | 3 ++- src/VCF_Tasks.cpp | 6 ++++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/systems/include/PedalsSystem.h b/lib/systems/include/PedalsSystem.h index 6dfddcb..b09999a 100644 --- a/lib/systems/include/PedalsSystem.h +++ b/lib/systems/include/PedalsSystem.h @@ -65,7 +65,8 @@ class PedalsSystem _sensorData.accel_2 = pedal_data.accel_2; _sensorData.brake_1 = pedal_data.brake_1; _sensorData.brake_2 = pedal_data.brake_2; - _sensorData.pedal_pressure = pedal_data.pedal_pressure; //TODO: change this to use brake pressure front and rear + _sensorData.brake_pressure_front = pedal_data.brake_pressure_front; + _sensorData.brake_pressure_rear = pedal_data.brake_pressure_rear; } const PedalsSystemData_s &get_pedals_system_data() diff --git a/lib/systems/src/PedalsSystem.cpp b/lib/systems/src/PedalsSystem.cpp index 6e0ac04..85979d2 100644 --- a/lib/systems/src/PedalsSystem.cpp +++ b/lib/systems/src/PedalsSystem.cpp @@ -55,9 +55,10 @@ void PedalsSystem::evaluate_pedals(PedalSensorData_s pedals_data, unsigned long bool accel_pressed = accel_percent > _accelParams.activation_percentage; bool brake_pressed = brake_percent > _brakeParams.activation_percentage; + bool mech_brake_pressed = brake_percent >= _brakeParams.mechanical_activation_percentage; _systemData.accel_is_pressed = accel_pressed; _systemData.brake_is_pressed = brake_pressed; - bool mech_brake_pressed = brake_percent >= _brakeParams.mechanical_activation_percentage; + _systemData.mech_brake_is_active = mech_brake_pressed; _systemData.brake_and_accel_pressed_implausibility_high = accel_pressed && _systemData.brake_is_pressed; diff --git a/src/VCF_Tasks.cpp b/src/VCF_Tasks.cpp index 0e378d2..2b4e088 100644 --- a/src/VCF_Tasks.cpp +++ b/src/VCF_Tasks.cpp @@ -32,7 +32,8 @@ HT_TASK::TaskResponse run_read_adc0_task(const unsigned long& sysMicros, const H .accel_2 = static_cast(ADCInterfaceInstance::instance().acceleration_2().conversion), .brake_1 = static_cast(ADCInterfaceInstance::instance().brake_1().conversion), .brake_2 = static_cast(ADCInterfaceInstance::instance().brake_2().conversion), - .pedal_pressure = 0 // TODO: Need changes to support both brake pressure sensors + .brake_pressure_front = static_cast(ADCInterfaceInstance::instance().brake_pressure_front().conversion), + .brake_pressure_rear = static_cast(ADCInterfaceInstance::instance().brake_pressure_rear().conversion) }); return HT_TASK::TaskResponse::YIELD; } @@ -239,12 +240,13 @@ HT_TASK::TaskResponse enqueue_pedals_data(const unsigned long &sys_micros, const pedals_data.brake_pedal_active = PedalsSystemInstance::instance().get_pedals_system_data().brake_is_pressed; pedals_data.mechanical_brake_active = PedalsSystemInstance::instance().get_pedals_system_data().mech_brake_is_active; pedals_data.implaus_exceeded_max_duration = PedalsSystemInstance::instance().get_pedals_system_data().implausibility_has_exceeded_max_duration; - pedals_data.accel_pedal_ro = HYTECH_accel_pedal_ro_toS(PedalsSystemInstance::instance().get_pedals_system_data().accel_percent); pedals_data.brake_pedal_ro = HYTECH_brake_pedal_ro_toS(PedalsSystemInstance::instance().get_pedals_system_data().brake_percent); // Serial.println(pedals_data.brake_pedal_ro); // Serial.println(pedals_data.accel_pedal_ro); + + // TODO: Need to add brake pressure data to CAN msg CAN_util::enqueue_msg(&pedals_data, &Pack_PEDALS_SYSTEM_DATA_hytech, VCFCANInterfaceImpl::VCFCANInterfaceObjectsInstance::instance().main_can_tx_buffer); return HT_TASK::TaskResponse::YIELD; }