Skip to content

Commit d89d232

Browse files
committed
adjusted changes to reflect current state of VCF
1 parent 9cc8ef7 commit d89d232

16 files changed

Lines changed: 150 additions & 230 deletions

include/VCF_Constants.h

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,10 @@ namespace VCFInterfaceConstants {
9191
constexpr float FR_LOADCELL_SCALE = 1.0; //Values
9292
constexpr float FR_LOADCELL_OFFSET = 0.0;
9393

94-
constexpr float FR_SUS_POT_SCALE = 1.0;
95-
constexpr float FR_SUS_POT_OFFSET = 0;
96-
constexpr float FL_SUS_POT_SCALE = 1.0;
97-
constexpr float FL_SUS_POT_OFFSET = 0;
94+
constexpr float FR_SUS_POT_SCALE = 0.01396; // Calibrated for mm between mounting bolts
95+
constexpr float FR_SUS_POT_OFFSET = 150.0;
96+
constexpr float FL_SUS_POT_SCALE = 0.01396; // Same as FR
97+
constexpr float FL_SUS_POT_OFFSET = 150.0;
9898

9999
constexpr float BRAKE_PRESSURE_FRONT_SCALE = 1.0;
100100
constexpr float BRAKE_PRESSURE_FRONT_OFFSET = 0;
@@ -136,7 +136,7 @@ namespace VCFSystemConstants {
136136
constexpr float BRAKE_MECHANICAL_ACTIVATION_PERCENTAGE = 0.5f;
137137

138138
// Steering System Constants
139-
constexpr uint32_t MIN_STEERING_SIGNAL_ANALOG_ADDR = 56; //Raw ADC value from analog sensor at minimum (left) steering angle (calibration) TODO: test and find real values for min&max
139+
constexpr uint32_t MIN_STEERING_SIGNAL_ANALOG_ADDR = 56; //Raw ADC value from analog sensor at minimum (left) steering angle (calibration)
140140
constexpr uint32_t MAX_STEERING_SIGNAL_ANALOG_ADDR = 60; //Raw ADC value from analog sensor at maximum (right) steering angle
141141
constexpr uint32_t MIN_STEERING_SIGNAL_DIGITAL_ADDR = 32; //Raw ADC value from digital sensor at minimum (left) steering angle
142142
constexpr uint32_t MAX_STEERING_SIGNAL_DIGITAL_ADDR = 36; //Raw ADC value from digital sensor at maximum (right) steering angle
@@ -171,43 +171,45 @@ namespace VCFTaskConstants {
171171
constexpr unsigned long CAN_SEND_PRIORITY = 10;
172172
constexpr unsigned long CAN_SEND_PERIOD = 2000; // 2 000 us = 500 Hz
173173

174-
constexpr unsigned long PEDALS_PRIORITY = 5;
175-
constexpr unsigned long PEDALS_SEND_PERIOD = 4000; // 4 000 us = 250 Hz
176-
constexpr unsigned long PEDALS_SAMPLE_PERIOD = 500; // 500 us = 2 kHz
177-
174+
178175
constexpr unsigned long BUZZER_PRIORITY = 20;
179176
constexpr unsigned long BUZZER_WRITE_PERIOD = 100000; // 100 000 us = 10 Hz
180-
177+
181178
constexpr unsigned long DASH_SAMPLE_PRIORITY = 21;
182179
constexpr unsigned long DASH_SAMPLE_PERIOD = 100000; // 100 000 us = 10 Hz
183-
180+
184181
constexpr unsigned long DASH_SEND_PRIORITY = 7;
185182
constexpr unsigned long DASH_SEND_PERIOD = 100000; // 100 000 us = 10 Hz
186-
183+
187184
constexpr unsigned long DEBUG_PRIORITY = 100;
188185
constexpr unsigned long DEBUG_PERIOD = 10000; // 10 000 us = 2 Hz
189-
186+
190187
constexpr unsigned long NEOPIXEL_UPDATE_PRIORITY = 90;
191188
constexpr unsigned long NEOPIXEL_UPDATE_PERIOD = 100000; // 100 000 us = 10 Hz
192-
193-
constexpr unsigned long STEERING_SEND_PRIORITY = 25;
194-
constexpr unsigned long STEERING_SEND_PERIOD = 4000; // 4 000 us = 250 Hz
195-
196-
constexpr unsigned long STEERING_SAMPLE_PERIOD = 1000; // 2000 us = 500 Hz
197-
constexpr unsigned long STEERING_SAMPLE_PRIORITY = 10;
198-
189+
190+
199191
constexpr unsigned long LOADCELL_SAMPLE_PRIORITY = 24;
200192
constexpr unsigned long LOADCELL_SAMPLE_PERIOD = 250; // 250 us = 4 kHz
201193
constexpr unsigned long LOADCELL_SEND_PRIORITY = 25;
202194
constexpr unsigned long LOADCELL_SEND_PERIOD = 4000; // 4 000 us = 250 Hz
203-
195+
204196
constexpr unsigned long ETHERNET_SEND_PRIORITY = 20;
205197
constexpr unsigned long ETHERNET_SEND_PERIOD = 100000; // 100 000 us = 10Hz
206-
198+
199+
constexpr unsigned long PEDALS_PRIORITY = 5;
200+
constexpr unsigned long PEDALS_SEND_PERIOD = 4000; // 4 000 us = 250 Hz
201+
constexpr unsigned long PEDALS_SAMPLE_PERIOD = 500; // 500 us = 2 kHz
202+
207203
constexpr unsigned long PEDALS_RECALIBRATION_PRIORITY = 150;
208204
constexpr unsigned long PEDALS_RECALIBRATION_PERIOD = 100000; // 100 000 us = 10 Hz
205+
206+
constexpr unsigned long STEERING_SEND_PRIORITY = 25;
207+
constexpr unsigned long STEERING_SEND_PERIOD = 4000; // 4 000 us = 250 Hz
208+
209+
constexpr unsigned long STEERING_SAMPLE_PERIOD = 1000; // 2000 us = 500 Hz
210+
constexpr unsigned long STEERING_SAMPLE_PRIORITY = 10;
209211

210-
constexpr unsigned long STEERING_RECALIBRATION_PRIORITY = 150; // TODO: Determine real values for these
212+
constexpr unsigned long STEERING_RECALIBRATION_PRIORITY = 150;
211213
constexpr unsigned long STEERING_RECALIBRATION_PERIOD = 100000;
212214

213215
// IIR filter alphas

include/VCF_Tasks.h

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,6 @@ HT_TASK::TaskResponse run_read_adc0_task(const unsigned long& sysMicros, const H
5757
*/
5858
HT_TASK::TaskResponse run_read_adc1_task(const unsigned long& sysMicros, const HT_TASK::TaskInfo& taskInfo);
5959

60-
/**
61-
* This task will command the OrbisBRInterface to sample and store data from the digital steering sensor
62-
*/
63-
HT_TASK::TaskResponse run_read_digital_steering_task(const unsigned long& sysMicros, const HT_TASK::TaskInfo& taskInfo);
64-
6560
HT_TASK::TaskResponse init_kick_watchdog(const unsigned long& sysMicros, const HT_TASK::TaskInfo& taskInfo);
6661
HT_TASK::TaskResponse run_kick_watchdog(const unsigned long& sysMicros, const HT_TASK::TaskInfo& taskInfo);
6762

@@ -85,20 +80,9 @@ HT_TASK::TaskResponse run_buzzer_control_task(const unsigned long& sysMicros, co
8580
HT_TASK::TaskResponse init_handle_send_vcf_ethernet_data(const unsigned long& sysMicros, const HT_TASK::TaskInfo& taskInfo);
8681
HT_TASK::TaskResponse run_handle_send_vcf_ethernet_data(const unsigned long& sysMicros, const HT_TASK::TaskInfo& taskInfo);
8782

88-
/**
89-
* The handle_receive_VCR_ethernet_data task will receive a protobuf message
90-
* from VCR. This function relies on the VCF (receiving) socket and vcf_data
91-
* defined in VCFGlobals.h, and Ethernet constants defined in
92-
* EthernetAddressDefs.h.
93-
*
94-
*/
95-
HT_TASK::TaskResponse init_handle_receive_vcr_ethernet_data(const unsigned long& sysMicros, const HT_TASK::TaskInfo& taskInfo);
96-
HT_TASK::TaskResponse run_handle_receive_vcr_ethernet_data(const unsigned long& sysMicros, const HT_TASK::TaskInfo& taskInfo);
97-
9883
// this task attempts to send any data that is enqueued at 250hz. this will be the max rate that you can send over the CAN bus.
9984
// you dont have to enqeue at this rate, but this allows us to have 2 layers of rate limiting on CAN sending
10085
HT_TASK::TaskResponse handle_CAN_send(const unsigned long &sysMicros, const HT_TASK::TaskInfo &taskInfo); // NOLINT (capitalization of CAN)
101-
HT_TASK::TaskResponse handle_CAN_receive(const unsigned long& sysMicros, const HT_TASK::TaskInfo& taskInfo); // NOLINT (capitalization of CAN)
10286

10387
HT_TASK::TaskResponse run_dash_GPIOs_task(const unsigned long& sys_micros, const HT_TASK::TaskInfo& task_info); // NOLINT (capitalization of GPIOs)
10488
HT_TASK::TaskResponse send_dash_data(const unsigned long &sysMicros, const HT_TASK::TaskInfo &taskInfo);

lib/interfaces/include/DashboardInterface.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
struct DashboardGPIOs_s {
1616

1717
// GPIO
18-
uint8_t BTN_DIM_READ;
1918
uint8_t BRIGHTNESS_CONTROL_PIN;
2019
uint8_t PRESET_BUTTON;
2120
uint8_t MC_CYCLE_BUTTON;
@@ -31,7 +30,6 @@ class DashboardInterface
3130

3231
DashboardInterface(DashboardGPIOs_s gpios) : _dashboard_gpios(gpios)
3332
{
34-
pinMode(_dashboard_gpios.BTN_DIM_READ, INPUT_PULLUP); //TODO: verify pullup
3533
pinMode(_dashboard_gpios.START_BUTTON, INPUT_PULLUP);
3634
pinMode(_dashboard_gpios.PRESET_BUTTON, INPUT_PULLUP);
3735
pinMode(_dashboard_gpios.MC_CYCLE_BUTTON, INPUT_PULLUP);

lib/interfaces/include/NeopixelController.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ class NeopixelController
8383
Adafruit_NeoPixel _neopixels;
8484
uint8_t _current_brightness;
8585
uint8_t _neopixel_count;
86-
86+
const uint8_t _hv_threshold_voltage = 60;
87+
MinCellMonitoringThresholds_s _min_cell_thresholds;
8788
};
8889

8990
using NeopixelControllerInstance = etl::singleton<NeopixelController>;

lib/interfaces/include/SteeringEncoderInterface.h

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,6 @@
22
#define STEERING_ENCODER_INTERFACE_H
33
#include "SharedFirmwareTypes.h"
44

5-
// enum class SteeringEncoderStatus_e
6-
// {
7-
// NOMINAL = 0,
8-
// ERROR = 1,
9-
// };
10-
11-
/// @brief Error and warning flags from the encoder.
12-
/// @note Specific encoders may populate only a subset of these flags.
13-
// struct EncoderErrorFlags_s
14-
// {
15-
// bool dataInvalid = false;
16-
// bool operatingLimit = false;
17-
// bool noData = false;
18-
// };
19-
20-
/// @brief Complete steering angle measurement with status and error flags.
21-
/// @note This struct is transmitted across the CAN bus to other vehicle systems.
22-
// struct SteeringEncoderReading_s
23-
// {
24-
// float angle = 0.0f;
25-
// int rawValue = 0;
26-
// SteeringEncoderStatus_e status = SteeringEncoderStatus_e::NOMINAL;
27-
// EncoderErrorFlags_s errors;
28-
// };
29-
305
class SteeringEncoderInterface
316
{
327
public:

lib/interfaces/include/VCRInterface.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,17 @@
77
#include "etl/singleton.h"
88
#include "hytech.h"
99
#include "FlexCAN_T4.h"
10+
1011
struct InverterErrorFlags_s{
1112

1213
veh_vec<bool> error;
1314

1415
};
16+
17+
struct InverterBusVolts_s{
18+
veh_vec<int> voltage;
19+
};
20+
1521
class VCRInterface
1622
{
1723
public:
@@ -40,6 +46,7 @@ class VCRInterface
4046

4147
VehicleState_e get_vehicle_state() {return _vehicle_state_value;}
4248
DrivetrainState_e get_drivetrain_state() {return _drivetrain_state_value;}
49+
InverterBusVolts_s get_dc_bus_voltage() {return _bus_voltages;}
4350
bool get_db_in_ctrl() {return _is_db_in_ctrl;}
4451
bool get_inverter_error();
4552

@@ -53,7 +60,7 @@ class VCRInterface
5360
TorqueLimit_e _torque_limit = TorqueLimit_e::TCMUX_LOW_TORQUE;
5461
InverterErrorFlags_s _inv_error_status; //creates object that reflects the inverter error status...the object
5562
//holds the error flags for each inverter, the getter above returns True if there's an error in any of the 4
56-
63+
InverterBusVolts_s _bus_voltages;
5764
};
5865

5966
using VCRInterfaceInstance = etl::singleton<VCRInterface>;

lib/interfaces/src/ADCInterface.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,12 @@ void ADCInterface::update_filtered_values(float alpha) {
7979
_FL_sus_pot_filtered = iir_filter(
8080
alpha,
8181
_FL_sus_pot_filtered,
82-
static_cast<float>(FL_sus_pot().raw)
82+
FL_sus_pot().conversion
8383
);
8484
_FR_sus_pot_filtered = iir_filter(
8585
alpha,
8686
_FR_sus_pot_filtered,
87-
static_cast<float>(FR_sus_pot().raw)
87+
FR_sus_pot().conversion
8888
);
8989
}
9090

lib/interfaces/src/DashboardInterface.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
/* Button reads */
77
DashInputState_s DashboardInterface::get_dashboard_outputs()
88
{
9-
_dashboard_outputs.btn_dim_read_is_pressed = !digitalRead(_dashboard_gpios.BTN_DIM_READ);
109
_dashboard_outputs.brightness_ctrl_btn_is_pressed = !digitalRead(_dashboard_gpios.BRIGHTNESS_CONTROL_PIN);
1110
_dashboard_outputs.preset_btn_is_pressed = !digitalRead(_dashboard_gpios.PRESET_BUTTON);
1211
_dashboard_outputs.mc_reset_btn_is_pressed = !digitalRead(_dashboard_gpios.MC_CYCLE_BUTTON);

lib/interfaces/src/NeopixelController.cpp

Lines changed: 11 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -61,27 +61,27 @@ void NeopixelController::refresh_neopixels(const PedalsSystemData_s &pedals_data
6161
}
6262

6363
LED_color_e pack_color = LED_color_e::OFF;
64-
if (interfaces.acu_interface.get_cell_voltage() > 4.1) //NOLINT 4.1 is near max voltage
64+
if (interfaces.acu_interface.get_cell_voltage() > _min_cell_thresholds.max_level) //NOLINT 4.1 is near max voltage
6565
{
6666
pack_color = LED_color_e::PURPLE;
6767
}
68-
else if (interfaces.acu_interface.get_cell_voltage() > 3.8) //NOLINT 3.8 is second from max voltage
68+
else if (interfaces.acu_interface.get_cell_voltage() > _min_cell_thresholds.second_level) //NOLINT 3.8 is second from max voltage
6969
{
7070
pack_color = LED_color_e::BLUE;
7171
}
72-
else if (interfaces.acu_interface.get_cell_voltage() > 3.6) //NOLINT volts
72+
else if (interfaces.acu_interface.get_cell_voltage() > _min_cell_thresholds.third_level) //NOLINT volts
7373
{
7474
pack_color = LED_color_e::GREEN;
7575
}
76-
else if (interfaces.acu_interface.get_cell_voltage() > 3.5) //NOLINT volts
76+
else if (interfaces.acu_interface.get_cell_voltage() > _min_cell_thresholds.fourth_level) //NOLINT volts
7777
{
7878
pack_color = LED_color_e::YELLOW;
7979
}
80-
else if (interfaces.acu_interface.get_cell_voltage() > 3.4) //NOLINT volts
80+
else if (interfaces.acu_interface.get_cell_voltage() > _min_cell_thresholds.fifth_level) //NOLINT volts
8181
{
8282
pack_color = LED_color_e::ORANGE;
8383
}
84-
else if (interfaces.acu_interface.get_cell_voltage() < 3.4) //NOLINT volts
84+
else if (interfaces.acu_interface.get_cell_voltage() < _min_cell_thresholds.critical_charge_level) //NOLINT volts
8585
{
8686
pack_color = LED_color_e::RED;
8787
}
@@ -131,41 +131,16 @@ void NeopixelController::refresh_neopixels(const PedalsSystemData_s &pedals_data
131131
}
132132
}
133133

134-
LED_color_e hv_status_color = LED_color_e::OFF;
135-
switch (interfaces.vcr_interface.get_drivetrain_state())
136-
{
137-
case DrivetrainState_e::NOT_ENABLED_NO_HV_PRESENT:
138-
case DrivetrainState_e::INVERTERS_READY:
139-
{
140-
hv_status_color = LED_color_e::GREEN;
141-
break;
142-
}
143-
case DrivetrainState_e::ENABLED_DRIVE_MODE:
144-
case DrivetrainState_e::INVERTERS_HV_ENABLED:
145-
case DrivetrainState_e::NOT_ENABLED_HV_PRESENT:
146-
{
147-
hv_status_color = LED_color_e::YELLOW;
148-
}
149-
case DrivetrainState_e::ERROR:
150-
{
151-
hv_status_color = LED_color_e::RED;
152-
}
153-
case DrivetrainState_e::CLEARING_ERRORS:
154-
{
155-
hv_status_color = LED_color_e::ORANGE;
156-
}
157-
case DrivetrainState_e::NOT_CONNECTED:
158-
default:
159-
{
160-
hv_status_color = LED_color_e::PURPLE;
161-
}
162-
}
134+
bool hv_present = interfaces.vcr_interface.get_dc_bus_voltage().voltage.FL > _hv_threshold_voltage ||
135+
interfaces.vcr_interface.get_dc_bus_voltage().voltage.FR > _hv_threshold_voltage ||
136+
interfaces.vcr_interface.get_dc_bus_voltage().voltage.RL > _hv_threshold_voltage ||
137+
interfaces.vcr_interface.get_dc_bus_voltage().voltage.RR > _hv_threshold_voltage;
163138

164139

165140
constexpr float glv_critical_voltage = 22.0f;
166141

167142
/* SHUTDOWN LEDS */
168-
set_neopixel_color(LED_ID_e::LATCH, hv_status_color); // Unused for now
143+
set_neopixel_color(LED_ID_e::LATCH, hv_present ? LED_color_e::PURPLE : LED_color_e::GREEN);
169144
set_neopixel_color(LED_ID_e::IMD, interfaces.dash_interface.imd_ok ? LED_color_e::GREEN : LED_color_e::RED);
170145
set_neopixel_color(LED_ID_e::BMS, interfaces.dash_interface.bms_ok ? LED_color_e::GREEN : LED_color_e::RED);
171146
set_neopixel_color(LED_ID_e::SHUTDOWN, LED_color_e::OFF); // Unused for now

lib/interfaces/src/VCFEthernetInterface.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ hytech_msgs_VCFData_s VCFEthernetInterface::make_vcf_data_msg(ADCInterface &ADCI
1414
out.has_front_suspot_data = true;
1515
out.has_pedals_system_data = true;
1616
out.has_steering_data = true;
17+
out.has_steering_system_data = true;
1718
out.has_vcf_ethernet_link_data = true;
1819
out.has_vcf_shutdown_data = true;
20+
out.has_brake_pressure_data = true;
1921

2022
// Load cells
2123
out.front_loadcell_data.FL_loadcell_analog = static_cast<uint32_t>(ADCInterfaceInstance.get_filtered_FL_load_cell());
@@ -45,7 +47,6 @@ hytech_msgs_VCFData_s VCFEthernetInterface::make_vcf_data_msg(ADCInterface &ADCI
4547
out.steering_system_data.both_sensors_fail = steeringInstance.get_steering_system_data().both_sensors_fail;
4648
out.steering_system_data.interface_sensor_error = steeringInstance.get_steering_system_data().interface_sensor_error;
4749

48-
4950
//TODO: MODIFY ETH STRUCT
5051
// Dash
5152
out.dash_input_state.dim_btn_is_pressed = dashInstance.get_dashboard_outputs().brightness_ctrl_btn_is_pressed;
@@ -76,6 +77,10 @@ hytech_msgs_VCFData_s VCFEthernetInterface::make_vcf_data_msg(ADCInterface &ADCI
7677
out.pedals_system_data.brake_percent = pedalsInstance.get_pedals_system_data().brake_percent;
7778
out.pedals_system_data.regen_percent = pedalsInstance.get_pedals_system_data().regen_percent;
7879

80+
// Brake pressure
81+
out.brake_pressure_data.front_brake_pressure = ADCInterfaceInstance.get_brake_pressure_front().conversion;
82+
out.brake_pressure_data.rear_brake_pressure = ADCInterfaceInstance.get_brake_pressure_rear().conversion;
83+
7984
// Shutdown Senses
8085
out.vcf_shutdown_data.d_inertia_switch_out_read = ADCInterfaceInstance.shdn_d().conversion;
8186
out.vcf_shutdown_data.d_inertia_switch = ADCInterfaceInstance.shdn_d().conversion > SHDN_HIGH_THRESHOLD ? true : false;

0 commit comments

Comments
 (0)