MCU
Loading...
Searching...
No Matches
AMSInterface.h
Go to the documentation of this file.
1#ifndef __AMSINTERFACE_H__
2#define __AMSINTERFACE_H__
3
4#include "FlexCAN_T4.h"
5#include "HyTech_CAN.h"
6#include "SysClock.h"
7#include "hytech.h"
9
10/* Heartbeat Interval is the allowable amount of time between BMS status messages before car delatches */
11const unsigned long HEARTBEAT_INTERVAL = 2000; // milliseconds
12/* The total pcc threshold is the lowest allowable voltage of the entire pack (in Volts)*/
13const unsigned long PACK_CHARGE_CRIT_TOTAL_THRESHOLD = 420;
14/* The lowest pcc threshold is the lowest allowable single cell voltage (in 100 microvolts)*/
15const unsigned long PACK_CHARGE_CRIT_LOWEST_CELL_THRESHOLD = 35000; //equivalent to 3.5V
16
17const float DEFAULT_INIT_TEMP = 40.0;
18const float DEFAULT_INIT_VOLTAGE = 3.5;
19const float DEFAULT_TEMP_ALPHA = 0.8;
20const float DEFAULT_VOLTAGE_ALPHA = 0.8;
21const uint16_t MAX_PACK_CHARGE = 48600;
22const unsigned long DEFAULT_INITIALIZATION_WAIT_INTERVAL = 5000;
23
24
27{
28public:
34 AMSInterface(CANBufferType *msg_output_queue, int sw_ok_pin, float init_temp, float init_volt, float temp_alpha, float volt_alpha):
35 msg_queue_(msg_output_queue),
36 pin_software_ok_(sw_ok_pin),
37 filtered_max_cell_temp(init_temp),
39 cell_temp_alpha(temp_alpha),
40 cell_voltage_alpha(volt_alpha),
41 use_em_for_soc_(true),
42 charge_(0.0f),
43 SoC_(0.0f),
46
47 /* Overloaded constructor that only takes in software OK pin and uses default voltages and temp*/
48 AMSInterface(CANBufferType *msg_output_queue, int sw_ok_pin):
50
51 /* Initialize the heartbeat timer */
52 void init(SysTick_s &initial_tick);
53
54 /* Init software OK pin by setting high*/
55 void set_start_state();
56
57 /* Check if the last heartbeat arrived within allowable interval */
58 bool heartbeat_received(unsigned long curr_millis);
59
60 /* Check if either lowest cell or total pack is below threshold*/
62
63 //SETTERS//
64 /* set software OK pin */
65 void set_state_ok_high(bool ok_high);
66 /* set the last heartbeat to the current millis time */
67 void set_heartbeat(unsigned long curr_millis);
68
69 //GETTERS//
70 /* IIR filter and return filtered max cell temperature */
72 /* IIR filter and return filtered min cell voltage */
74 /*gets the derate factor for acc system*/
76
83 float initialize_charge();
84
94 void calculate_SoC_em(const SysTick_s &tick);
95
105 void calculate_SoC_acu(const SysTick_s &tick);
106
113 float get_SoC() {return SoC_;}
114
121 void tick(const SysTick_s &tick);
122
123 //RETRIEVE CAN MESSAGES//
124
128 void retrieve_status_CAN(unsigned long curr_millis, CAN_message_t &recvd_msg);
129
133 void retrieve_temp_CAN(CAN_message_t &recvd_msg);
134
139 void retrieve_voltage_CAN(CAN_message_t &recvd_msg);
140
141 /*Updates Acc_derate_factor*/
143
148 void retrieve_em_measurement_CAN(CAN_message_t &can_msg);
149
154 void retrieve_current_shunt_CAN(const CAN_message_t &can_msg);
155
161
166 void set_use_em_for_soc(bool new_use_em_for_soc) {
167 use_em_for_soc_ = new_use_em_for_soc;
168 }
169
174
176 template <typename U>
177 void enqueue_new_CAN(U *structure, uint32_t (*pack_function)(U *, uint8_t *, uint8_t *, uint8_t *));
178
179 // Getters (for testing purposes)
180 BMS_VOLTAGES_t get_bms_voltages() {return bms_voltages_;}
181 EM_MEASUREMENT_t get_em_measurements() {return em_measurements_;}
182 ACU_SHUNT_MEASUREMENTS_t get_acu_shunt_measurements() {return acu_shunt_measurements_;}
183
184
185private:
186
187 const float VOLTAGE_LOOKUP_TABLE[101] = {3.972, 3.945, 3.918, 3.891, 3.885, 3.874, 3.864, 3.858, 3.847, 3.836, 3.82, 3.815, 3.815, 3.798, 3.788,
188 3.782, 3.771, 3.755, 3.744, 3.744, 3.733, 3.728, 3.723, 3.712, 3.701, 3.695, 3.69, 3.679, 3.679, 3.668, 3.663, 3.657, 3.647,
189 3.647, 3.636, 3.625, 3.625, 3.625, 3.614, 3.609, 3.603, 3.603, 3.592, 3.592, 3.592, 3.581, 3.581, 3.571, 3.571, 3.571, 3.56,
190 3.56, 3.56, 3.549, 3.549, 3.549, 3.549, 3.538, 3.538, 3.551, 3.546, 3.535, 3.535, 3.535, 3.53, 3.524, 3.524, 3.524, 3.513,
191 3.513, 3.513, 3.503, 3.503, 3.492, 3.492, 3.492, 3.487, 3.481, 3.481, 3.476, 3.471, 3.46, 3.46, 3.449, 3.444, 3.428, 3.428,
192 3.417, 3.401, 3.39, 3.379, 3.363, 3.331, 3.299, 3.267, 3.213, 3.149, 3.041, 3, 3, 0};
193
198
199 /* software OK pin */
201
202 /* AMS CAN messages */
203 BMS_status bms_status_;
204 BMS_temperatures bms_temperatures_;
205 ACU_SHUNT_MEASUREMENTS_t acu_shunt_measurements_;
206 EM_MEASUREMENT_t em_measurements_;
207 BMS_VOLTAGES_t bms_voltages_;
208
209 /* AMS last heartbeat time */
210 unsigned long last_heartbeat_time_;
211
212 /* IIR filter parameters */
219
221
227 bool use_em_for_soc_ = true;
228
233 float charge_;
234
240 float SoC_;
241
245 SysTick_s last_tick_;
246
251
257
261 unsigned long timestamp_start_;
262
263
264 // Check if lowest cell temperature is below threshold
266 // Check if total pack charge is above threshold
268
269};
270
271#endif /* __AMSINTERFACE_H__ */
Circular_Buffer< uint8_t,(uint32_t) 128, sizeof(CAN_message_t)> CANBufferType
this class is for interfacing with the AMS (accumulator management system)
Definition: AMSInterface.h:27
float get_acc_derate_factor()
bool has_initialized_charge_
Definition: AMSInterface.h:250
void enqueue_state_of_charge_CAN()
float cell_voltage_alpha
Definition: AMSInterface.h:218
void tick(const SysTick_s &tick)
float get_SoC()
Definition: AMSInterface.h:113
BMS_VOLTAGES_t bms_voltages_
Definition: AMSInterface.h:207
float acc_derate_factor
Definition: AMSInterface.h:220
float filtered_min_cell_voltage
Definition: AMSInterface.h:216
void retrieve_current_shunt_CAN(const CAN_message_t &can_msg)
void set_heartbeat(unsigned long curr_millis)
SysTick_s last_tick_
Definition: AMSInterface.h:245
BMS_temperatures bms_temperatures_
Definition: AMSInterface.h:204
float get_filtered_min_cell_voltage()
float bms_low_voltage
Definition: AMSInterface.h:214
ACU_SHUNT_MEASUREMENTS_t acu_shunt_measurements_
Definition: AMSInterface.h:205
bool is_below_pack_charge_critical_total_thresh()
void init(SysTick_s &initial_tick)
void retrieve_status_CAN(unsigned long curr_millis, CAN_message_t &recvd_msg)
void retrieve_temp_CAN(CAN_message_t &recvd_msg)
float bms_high_temp
Definition: AMSInterface.h:213
void enqueue_new_CAN(U *structure, uint32_t(*pack_function)(U *, uint8_t *, uint8_t *, uint8_t *))
Definition: AMSInterface.cpp:6
unsigned long last_heartbeat_time_
Definition: AMSInterface.h:210
bool heartbeat_received(unsigned long curr_millis)
void calculate_SoC_acu(const SysTick_s &tick)
bool use_em_for_soc_
Definition: AMSInterface.h:227
float cell_temp_alpha
Definition: AMSInterface.h:217
float get_filtered_max_cell_temp()
unsigned long timestamp_start_
Definition: AMSInterface.h:261
int pin_software_ok_
Definition: AMSInterface.h:200
EM_MEASUREMENT_t get_em_measurements()
Definition: AMSInterface.h:181
void set_state_ok_high(bool ok_high)
bool is_using_em_for_soc()
Definition: AMSInterface.h:160
bool has_received_bms_voltage_
Definition: AMSInterface.h:256
BMS_status bms_status_
Definition: AMSInterface.h:203
BMS_VOLTAGES_t get_bms_voltages()
Definition: AMSInterface.h:180
bool is_below_pack_charge_critical_low_thresh()
void retrieve_voltage_CAN(CAN_message_t &recvd_msg)
EM_MEASUREMENT_t em_measurements_
Definition: AMSInterface.h:206
ACU_SHUNT_MEASUREMENTS_t get_acu_shunt_measurements()
Definition: AMSInterface.h:182
AMSInterface(CANBufferType *msg_output_queue, int sw_ok_pin, float init_temp, float init_volt, float temp_alpha, float volt_alpha)
Definition: AMSInterface.h:34
CANBufferType * msg_queue_
Definition: AMSInterface.h:197
float initialize_charge()
void set_start_state()
float filtered_max_cell_temp
Definition: AMSInterface.h:215
void retrieve_em_measurement_CAN(CAN_message_t &can_msg)
const float VOLTAGE_LOOKUP_TABLE[101]
Definition: AMSInterface.h:187
AMSInterface(CANBufferType *msg_output_queue, int sw_ok_pin)
Definition: AMSInterface.h:48
void set_use_em_for_soc(bool new_use_em_for_soc)
Definition: AMSInterface.h:166
bool pack_charge_is_critical()
void calculate_acc_derate_factor()
void calculate_SoC_em(const SysTick_s &tick)
const float DEFAULT_VOLTAGE_ALPHA
Definition: AMSInterface.h:20
const float DEFAULT_INIT_VOLTAGE
Definition: AMSInterface.h:18
const unsigned long PACK_CHARGE_CRIT_LOWEST_CELL_THRESHOLD
Definition: AMSInterface.h:15
const float DEFAULT_INIT_TEMP
Definition: AMSInterface.h:17
const uint16_t MAX_PACK_CHARGE
Definition: AMSInterface.h:21
const float DEFAULT_TEMP_ALPHA
Definition: AMSInterface.h:19
const unsigned long PACK_CHARGE_CRIT_TOTAL_THRESHOLD
Definition: AMSInterface.h:13
const unsigned long DEFAULT_INITIALIZATION_WAIT_INTERVAL
Definition: AMSInterface.h:22
const unsigned long HEARTBEAT_INTERVAL
Definition: AMSInterface.h:11
const float DEFAULT_VOLTAGE_ALPHA
Definition: AMSInterface.h:21
const float DEFAULT_INIT_VOLTAGE
Definition: AMSInterface.h:19
const float DEFAULT_INIT_TEMP
Definition: AMSInterface.h:18
const float DEFAULT_TEMP_ALPHA
Definition: AMSInterface.h:20