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 "SysClock.h"
5
6#define CANBufferType_mock int
7#define CAN_message_t_mock int
8
9
14const unsigned long HEARTBEAT_INTERVAL = 2000; // milliseconds
15const unsigned long PACK_CHARGE_CRIT_TOTAL_THRESHOLD = 420;
16const unsigned long PACK_CHARGE_CRIT_LOWEST_CELL_THRESHOLD = 35000; //equivalent to 3.5V
17
18const float DEFAULT_INIT_TEMP = 40.0;
19const float DEFAULT_INIT_VOLTAGE = 3.5;
20const float DEFAULT_TEMP_ALPHA = 0.8;
21const float DEFAULT_VOLTAGE_ALPHA = 0.8;
22const unsigned short MAX_PACK_CHARGE = 48600;
23const unsigned long DEFAULT_INITIALIZATION_WAIT_INTERVAL = 5000;
24
25class AMSInterface
26{
27public:
28
29 AMSInterface(CANBufferType_mock *msg_output_queue, int sw_ok_pin, float init_temp, float init_volt, float temp_alpha, float volt_alpha):
30 msg_queue_(msg_output_queue),
31 pin_software_ok_(sw_ok_pin),
32 filtered_max_cell_temp(init_temp),
34 cell_temp_alpha(temp_alpha),
35 cell_voltage_alpha(volt_alpha),
36 use_em_for_soc_(true),
37 charge_(0.0f),
38 SoC_(0.0f),
41
42 AMSInterface(CANBufferType_mock *msg_output_queue, int sw_ok_pin):
44
45
46 void init(SysTick_s &initial_tick) {};
47 void set_start_state() {};
48 bool heartbeat_received(unsigned long curr_millis) {return ((curr_millis - last_heartbeat_time_) < HEARTBEAT_INTERVAL);};
50
51 //SETTERS//
52 void set_state_ok_high(bool ok_high) {};
53 void set_heartbeat(unsigned long curr_millis) {last_heartbeat_time_ = curr_millis;};
54
55 //GETTERS//
59
61 void calculate_SoC_em(const SysTick_s &tick) {};
62 void calculate_SoC_acu(const SysTick_s &tick) {};
63 float get_SoC() {return SoC_;}
64 void tick(const SysTick_s &tick) {};
65
66 void retrieve_status_CAN(unsigned long curr_millis, CAN_message_t_mock &recvd_msg) {};
70
74 void set_use_em_for_soc(bool new_use_em_for_soc) {
75 use_em_for_soc_ = new_use_em_for_soc;
76 }
78
80 //template <typename U>
81 //void enqueue_new_CAN(U *structure, uint32_t (*pack_function)(U *, uint8_t *, uint8_t *, uint8_t *));
82
83 // Getters (for testing purposes)
84 //BMS_VOLTAGES_t get_bms_voltages() {return bms_voltages_;}
85 //EM_MEASUREMENT_t get_em_measurements() {return em_measurements_;}
86 //ACU_SHUNT_MEASUREMENTS_t get_acu_shunt_measurements() {return acu_shunt_measurements_;}
87
88
89private:
90
91 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,
92 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,
93 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,
94 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,
95 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,
96 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};
97
99
100 /* software OK pin */
102
103 /* AMS CAN messages */
104 //BMS_status bms_status_;
105 //BMS_temperatures bms_temperatures_;
106 //ACU_SHUNT_MEASUREMENTS_t acu_shunt_measurements_;
107 //EM_MEASUREMENT_t em_measurements_;
108 //BMS_VOLTAGES_t bms_voltages_;
109
110 /* AMS last heartbeat time */
111 unsigned long last_heartbeat_time_;
112
113 /* IIR filter parameters */
114 float bms_high_temp;
115 float bms_low_voltage;
118 float cell_temp_alpha;
119 float cell_voltage_alpha;
120
121 float acc_derate_factor;
122 bool use_em_for_soc_ = true;
123 float charge_;
124 float SoC_;
125 SysTick_s last_tick_;
128 unsigned long timestamp_start_;
129
132
133};
134
135#endif /* __AMSINTERFACE_H__ */
this class is for interfacing with the AMS (accumulator management system)
Definition: AMSInterface.h:27
float get_acc_derate_factor()
Definition: AMSInterface.h:58
bool has_initialized_charge_
Definition: AMSInterface.h:250
void enqueue_state_of_charge_CAN()
Definition: AMSInterface.h:77
float cell_voltage_alpha
Definition: AMSInterface.h:218
void tick(const SysTick_s &tick)
float get_SoC()
Definition: AMSInterface.h:63
float acc_derate_factor
Definition: AMSInterface.h:220
float filtered_min_cell_voltage
Definition: AMSInterface.h:216
void set_heartbeat(unsigned long curr_millis)
Definition: AMSInterface.h:53
SysTick_s last_tick_
Definition: AMSInterface.h:245
void retrieve_current_shunt_CAN(const CAN_message_t_mock &can_msg)
Definition: AMSInterface.h:72
float get_filtered_min_cell_voltage()
Definition: AMSInterface.h:57
float bms_low_voltage
Definition: AMSInterface.h:214
void retrieve_status_CAN(unsigned long curr_millis, CAN_message_t_mock &recvd_msg)
Definition: AMSInterface.h:66
bool is_below_pack_charge_critical_total_thresh()
void init(SysTick_s &initial_tick)
Definition: AMSInterface.h:46
float bms_high_temp
Definition: AMSInterface.h:213
AMSInterface(CANBufferType_mock *msg_output_queue, int sw_ok_pin)
Definition: AMSInterface.h:42
void retrieve_temp_CAN(CAN_message_t_mock &recvd_msg)
Definition: AMSInterface.h:67
unsigned long last_heartbeat_time_
Definition: AMSInterface.h:210
bool heartbeat_received(unsigned long curr_millis)
Definition: AMSInterface.h:48
void calculate_SoC_acu(const SysTick_s &tick)
Definition: AMSInterface.h:62
bool use_em_for_soc_
Definition: AMSInterface.h:227
float cell_temp_alpha
Definition: AMSInterface.h:217
float get_filtered_max_cell_temp()
Definition: AMSInterface.h:56
unsigned long timestamp_start_
Definition: AMSInterface.h:261
int pin_software_ok_
Definition: AMSInterface.h:200
void set_state_ok_high(bool ok_high)
Definition: AMSInterface.h:52
CANBufferType_mock * msg_queue_
Definition: AMSInterface.h:98
bool is_using_em_for_soc()
Definition: AMSInterface.h:73
bool has_received_bms_voltage_
Definition: AMSInterface.h:256
bool is_below_pack_charge_critical_low_thresh()
AMSInterface(CANBufferType_mock *msg_output_queue, int sw_ok_pin, float init_temp, float init_volt, float temp_alpha, float volt_alpha)
Definition: AMSInterface.h:29
void retrieve_voltage_CAN(CAN_message_t_mock &recvd_msg)
Definition: AMSInterface.h:68
void retrieve_em_measurement_CAN(CAN_message_t_mock &can_msg)
Definition: AMSInterface.h:71
CANBufferType * msg_queue_
Definition: AMSInterface.h:197
float initialize_charge()
Definition: AMSInterface.h:60
void set_start_state()
Definition: AMSInterface.h:47
float filtered_max_cell_temp
Definition: AMSInterface.h:215
const float VOLTAGE_LOOKUP_TABLE[101]
Definition: AMSInterface.h:187
void set_use_em_for_soc(bool new_use_em_for_soc)
Definition: AMSInterface.h:74
bool pack_charge_is_critical()
Definition: AMSInterface.h:49
void calculate_acc_derate_factor()
Definition: AMSInterface.h:69
void calculate_SoC_em(const SysTick_s &tick)
Definition: AMSInterface.h:61
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
#define CAN_message_t_mock
Definition: AMSInterface.h:7
const float DEFAULT_INIT_TEMP
Definition: AMSInterface.h:18
const float DEFAULT_TEMP_ALPHA
Definition: AMSInterface.h:20
const unsigned long HEARTBEAT_INTERVAL
Definition: AMSInterface.h:14
#define CANBufferType_mock
Definition: AMSInterface.h:6