1#ifdef ENABLE_DEBUG_PRINTS
2#define DEBUG_PRINTS true
4#define DEBUG_PRINTS false
11#include "FlexCAN_T4.h"
12#include "HyTech_CAN.h"
17#include "ProtobufMsgInterface.h"
18#include "HytechCANInterface.h"
20#include "Teensy_ADC.h"
22#include "ORBIS_BR10.h"
23#include "MCUInterface.h"
24#include "AMSInterface.h"
25#include "WatchdogInterface.h"
26#include "DashboardInterface.h"
27#include "InverterInterface.h"
28#include "TelemetryInterface.h"
30#include "VectornavInterface.h"
31#include "LoadCellInterface.h"
51#include "hytech_msgs.pb.h"
55using namespace qindesign::network;
168FlexCAN_T4<CAN2, RX_SIZE_256, TX_SIZE_16>
INV_CAN;
231 .tcs_pid_p_lowerBound_front = 55.0,
232 .tcs_pid_p_upperBound_front = 42.0,
233 .tcs_pid_p_lowerBound_rear = 32.0,
234 .tcs_pid_p_upperBound_rear = 42.0,
239 .useTCSLimitedYawPID =
true,
240 .useNormalForce =
true,
241 .useTractionControl =
true,
242 .usePowerLimit =
true,
243 .usePIDPowerLimit =
false,
244 .useDecoupledYawBrakes =
true,
245 .useDiscontinuousYawPIDBrakes =
true,
246 .launchDeadZone = 20.0,
247 .launchVelThreshold = 0.15,
248 .tcsVelThreshold = 1.5,
249 .yawPIDMaxDifferential = 10.0,
250 .yawPIDErrorThreshold = 0.1,
251 .yawPIDVelThreshold = 0.35,
252 .yawPIDCoastThreshold = 2.5,
253 .yaw_pid_brakes_p = 0.1,
254 .yaw_pid_brakes_i = 0.0,
255 .yaw_pid_brakes_d = 0.0,
256 .decoupledYawPIDBrakesMaxDIfference = 2,
257 .discontinuousBrakesPercentThreshold = 0.7,
260 .useNoRegen5kph =
true,
261 .useTorqueBias =
true,
262 .DriveTorquePercentFront = 0.5,
263 .BrakeTorquePercentFront = 0.6,
264 .MechPowerMaxkW = 51.5,
265 .launchLeftRightMaxDiff = 2.0,
266 .tcs_pid_lower_rpm_front = 0.0,
267 .tcs_pid_upper_rpm_front = 5000.0,
268 .tcs_pid_lower_rpm_rear = 0.0,
269 .tcs_pid_upper_rpm_rear = 5000.0,
270 .maxNormalLoadBrakeScalingFront = 1.15,
271 .tcs_saturation_front = 20,
272 .tcs_saturation_rear = 20,
273 .TCSGenLeftRightDiffLowerBound = 2,
274 .TCSGenLeftRightDiffUpperBound = 20,
275 .TCSWheelSteerLowerBound = 2,
276 .TCSWheelSteerUpperBound = 25,
277 .useRPM_TCS_GainSchedule =
true,
278 .useNL_TCS_GainSchedule =
false,
279 .TCS_NL_startBoundPerc_FrontAxle = 0.5,
280 .TCS_NL_endBoundPerc_FrontAxle = 0.4,
281 .TCS_NL_startBoundPerc_RearAxle = 0.5,
282 .TCS_NL_endBoundPerc_RearAxle = 0.6,
283 .useNL_TCS_SlipSchedule =
true,
284 .launchSL_startBound_Front = 0.25,
285 .launchSL_endBound_Front = 0.25,
286 .launchSL_startBound_Rear = 0.3,
287 .launchSL_endBound_Rear = 0.4,
288 .TCS_SL_startBound_Front = 0.25,
289 .TCS_SL_endBound_Front = 0.15,
290 .TCS_SL_startBound_Rear = 0.3,
291 .TCS_SL_endBound_Rear = 0.4,
292 .TCS_SL_NLPerc_startBound_Front = 0.5,
293 .TCS_SL_NLPerc_endBound_Front = 0.4,
294 .TCS_SL_NLPerc_startBound_Rear = 0.5,
295 .TCS_SL_NLPerc_endBound_Rear = 0.6,
299 .max_regen_torque = 21.42,
322 {
false,
false,
true,
false,
true});
389 SysTick_s curr_tick =
sys_clock.tick(micros());
401 Serial.begin(115200);
406 safety_system.init();
420 SysTick_s curr_tick =
sys_clock.tick(micros());
434 steering_system.getSteeringSystemData(),
439 vn_interface.get_vn_struct(),
459 fsm.tick_state_machine(curr_tick.millis, car_state_inst);
462 safety_system.software_shutdown(curr_tick);
472 Serial.print(
"Steering system reported angle (deg): ");
473 Serial.println(steering_system.getSteeringSystemData().angle);
474 Serial.print(
"Steering system status: ");
475 Serial.println(
static_cast<uint8_t
>(steering_system.getSteeringSystemData().status));
476 Serial.print(
"Primary sensor angle: ");
477 Serial.println(
steering1.convert().angle);
478 Serial.print(
"Secondary sensor angle: ");
480 Serial.print(
" raw: ");
482 Serial.print(
"Sensor divergence: ");
485 Serial.println(
"Pedal outputs:");
486 Serial.print(
"Accel 1 raw: ");
488 Serial.print(
"Accel 2 raw: ");
490 Serial.print(
"Accel percent: ");
492 Serial.print(
"Brake 1 raw: ");
494 Serial.print(
"Brake 2 raw: ");
496 Serial.print(
"Brake percent: ");
499 Serial.print(
"Derating factor: ");
501 Serial.print(
"Filtered min cell voltage: ");
502 Serial.println(
ams_interface.get_filtered_min_cell_voltage());
503 Serial.print(
"Filtered max cell temp: ");
505 Serial.print(
"Current TC index: ");
507 Serial.print(
"Current TC error: ");
510 Serial.print(
"dial state: ");
511 Serial.println(
static_cast<int>(dashboard.getDialMode()));
549 TriggerBits_s t = current_system_tick.triggers;
554 int(fsm.get_state()),
561 dashboard.getDialMode());
564 static_cast<int>(fsm.get_state()),
566 safety_system.get_software_is_ok(),
571 dashboard.launchControlButtonPressed());
576 telem_interface.tick(
625 main_ecu.read_mcu_status();
645 steering_system.tick(
647 .tick = current_system_tick,
654 auto __attribute__((unused)) case_status =
case_system.evaluate(
656 vn_interface.get_vn_struct(),
657 steering_system.getSteeringSystemData(),
663 dashboard.startButtonPressed(),
664 vn_interface.get_vn_struct().vn_status);
672 std::function<void(
unsigned long,
const uint8_t *,
size_t,
DrivebrainETHInterface &,
const pb_msgdesc_t *)> recv_boi = &recv_pb_stream_msg<hytech_msgs_MCUCommandData, DrivebrainETHInterface>;
675 if (systick.triggers.trigger1000)
const int MCU15_BRAKE1_CHANNEL
const int MCU15_STEERING_CHANNEL
const float LOADCELL_FL_SCALE
const int MCU15_ACCEL2_CHANNEL
const int BRAKE2_PEDAL_OOR_MIN
const float LOADCELL_FL_OFFSET
const int ACCEL1_PEDAL_MIN
const int BRAKE1_PEDAL_MAX
const int BRAKE2_PEDAL_MIN
const int MCU15_CUR_POS_SENSE_CHANNEL
const float DEFAULT_PEDAL_IMPLAUSIBILITY_MARGIN
const int MCU15_GLV_SENSE_CHANNEL
const int BRAKE1_PEDAL_MIN
const int ACCEL1_PEDAL_MAX
const float BRAKE_ACTIVATION_PERCENTAGE
const unsigned long TELEM_CAN_BAUDRATE
const float GLV_SENSE_SCALE
const float LOADCELL_RL_SCALE
const float STEERING_RANGE_DEGREES
const int ACCEL2_PEDAL_OOR_MIN
const int ACCEL2_PEDAL_MIN
const int MCU15_FL_POTS_CHANNEL
const float STEERING_IIR_ALPHA
const int DEFAULT_ANALOG_PINS[MCU15_TEENSY_ADC_CHANNELS]
const int BRAKE1_PEDAL_OOR_MIN
const int ACCEL2_PEDAL_MAX
const int ACCEL1_PEDAL_OOR_MAX
const float DEFAULT_PEDAL_DEADZONE
const float LOADCELL_FR_SCALE
const int MCU15_FR_LOADCELL_CHANNEL
const float APPS_ACTIVATION_PERCENTAGE
const int ACCEL2_PEDAL_OOR_MAX
const int MCU15_BRAKE2_CHANNEL
const int MCU15_FL_LOADCELL_CHANNEL
const float LOADCELL_RL_OFFSET
const int SECONDARY_STEERING_SENSE_RIGHTMOST_BOUND
const int MCU15_ACCEL1_CHANNEL
const int ACCEL1_PEDAL_OOR_MIN
const float PRIMARY_STEERING_SENSE_OFFSET
const unsigned long INV_CAN_BAUDRATE
const int MCU15_CUR_NEG_SENSE_CHANNEL
const unsigned long BUZZER_ON_INTERVAL
const float BRAKE_MECH_THRESH
const float LOADCELL_RR_OFFSET
const float LOADCELL_RR_SCALE
const int BRAKE2_PEDAL_MAX
const int BRAKE2_PEDAL_OOR_MAX
const float LOADCELL_FR_OFFSET
const int BRAKE1_PEDAL_OOR_MAX
const int MCU15_FR_POTS_CHANNEL
const unsigned long INVERTER_ENABLING_TIMEOUT_INTERVAL
const int SECONDARY_STEERING_SENSE_LEFTMOST_BOUND
const int SECONDARY_STEERING_SENSE_CENTER
Circular_Buffer< uint8_t,(uint32_t) 128, sizeof(CAN_message_t)> CANBufferType
const int MCU15_THERM_FR_CHANNEL
const int MCU15_THERM_FL_CHANNEL
this class is for interfacing with the AMS (accumulator management system)
AnalogConversion_s convert()
Calculate sensor output and whether result is in sensor's defined bounds. DOES NOT SAMPLE.
this class with both take in sensor inputs as well as handle calculations for various derived states ...
Base class for all controllers, which define drivetrain command containing different variations of
Drivebrain Controller for fail-safe pass-through control of the car RESPONSIBILITIES AND DOCUMENTATIO...
bool get_timing_failure_status()
getter for the current status of whether or not the controller has had a timing failure during operat...
hytech_msgs_MCUOutputData make_db_msg(const SharedCarState_s &shared_state)
DrivebrainData_s get_latest_data()
bool drivetrain_error_occured()
void tick(const SysTick_s &tick)
DrivetrainDynamicReport_s get_dynamic_data()
LoadCellInterfaceOutput_s getLoadCellForces()
void tick(const LoadCellInterfaceTick_s &intake)
LoadCellInterfaceRawOutput_s get_latest_raw_data()
void update_raw_data(const LoadCellInterfaceTick_s &intake)
PedalsSystemData_s getPedalsSystemDataCopy()
const PedalsSystemData_s & getPedalsSystemData()
void tick(const SysTick_s &tick, const AnalogConversion_s &accel1, const AnalogConversion_s &accel2, const AnalogConversion_s &brake)
overloaded tick function that runs the evaluation of the pedals system. evaluates brake using only mi...
float getMechBrakeActiveThreshold()
makes CASE system a part of Controller hierarchy for use in TC Mux
const TorqueControllerMuxStatus & get_tc_mux_status()
void init(unsigned long curr_millis)
void on_can2_receive(const CAN_message_t &msg)
Circular_Buffer< uint8_t,(uint32_t) 16, sizeof(CAN_message_t)> CAN3_rxBuffer
void process_ring_buffer(BufferType &rx_buffer, const InterfaceType &interfaces, unsigned long curr_millis)
void send_all_CAN_msgs(bufferType &buffer, FlexCAN_T4_Base *can_interface)
void on_can3_receive(const CAN_message_t &msg)
Circular_Buffer< uint8_t,(uint32_t) 16, sizeof(CAN_message_t)> CAN2_rxBuffer
CANBufferType CAN2_txBuffer
const uint16_t default_protobuf_send_port
uint8_t default_MCU_MAC_address[6]
const IPAddress default_TCU_ip(192, 168, 1, 69)
const uint16_t default_protobuf_recv_port
const IPAddress default_MCU_ip(192, 168, 1, 30)
LoadCellInterface load_cell_interface
SteeringSystem steering_system & steering1
PedalsSystem pedals_system(accel_params, brake_params)
TorqueControllerSimple tc_simple(1.0f, 1.0f)
InverterInterface< CircularBufferType > InvInt_t
SABInterface sab_interface(LOADCELL_RL_SCALE, LOADCELL_RL_OFFSET, LOADCELL_RR_SCALE, LOADCELL_RR_OFFSET)
DrivebrainController db_controller(210)
OrbisBR10 steering1 & Serial5
FlexCAN_T4< CAN2, RX_SIZE_256, TX_SIZE_16 > INV_CAN
const PedalsParams accel2_only_params
TCMuxType torque_controller_mux({static_cast< Controller * >(&tc_simple), static_cast< Controller * >(&tc_vec), static_cast< Controller * >(&case_wrapper), static_cast< Controller * >(&simple_launch), static_cast< Controller * >(&db_controller)}, {false, false, true, false, true})
TorqueControllerLoadCellVectoring tc_vec
const PedalsParams accel_params
void tick_all_interfaces(const SysTick_s ¤t_system_tick)
EthernetUDP protobuf_send_socket
CANBufferType CircularBufferType
TorqueControllerCASEWrapper< CircularBufferType > case_wrapper & case_system
const PedalsParams brake1_only_params
const PedalsParams brake_params
const TelemetryInterfaceReadChannels telem_read_channels
BuzzerController buzzer(BUZZER_ON_INTERVAL)
CANInterfaces< CircularBufferType > CAN_receive_interfaces
WatchdogInterface wd_interface(WATCHDOG_INPUT)
VNInterface< CircularBufferType > vn_interface & CAN3_txBuffer
ETHInterfaces ethernet_interfaces
DrivebrainETHInterface db_eth_interface
FlexCAN_T4< CAN3, RX_SIZE_256, TX_SIZE_16 > TELEM_CAN
EthernetUDP protobuf_recv_socket
const PedalsParams brake2_only_params
void tick_all_systems(const SysTick_s ¤t_system_tick)
CASEConfiguration case_config
void handle_ethernet_interface_comms(const SysTick_s &systick, const hytech_msgs_MCUOutputData &out_msg)
SafetySystem safety_system & ams_interface
const PedalsParams accel1_only_params
void init_all_CAN_devices()
DrivetrainSystem< InvInt_t > DriveSys_t
TorqueControllerSimpleLaunch simple_launch
float AbsoluteTorqueLimit
veh_vec< AnalogConversion_s > loadCellConversions
system interface struct that contains the data from the pedal system
car state struct that contains state of everything about the car including
bool drivebrain_timing_failure
TorqueLimit_e active_torque_limit_enum
TorqueControllerMuxError active_error
ControllerMode_e active_controller_mode