Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions include/VCF_Constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion lib/systems/include/PedalsSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
3 changes: 2 additions & 1 deletion lib/systems/src/PedalsSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
66 changes: 34 additions & 32 deletions src/VCF_Tasks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ HT_TASK::TaskResponse run_read_adc0_task(const unsigned long& sysMicros, const H
.accel_2 = static_cast<uint32_t>(ADCInterfaceInstance::instance().acceleration_2().conversion),
.brake_1 = static_cast<uint32_t>(ADCInterfaceInstance::instance().brake_1().conversion),
.brake_2 = static_cast<uint32_t>(ADCInterfaceInstance::instance().brake_2().conversion),
.pedal_pressure = 0 // TODO: Need changes to support both brake pressure sensors
.brake_pressure_front = static_cast<uint32_t>(ADCInterfaceInstance::instance().brake_pressure_front().conversion),
.brake_pressure_rear = static_cast<uint32_t>(ADCInterfaceInstance::instance().brake_pressure_rear().conversion)
});
return HT_TASK::TaskResponse::YIELD;
}
Expand Down Expand Up @@ -69,14 +70,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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -535,33 +537,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
Expand Down