Skip to content

Commit 9cc8ef7

Browse files
committed
merged in main
2 parents 27fbcd4 + b841a8e commit 9cc8ef7

13 files changed

Lines changed: 182 additions & 223 deletions

include/VCF_Constants.h

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ namespace VCFInterfaceConstants {
2222
constexpr int BTN_PRESET_READ = 28; // Pedals recal button (brightness control on schematic)
2323

2424
constexpr int NEOPIXEL_CONTROL_PIN = 33;
25-
constexpr int NEOPIXEL_COUNT = 12; // 12 neopixeles on dashboard
25+
constexpr int NEOPIXEL_COUNT = 16; // 16 neopixeles on dashboard
2626

2727
// watchdog pins
2828
constexpr int WATCHDOG_PIN = 36;
@@ -101,6 +101,15 @@ namespace VCFInterfaceConstants {
101101
constexpr float BRAKE_PRESSURE_REAR_SCALE = 1.0;
102102
constexpr float BRAKE_PRESSURE_REAR_OFFSET = 0;
103103

104+
/* VCF CAN Constants */
105+
constexpr uint32_t TELEM_CAN_BAUDRATE = 1000000; // 1 000 000 = 1 Mbit/s
106+
constexpr uint32_t FAUX_CAN_BAUDRATE = 500000; // 500 000 = 500 Kbit/s
107+
}
108+
109+
// calibration and processing constants
110+
namespace VCFSystemConstants {
111+
constexpr float LBS_TO_NEWTONS = 4.4482216153;
112+
104113
// EEPROM addresses for min and max calibration values
105114
constexpr uint32_t ACCEL_1_MIN_ADDR = 0;
106115
constexpr uint32_t ACCEL_2_MIN_ADDR = 4;
@@ -125,11 +134,6 @@ namespace VCFInterfaceConstants {
125134
constexpr uint32_t BRAKE_MAX_SENSOR_PEDAL_2 = 4000;
126135
constexpr float BRAKE_DEADZONE_MARGIN = 0.04f;
127136
constexpr float BRAKE_MECHANICAL_ACTIVATION_PERCENTAGE = 0.5f;
128-
}
129-
130-
// calibration and processing constants
131-
namespace VCFSystemConstants {
132-
constexpr float LBS_TO_NEWTONS = 4.4482216153;
133137

134138
// Steering System Constants
135139
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
@@ -167,38 +171,38 @@ namespace VCFTaskConstants {
167171
constexpr unsigned long CAN_SEND_PRIORITY = 10;
168172
constexpr unsigned long CAN_SEND_PERIOD = 2000; // 2 000 us = 500 Hz
169173

174+
constexpr unsigned long PEDALS_PRIORITY = 5;
170175
constexpr unsigned long PEDALS_SEND_PERIOD = 4000; // 4 000 us = 250 Hz
171176
constexpr unsigned long PEDALS_SAMPLE_PERIOD = 500; // 500 us = 2 kHz
172-
constexpr unsigned long PEDALS_PRIORITY = 5;
173177

174-
constexpr unsigned long BUZZER_WRITE_PERIOD = 100000; // 100 000 us = 10 Hz
175178
constexpr unsigned long BUZZER_PRIORITY = 20;
179+
constexpr unsigned long BUZZER_WRITE_PERIOD = 100000; // 100 000 us = 10 Hz
176180

177-
constexpr unsigned long DASH_SAMPLE_PERIOD = 100000; // 100 000 us = 10 Hz
178181
constexpr unsigned long DASH_SAMPLE_PRIORITY = 21;
182+
constexpr unsigned long DASH_SAMPLE_PERIOD = 100000; // 100 000 us = 10 Hz
179183

180-
constexpr unsigned long DASH_SEND_PERIOD = 100000; // 100 000 us = 10 Hz
181184
constexpr unsigned long DASH_SEND_PRIORITY = 7;
185+
constexpr unsigned long DASH_SEND_PERIOD = 100000; // 100 000 us = 10 Hz
182186

183187
constexpr unsigned long DEBUG_PRIORITY = 100;
184188
constexpr unsigned long DEBUG_PERIOD = 10000; // 10 000 us = 2 Hz
185189

186190
constexpr unsigned long NEOPIXEL_UPDATE_PRIORITY = 90;
187191
constexpr unsigned long NEOPIXEL_UPDATE_PERIOD = 100000; // 100 000 us = 10 Hz
188192

189-
constexpr unsigned long STEERING_SEND_PERIOD = 4000; // 4 000 us = 250 Hz
190193
constexpr unsigned long STEERING_SEND_PRIORITY = 25;
194+
constexpr unsigned long STEERING_SEND_PERIOD = 4000; // 4 000 us = 250 Hz
195+
191196
constexpr unsigned long STEERING_SAMPLE_PERIOD = 1000; // 2000 us = 500 Hz
192197
constexpr unsigned long STEERING_SAMPLE_PRIORITY = 10;
193198

194-
constexpr unsigned long LOADCELL_SAMPLE_PERIOD = 250; // 250 us = 4 kHz
195199
constexpr unsigned long LOADCELL_SAMPLE_PRIORITY = 24;
200+
constexpr unsigned long LOADCELL_SAMPLE_PERIOD = 250; // 250 us = 4 kHz
201+
constexpr unsigned long LOADCELL_SEND_PRIORITY = 25;
202+
constexpr unsigned long LOADCELL_SEND_PERIOD = 4000; // 4 000 us = 250 Hz
196203

197-
constexpr unsigned long ETHERNET_SEND_PERIOD = 100000; // 100 000 us = 10Hz
198204
constexpr unsigned long ETHERNET_SEND_PRIORITY = 20;
199-
200-
constexpr unsigned long LOADCELL_SEND_PERIOD = 4000; // 4 000 us = 250 Hz
201-
constexpr unsigned long LOADCELL_SEND_PRIORITY = 25;
205+
constexpr unsigned long ETHERNET_SEND_PERIOD = 100000; // 100 000 us = 10Hz
202206

203207
constexpr unsigned long PEDALS_RECALIBRATION_PRIORITY = 150;
204208
constexpr unsigned long PEDALS_RECALIBRATION_PERIOD = 100000; // 100 000 us = 10 Hz

include/VCF_Globals.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,7 @@
2727
/* From MCP23017 Library */
2828
#include "MCP23017.h"
2929

30-
31-
/* Interface and system data structs */
32-
// using VCFData_sInstance = etl::singleton<VCFData_s>;
33-
3430
/* IOExpander setup */
3531
using IOExpanderInstance = etl::singleton<MCP23017>;
3632

37-
/* Digital Steering Setup */
38-
using OrbisBRInstance = etl::singleton<OrbisBR>;
39-
40-
/* Ethernet sockets */
41-
extern qindesign::network::EthernetUDP VCF_socket;
42-
extern qindesign::network::EthernetUDP VCR_socket;
43-
4433
#endif /* VCF_GLOBALS */

lib/interfaces/include/NeopixelController.h

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,34 @@
1818
#include "etl/singleton.h"
1919
#include "VCFCANInterfaceImpl.h"
2020

21+
struct MinCellMonitoringThresholds_s
22+
{
23+
float max_level = 3.85;
24+
float second_level = 3.7;
25+
float third_level = 3.65;
26+
float fourth_level = 3.6;
27+
float fifth_level = 3.5;
28+
float critical_charge_level = 3.4;
29+
};
30+
2131
enum LED_ID_e
2232
{
23-
SHUTDOWN = 0,
24-
INVERTER_ERR = 1,
25-
TORQUE_MODE = 2,
26-
BRAKE = 3,
27-
BMS = 4,
28-
GLV = 5,
29-
PACK = 6,
30-
IMD = 7,
31-
IMPLAUSE = 8,
32-
RDY_DRIVE = 9,
33-
LATCH = 10,
34-
CRIT_CHARGE = 11
33+
INVERTER_ERR_WING = 0,
34+
BMS_WING = 1,
35+
SHUTDOWN = 2,
36+
INVERTER_ERR = 3,
37+
TORQUE_MODE = 4,
38+
BRAKE = 5,
39+
BMS = 6,
40+
GLV = 7,
41+
PACK = 8,
42+
IMD = 9,
43+
IMPLAUSE = 10,
44+
RDY_DRIVE = 11,
45+
LATCH = 12,
46+
CRIT_CHARGE = 13,
47+
LATCH_WING= 14,
48+
IMD_WING = 15
3549
};
3650

3751
enum class LED_color_e

lib/interfaces/include/VCFCANInterfaceImpl.h

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@
2020
/* Globally accessible types */
2121
using CANRXBufferType = Circular_Buffer<uint8_t, (uint32_t)16, sizeof(CAN_message_t)>;
2222
using CANTXBufferType = Circular_Buffer<uint8_t, (uint32_t)128, sizeof(CAN_message_t)>;
23-
template <CAN_DEV_TABLE CAN_DEV> using FlexCAN_Type = FlexCAN_T4<CAN_DEV, RX_SIZE_256, TX_SIZE_16>;
23+
24+
// Definitions of VCF CAN bus types
25+
using TelemCAN_t = FlexCAN_T4<CAN1, RX_SIZE_256, TX_SIZE_16>;
26+
using FrontAuxCAN_t = FlexCAN_T4<CAN2, RX_SIZE_256, TX_SIZE_16>;
2427

2528
/* Interfaces accessible to this one */
2629
struct CANInterfaces {
@@ -33,30 +36,33 @@ struct CANInterfaces {
3336
ACUInterface &acu_interface;
3437
VCRInterface &vcr_interface;
3538
};
39+
using CANInterfacesInstance = etl::singleton<CANInterfaces>;
3640

37-
struct VCFCANInterfaceObjects {
41+
struct VCFCANInterface {
42+
VCFCANInterface(etl::delegate<void (CANInterfaces &, const CAN_message_t &, unsigned long, CANInterfaceType_e)> recv_switch_func)
43+
: can_recv_switch(recv_switch_func)
44+
{}
3845

39-
VCFCANInterfaceObjects(etl::delegate<void(CANInterfaces &, const CAN_message_t &, unsigned long, CANInterfaceType_e)> recv_switch, FlexCAN_T4_Base * main_can): MAIN_CAN(main_can),can_recv_switch(recv_switch)
40-
{}
46+
TelemCAN_t TELEM_CAN;
4147

42-
43-
FlexCAN_T4_Base* MAIN_CAN;
44-
// TODO fix this. needs to be a pointer to an in-main global created instance of CAN3. this also cannot be a base type.
45-
CANRXBufferType main_can_rx_buffer;
46-
CANTXBufferType main_can_tx_buffer;
47-
etl::delegate<void(CANInterfaces &, const CAN_message_t &, unsigned long, CANInterfaceType_e)> can_recv_switch;
48-
48+
CANRXBufferType telem_can_rx_buffer;
49+
CANTXBufferType telem_can_tx_buffer;
50+
51+
FrontAuxCAN_t FRONT_AUX_CAN;
52+
53+
CANRXBufferType front_aux_can_rx_buffer;
54+
CANTXBufferType front_aux_can_tx_buffer;
55+
56+
etl::delegate<void (CANInterfaces &, const CAN_message_t &, unsigned long, CANInterfaceType_e)> can_recv_switch;
4957
};
58+
using VCFCANInterfaceInstance = etl::singleton<VCFCANInterface>;
5059

5160
namespace VCFCANInterfaceImpl {
5261
void on_main_can_recv(const CAN_message_t &msg);
53-
void vcf_recv_switch(CANInterfaces &interfaces, const CAN_message_t &msg, unsigned long millis, CANInterfaceType_e interface_type);
62+
void on_faux_can_recv(const CAN_message_t &msg);
63+
64+
void vcf_recv_switch(CANInterfaces &interfaces, const CAN_message_t &msg, unsigned long millis, CANInterfaceType_e interface_type); //vcf can receive
5465
void send_all_CAN_msgs(CANTXBufferType &buffer, FlexCAN_T4_Base *can_interface);
55-
56-
extern FlexCAN_T4<CAN1, RX_SIZE_256, TX_SIZE_16> main_can;
57-
58-
using VCFCANInterfaceObjectsInstance = etl::singleton<VCFCANInterfaceObjects>;
59-
using CANInterfacesInstance = etl::singleton<CANInterfaces>;
6066
}
6167

6268
#endif // VCFCANINTERFACEIMPL_H

lib/interfaces/include/VCFEthernetInterface.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef VCF_ETHERNET_INTERFACE_H
22
#define VCF_ETHERNET_INTERFACE_H
33

4+
#include "QNEthernet.h"
45
#include "hytech_msgs.pb.h"
56
#include "SharedFirmwareTypes.h"
67
#include "ADCInterface.h"
@@ -32,6 +33,10 @@ namespace VCFEthernetInterface
3233

3334
constexpr const size_t ver_hash_len = 9;
3435
constexpr float SHDN_HIGH_THRESHOLD = 12.0; // threshold for shutdown being considered high
36+
37+
/* Ethernet sockets */
38+
extern qindesign::network::EthernetUDP VCF_socket;
39+
extern qindesign::network::EthernetUDP VCR_socket;
3540
}
3641

3742
#endif /* VCF_ETHERNET_INTERFACE_H */

lib/interfaces/include/VCRInterface.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class VCRInterface
3737

3838
void receive_inverter_status_4(const CAN_message_t &can_msg);
3939

40+
4041
VehicleState_e get_vehicle_state() {return _vehicle_state_value;}
4142
DrivetrainState_e get_drivetrain_state() {return _drivetrain_state_value;}
4243
bool get_db_in_ctrl() {return _is_db_in_ctrl;}

lib/interfaces/src/NeopixelController.cpp

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,37 @@ void NeopixelController::init_neopixels() {
44
_neopixels.begin();
55
_neopixels.setBrightness(_current_brightness);
66
//set init color for every led
7-
for (int i = 0; i < _neopixel_count; i++) {
7+
for (int i = 0; i < _neopixel_count; i++)
8+
{
89
// BMS and IMD are off according to rules
9-
if (i == LED_ID_e::BMS || i == LED_ID_e::IMD){
10+
if (i == LED_ID_e::BMS || i == LED_ID_e::IMD || i == LED_ID_e::BMS_WING || i == LED_ID_e::IMD_WING)
11+
{
1012
_neopixels.setPixelColor(i, (uint32_t) LED_color_e::OFF);
11-
} else {
13+
}
14+
else
15+
{
1216
_neopixels.setPixelColor(i, (uint32_t) LED_color_e::INIT_COLOR);
1317
}
1418
}
1519
// write data to neopixels
1620
_neopixels.show();
1721
}
1822

19-
void NeopixelController::dim_neopixels() {
23+
void NeopixelController::dim_neopixels()
24+
{
2025
_current_brightness -= STEP_BRIGHTNESS;
2126
// set current brightness to 0xFF (255) if less than min brightness - sid :) DO NOT CHANGE
2227
if (_current_brightness < MIN_BRIGHTNESS) { _current_brightness |= 0xFF; } // NOLINT (bitmask with 255)
2328
_neopixels.setBrightness(_current_brightness);
2429
}
2530

26-
void NeopixelController::set_neopixel(uint16_t id, uint32_t c) {
31+
void NeopixelController::set_neopixel(uint16_t id, uint32_t c)
32+
{
2733
_neopixels.setPixelColor(id, c);
2834
}
2935

30-
void NeopixelController::refresh_neopixels(const PedalsSystemData_s &pedals_data, CANInterfaces &interfaces) {
31-
36+
void NeopixelController::refresh_neopixels(const PedalsSystemData_s &pedals_data, CANInterfaces &interfaces)
37+
{
3238
// If we are in pedals recalibration state, LIGHT UP DASHBOARD ALL RED.
3339
if (interfaces.vcr_interface.is_in_pedals_calibration_state() || interfaces.vcr_interface.is_in_steering_calibration_state()) {
3440
set_neopixel_color(LED_ID_e::BRAKE, LED_color_e::RED);
@@ -41,6 +47,8 @@ void NeopixelController::refresh_neopixels(const PedalsSystemData_s &pedals_data
4147
set_neopixel_color(LED_ID_e::INVERTER_ERR, LED_color_e::RED);
4248
set_neopixel_color(LED_ID_e::RDY_DRIVE, LED_color_e::RED);
4349
set_neopixel_color(LED_ID_e::GLV, LED_color_e::RED);
50+
set_neopixel_color(LED_ID_e::INVERTER_ERR_WING, LED_color_e::RED);
51+
set_neopixel_color(LED_ID_e::LATCH_WING, LED_color_e::RED);
4452
_neopixels.show();
4553
return;
4654
}
@@ -161,13 +169,18 @@ void NeopixelController::refresh_neopixels(const PedalsSystemData_s &pedals_data
161169
set_neopixel_color(LED_ID_e::IMD, interfaces.dash_interface.imd_ok ? LED_color_e::GREEN : LED_color_e::RED);
162170
set_neopixel_color(LED_ID_e::BMS, interfaces.dash_interface.bms_ok ? LED_color_e::GREEN : LED_color_e::RED);
163171
set_neopixel_color(LED_ID_e::SHUTDOWN, LED_color_e::OFF); // Unused for now
172+
set_neopixel_color(LED_ID_e::IMD_WING, interfaces.dash_interface.imd_ok ? LED_color_e::GREEN : LED_color_e::RED);
173+
set_neopixel_color(LED_ID_e::BMS_WING, interfaces.dash_interface.bms_ok ? LED_color_e::GREEN : LED_color_e::RED);
164174

165175
/* DRIVETRAIN LEDS */
166176
set_neopixel_color(LED_ID_e::BRAKE, brake_light_color);
167177
set_neopixel_color(LED_ID_e::INVERTER_ERR, interfaces.vcr_interface.get_inverter_error() ? LED_color_e::RED : LED_color_e::GREEN);
168178
set_neopixel_color(LED_ID_e::RDY_DRIVE, ready_drive_color);
169179
set_neopixel_color(LED_ID_e::TORQUE_MODE, torque_mode_color);
170-
set_neopixel_color(LED_ID_e::IMPLAUSE, pedals_data.brake_is_implausible ? LED_color_e::GREEN : LED_color_e::RED); // Unused for now
180+
set_neopixel_color(LED_ID_e::IMPLAUSE, pedals_data.brake_and_accel_pressed_implausibility_high ? LED_color_e::RED : LED_color_e::GREEN); // Unused for now
181+
182+
set_neopixel_color(LED_ID_e::LATCH_WING, hv_present ? LED_color_e::PURPLE : LED_color_e::GREEN); // Unused for now
183+
set_neopixel_color(LED_ID_e::INVERTER_ERR_WING, interfaces.vcr_interface.get_inverter_error() ? LED_color_e::RED : LED_color_e::GREEN);
171184

172185
/* VOLTAGE MONITOR */
173186
set_neopixel_color(LED_ID_e::PACK, pack_color); // Unused for now

lib/interfaces/src/VCFCANInterfaceImpl.cpp

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,31 @@
11
#include "VCFCANInterfaceImpl.h"
22
#include "BuzzerController.h"
33

4-
namespace VCFCANInterfaceImpl {
4+
namespace VCFCANInterfaceImpl {
55
void on_main_can_recv(const CAN_message_t &msg)
66
{
77
uint8_t buf[sizeof(CAN_message_t)];
88
memmove(buf, &msg, sizeof(msg)); // NOLINT (memory operations are fine)
9-
VCFCANInterfaceObjectsInstance::instance().main_can_rx_buffer.push_back(buf, sizeof(CAN_message_t));
9+
VCFCANInterfaceInstance::instance().telem_can_rx_buffer.push_back(buf, sizeof(CAN_message_t));
10+
}
11+
12+
void on_faux_can_recv(const CAN_message_t &msg)
13+
{
14+
VCFCANInterfaceInstance::instance().TELEM_CAN.write(msg); //immediately forward onto telem can to view data
15+
uint8_t buf[sizeof(CAN_message_t)];
16+
memmove(buf, &msg, sizeof(msg)); // NOLINT (memory operations are fine)
17+
VCFCANInterfaceInstance::instance().front_aux_can_rx_buffer.push_back(buf, sizeof(CAN_message_t));
18+
19+
// Serial.println("msg recvd");
20+
// Serial.print("MB: "); Serial.print(msg.mb);
21+
// Serial.print(" ID: 0x"); Serial.print(msg.id, HEX);
22+
// Serial.print(" EXT: "); Serial.print(msg.flags.extended);
23+
// Serial.print(" LEN: "); Serial.print(msg.len);
24+
// Serial.print(" DATA: ");
25+
// for ( uint8_t i = 0; i < 8; i++ ) {
26+
// Serial.print(msg.buf[i]); Serial.print(" ");
27+
// }
28+
// Serial.print(" TS: "); Serial.println(msg.timestamp);
1029
}
1130

1231
void vcf_recv_switch(CANInterfaces &interfaces, const CAN_message_t &msg, unsigned long millis, CANInterfaceType_e interface_type)
@@ -53,7 +72,6 @@ namespace VCFCANInterfaceImpl {
5372
interfaces.vcr_interface.receive_inverter_status_4(msg);
5473
break;
5574
}
56-
5775
default:
5876
break;
5977
}

0 commit comments

Comments
 (0)