MCU
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Private Attributes | List of all members
AMSInterface Class Reference

this class is for interfacing with the AMS (accumulator management system) More...

#include <AMSInterface.h>

Collaboration diagram for AMSInterface:
Collaboration graph

Public Member Functions

 AMSInterface (CANBufferType *msg_output_queue, int sw_ok_pin, float init_temp, float init_volt, float temp_alpha, float volt_alpha)
 
 AMSInterface (CANBufferType *msg_output_queue, int sw_ok_pin)
 
void init (SysTick_s &initial_tick)
 
void set_start_state ()
 
bool heartbeat_received (unsigned long curr_millis)
 
bool pack_charge_is_critical ()
 
void set_state_ok_high (bool ok_high)
 
void set_heartbeat (unsigned long curr_millis)
 
float get_filtered_max_cell_temp ()
 
float get_filtered_min_cell_voltage ()
 
float get_acc_derate_factor ()
 
float initialize_charge ()
 
void calculate_SoC_em (const SysTick_s &tick)
 
void calculate_SoC_acu (const SysTick_s &tick)
 
float get_SoC ()
 
void tick (const SysTick_s &tick)
 
void retrieve_status_CAN (unsigned long curr_millis, CAN_message_t &recvd_msg)
 
void retrieve_temp_CAN (CAN_message_t &recvd_msg)
 
void retrieve_voltage_CAN (CAN_message_t &recvd_msg)
 
void calculate_acc_derate_factor ()
 
void retrieve_em_measurement_CAN (CAN_message_t &can_msg)
 
void retrieve_current_shunt_CAN (const CAN_message_t &can_msg)
 
bool is_using_em_for_soc ()
 
void set_use_em_for_soc (bool new_use_em_for_soc)
 
void enqueue_state_of_charge_CAN ()
 
template<typename U >
void enqueue_new_CAN (U *structure, uint32_t(*pack_function)(U *, uint8_t *, uint8_t *, uint8_t *))
 
BMS_VOLTAGES_t get_bms_voltages ()
 
EM_MEASUREMENT_t get_em_measurements ()
 
ACU_SHUNT_MEASUREMENTS_t get_acu_shunt_measurements ()
 
 AMSInterface (CANBufferType_mock *msg_output_queue, int sw_ok_pin, float init_temp, float init_volt, float temp_alpha, float volt_alpha)
 
 AMSInterface (CANBufferType_mock *msg_output_queue, int sw_ok_pin)
 
void init (SysTick_s &initial_tick)
 
void set_start_state ()
 
bool heartbeat_received (unsigned long curr_millis)
 
bool pack_charge_is_critical ()
 
void set_state_ok_high (bool ok_high)
 
void set_heartbeat (unsigned long curr_millis)
 
float get_filtered_max_cell_temp ()
 
float get_filtered_min_cell_voltage ()
 
float get_acc_derate_factor ()
 
float initialize_charge ()
 
void calculate_SoC_em (const SysTick_s &tick)
 
void calculate_SoC_acu (const SysTick_s &tick)
 
float get_SoC ()
 
void tick (const SysTick_s &tick)
 
void retrieve_status_CAN (unsigned long curr_millis, CAN_message_t_mock &recvd_msg)
 
void retrieve_temp_CAN (CAN_message_t_mock &recvd_msg)
 
void retrieve_voltage_CAN (CAN_message_t_mock &recvd_msg)
 
void calculate_acc_derate_factor ()
 
void retrieve_em_measurement_CAN (CAN_message_t_mock &can_msg)
 
void retrieve_current_shunt_CAN (const CAN_message_t_mock &can_msg)
 
bool is_using_em_for_soc ()
 
void set_use_em_for_soc (bool new_use_em_for_soc)
 
void enqueue_state_of_charge_CAN ()
 

Private Member Functions

bool is_below_pack_charge_critical_low_thresh ()
 
bool is_below_pack_charge_critical_total_thresh ()
 
bool is_below_pack_charge_critical_low_thresh ()
 
bool is_below_pack_charge_critical_total_thresh ()
 

Private Attributes

const float VOLTAGE_LOOKUP_TABLE [101]
 
CANBufferTypemsg_queue_
 
int pin_software_ok_
 
BMS_status bms_status_
 
BMS_temperatures bms_temperatures_
 
ACU_SHUNT_MEASUREMENTS_t acu_shunt_measurements_
 
EM_MEASUREMENT_t em_measurements_
 
BMS_VOLTAGES_t bms_voltages_
 
unsigned long last_heartbeat_time_
 
float bms_high_temp
 
float bms_low_voltage
 
float filtered_max_cell_temp
 
float filtered_min_cell_voltage
 
float cell_temp_alpha
 
float cell_voltage_alpha
 
float acc_derate_factor
 
bool use_em_for_soc_ = true
 
float charge_
 
float SoC_
 
SysTick_s last_tick_
 
bool has_initialized_charge_
 
bool has_received_bms_voltage_
 
unsigned long timestamp_start_
 
CANBufferType_mockmsg_queue_
 

Detailed Description

this class is for interfacing with the AMS (accumulator management system)

Definition at line 26 of file AMSInterface.h.

Constructor & Destructor Documentation

◆ AMSInterface() [1/4]

AMSInterface::AMSInterface ( CANBufferType msg_output_queue,
int  sw_ok_pin,
float  init_temp,
float  init_volt,
float  temp_alpha,
float  volt_alpha 
)
inline

Constructor for the AMS Interface

Parameters
sw_ok_pinThe software ok pin number. This pin is connected to the shutdown line and will go low if the AMS times out

Definition at line 34 of file AMSInterface.h.

34 :
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),
bool has_initialized_charge_
Definition: AMSInterface.h:250
float cell_voltage_alpha
Definition: AMSInterface.h:218
float filtered_min_cell_voltage
Definition: AMSInterface.h:216
bool use_em_for_soc_
Definition: AMSInterface.h:227
float cell_temp_alpha
Definition: AMSInterface.h:217
int pin_software_ok_
Definition: AMSInterface.h:200
bool has_received_bms_voltage_
Definition: AMSInterface.h:256
CANBufferType * msg_queue_
Definition: AMSInterface.h:197
float filtered_max_cell_temp
Definition: AMSInterface.h:215

◆ AMSInterface() [2/4]

AMSInterface::AMSInterface ( CANBufferType msg_output_queue,
int  sw_ok_pin 
)
inline

Definition at line 48 of file AMSInterface.h.

48 :
this class is for interfacing with the AMS (accumulator management system)
Definition: AMSInterface.h:27
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

◆ AMSInterface() [3/4]

AMSInterface::AMSInterface ( CANBufferType_mock msg_output_queue,
int  sw_ok_pin,
float  init_temp,
float  init_volt,
float  temp_alpha,
float  volt_alpha 
)
inline

Definition at line 29 of file AMSInterface.h.

29 :
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),

◆ AMSInterface() [4/4]

AMSInterface::AMSInterface ( CANBufferType_mock msg_output_queue,
int  sw_ok_pin 
)
inline

Definition at line 42 of file AMSInterface.h.

Member Function Documentation

◆ calculate_acc_derate_factor() [1/2]

void AMSInterface::calculate_acc_derate_factor ( )

Definition at line 180 of file AMSInterface.cpp.

180 {
181 float voltage_lim_factor = 1.0;
182 float startDerateVoltage = 3.5;
183 float endDerateVoltage = 3.2;
184 float voltage_lim_max = 1;
185 float voltage_lim_min = 0.2;
186
187 float temp_lim_factor = 1.0;
188 float startDerateTemp = 50;
189 float stopDerateTemp = 58;
190 float temp_lim_max = 1;
191 float temp_lim_min = 0.2;
192
194 //float_map equivalient because new code is bad
195 voltage_lim_factor = (filtered_min_cell_voltage - startDerateVoltage) * (voltage_lim_min - voltage_lim_max) / (endDerateVoltage - startDerateVoltage) + voltage_lim_max;
196 voltage_lim_factor = max(min(voltage_lim_max, voltage_lim_factor), voltage_lim_min);
197
198 temp_lim_factor = (filtered_max_cell_temp - startDerateTemp) * (temp_lim_min - temp_lim_max) / (stopDerateTemp - startDerateTemp) + temp_lim_max;
199 temp_lim_factor = max(min(temp_lim_factor, temp_lim_max), temp_lim_min);
200
201 acc_derate_factor = min(temp_lim_factor,voltage_lim_factor);
202}
float acc_derate_factor
Definition: AMSInterface.h:220
float get_filtered_min_cell_voltage()

◆ calculate_acc_derate_factor() [2/2]

void AMSInterface::calculate_acc_derate_factor ( )
inline

Definition at line 69 of file AMSInterface.h.

69{};

◆ calculate_SoC_acu() [1/2]

void AMSInterface::calculate_SoC_acu ( const SysTick_s &  tick)

Calculates SoC based on the ACU_SHUNT_MEASUREMENTS CAN message. Calling calculate_SoC_acu() will update the SoC_ and charge_ member variables.

Parameters
Thecurrent tick that the calculate_SoC_em function should use for integration.
Precondition
The last_tick_ member variable must be updated correctly.
Postcondition
The charge_ field has the updated charge, and the SoC field contains an updated percentage.

Definition at line 103 of file AMSInterface.cpp.

103 {
104 unsigned long delta_time_micros = tick.micros - last_tick_.micros;
105
106 // Converts analog read (from 0 to 4095) into some value (0.0 to 3.3)
107 // float current = HYTECH_current_shunt_read_ro_fromS(acu_shunt_measurements_.current_shunt_read_ro);
108
109 // shunt_voltage ranges from -3.33 to 2.635
110 // float shunt_voltage = (current * (9.22 / 5.1)) - 3.3 - 0.03;
111
112 // calc_current ranges from -666 to 527.176
113 // float calc_current = (shunt_voltage / 0.005);
114 charge_ -= (HYTECH_current_shunt_read_ro_fromS(acu_shunt_measurements_.current_shunt_read_ro) * delta_time_micros) / 1000000;
115
116 SoC_ = (charge_ / MAX_PACK_CHARGE) * 100;
117}
void tick(const SysTick_s &tick)
SysTick_s last_tick_
Definition: AMSInterface.h:245
ACU_SHUNT_MEASUREMENTS_t acu_shunt_measurements_
Definition: AMSInterface.h:205
const unsigned short MAX_PACK_CHARGE
Definition: AMSInterface.h:22

◆ calculate_SoC_acu() [2/2]

void AMSInterface::calculate_SoC_acu ( const SysTick_s &  tick)
inline

Definition at line 62 of file AMSInterface.h.

62{};

◆ calculate_SoC_em() [1/2]

void AMSInterface::calculate_SoC_em ( const SysTick_s &  tick)

Calculates SoC based on the energy meter CAN message. Calling calculate_SoC_em() will update the SoC_ and charge_ member variables.

Parameters
Thecurrent tick that the calculate_SoC_em function should use for integration.
Precondition
The last_tick_ member variable must be updated correctly.
Postcondition
The charge_ field has the updated charge, and the SoC field contains an updated percentage.

Definition at line 92 of file AMSInterface.cpp.

92 {
93 unsigned long delta_time_micros = tick.micros - last_tick_.micros;
94
95 float current = HYTECH_em_current_ro_fromS(em_measurements_.em_current_ro); // Current in amps
96
97 // coulombs = amps * microseconds * (1sec / 1000000 microsec)
98 charge_ -= (current * delta_time_micros) / 1000000;
99
100 SoC_ = (charge_ / MAX_PACK_CHARGE) * 100;
101}
EM_MEASUREMENT_t em_measurements_
Definition: AMSInterface.h:206

◆ calculate_SoC_em() [2/2]

void AMSInterface::calculate_SoC_em ( const SysTick_s &  tick)
inline

Definition at line 61 of file AMSInterface.h.

61{};

◆ enqueue_new_CAN()

template<typename U >
void AMSInterface::enqueue_new_CAN ( U *  structure,
uint32_t(*)(U *, uint8_t *, uint8_t *, uint8_t *)  pack_function 
)

Helper function to enqueue CAN messages using the new CAN library

Definition at line 6 of file AMSInterface.cpp.

6 {
7 CAN_message_t can_msg;
8 can_msg.id = pack_function(structure, can_msg.buf, &can_msg.len, (uint8_t*) &can_msg.flags.extended);
9 uint8_t buf[sizeof(CAN_message_t)] = {};
10 memmove(buf, &can_msg, sizeof(CAN_message_t));
11 msg_queue_->push_back(buf, sizeof(CAN_message_t));
12}

◆ enqueue_state_of_charge_CAN() [1/2]

void AMSInterface::enqueue_state_of_charge_CAN ( )

Puts the current value of SoC_ and charge_ onto msg_queue_.

◆ enqueue_state_of_charge_CAN() [2/2]

void AMSInterface::enqueue_state_of_charge_CAN ( )
inline

Definition at line 77 of file AMSInterface.h.

77{};

◆ get_acc_derate_factor() [1/2]

float AMSInterface::get_acc_derate_factor ( )

Definition at line 204 of file AMSInterface.cpp.

204 {
206 return acc_derate_factor;
207}
void calculate_acc_derate_factor()

◆ get_acc_derate_factor() [2/2]

float AMSInterface::get_acc_derate_factor ( )
inline

Definition at line 58 of file AMSInterface.h.

58{};

◆ get_acu_shunt_measurements()

ACU_SHUNT_MEASUREMENTS_t AMSInterface::get_acu_shunt_measurements ( )
inline

Definition at line 182 of file AMSInterface.h.

◆ get_bms_voltages()

BMS_VOLTAGES_t AMSInterface::get_bms_voltages ( )
inline

Definition at line 180 of file AMSInterface.h.

180{return bms_voltages_;}
BMS_VOLTAGES_t bms_voltages_
Definition: AMSInterface.h:207

◆ get_em_measurements()

EM_MEASUREMENT_t AMSInterface::get_em_measurements ( )
inline

Definition at line 181 of file AMSInterface.h.

181{return em_measurements_;}

◆ get_filtered_max_cell_temp() [1/2]

float AMSInterface::get_filtered_max_cell_temp ( )

Definition at line 67 of file AMSInterface.cpp.

67 {
68 bms_high_temp = bms_temperatures_.get_high_temperature() / 100.0;
71}
BMS_temperatures bms_temperatures_
Definition: AMSInterface.h:204
float bms_high_temp
Definition: AMSInterface.h:213

◆ get_filtered_max_cell_temp() [2/2]

float AMSInterface::get_filtered_max_cell_temp ( )
inline

Definition at line 56 of file AMSInterface.h.

56{};

◆ get_filtered_min_cell_voltage() [1/2]

float AMSInterface::get_filtered_min_cell_voltage ( )

Definition at line 73 of file AMSInterface.cpp.

73 {
74 bms_low_voltage = HYTECH_low_voltage_ro_fromS(bms_voltages_.low_voltage_ro);
77}
float bms_low_voltage
Definition: AMSInterface.h:214

◆ get_filtered_min_cell_voltage() [2/2]

float AMSInterface::get_filtered_min_cell_voltage ( )
inline

Definition at line 57 of file AMSInterface.h.

57{};

◆ get_SoC() [1/2]

float AMSInterface::get_SoC ( )
inline

Retrieves the value of the SoC member variable. This function does NOT recalculate the SoC_ variable, it only returns the value that is stored.

Returns
the current value stored in the SoC_ member variable.

Definition at line 113 of file AMSInterface.h.

113{return SoC_;}

◆ get_SoC() [2/2]

float AMSInterface::get_SoC ( )
inline

Definition at line 63 of file AMSInterface.h.

63{return SoC_;}

◆ heartbeat_received() [1/2]

bool AMSInterface::heartbeat_received ( unsigned long  curr_millis)

Definition at line 50 of file AMSInterface.cpp.

50 {
51 return ((curr_millis - last_heartbeat_time_) < HEARTBEAT_INTERVAL);
52}
unsigned long last_heartbeat_time_
Definition: AMSInterface.h:210
const unsigned long HEARTBEAT_INTERVAL
Definition: AMSInterface.h:14

◆ heartbeat_received() [2/2]

bool AMSInterface::heartbeat_received ( unsigned long  curr_millis)
inline

Definition at line 48 of file AMSInterface.h.

48{return ((curr_millis - last_heartbeat_time_) < HEARTBEAT_INTERVAL);};

◆ init() [1/2]

void AMSInterface::init ( SysTick_s &  initial_tick)

Definition at line 14 of file AMSInterface.cpp.

14 {
15
16 // Set pin mode
17 pinMode(pin_software_ok_, OUTPUT);
18
19 set_heartbeat(initial_tick.millis);
20
21 last_tick_ = initial_tick;
22
23 timestamp_start_ = -1; //starts at -1
24
25 // Initializes the bms_voltages_ member variable to an invalid state. This will
26 // get overridden once retrieve_voltage_CAN() has been called at least once.
27 bms_voltages_.low_voltage_ro = 0xFFFFU;
28 bms_voltages_.high_voltage_ro = 0x1111U;
29
30}
void set_heartbeat(unsigned long curr_millis)
unsigned long timestamp_start_
Definition: AMSInterface.h:261

◆ init() [2/2]

void AMSInterface::init ( SysTick_s &  initial_tick)
inline

Definition at line 46 of file AMSInterface.h.

46{};

◆ initialize_charge() [1/2]

float AMSInterface::initialize_charge ( )

Initializes the charge member variable from the voltage of the minimum cell using the VOLTAGE_LOOKUP_TABLE.

Precondition
The bms_voltages_ member variable MUST be initialized before this function can be called.
Returns
The charge, in coulombs, that the charge member variable is initialized to.

Definition at line 79 of file AMSInterface.cpp.

79 {
80 int i = 0;
81 float lowest_voltage = HYTECH_low_voltage_ro_fromS(bms_voltages_.low_voltage_ro);
82
83 while (lowest_voltage - VOLTAGE_LOOKUP_TABLE[i] < 0) {
84 i++;
85 }
86 charge_ = ( (100 - i) / 100.0) * MAX_PACK_CHARGE;
87 SoC_ = (charge_ / MAX_PACK_CHARGE) * 100;
88
89 return charge_;
90}
const float VOLTAGE_LOOKUP_TABLE[101]
Definition: AMSInterface.h:187

◆ initialize_charge() [2/2]

float AMSInterface::initialize_charge ( )
inline

Definition at line 60 of file AMSInterface.h.

60{};

◆ is_below_pack_charge_critical_low_thresh() [1/2]

bool AMSInterface::is_below_pack_charge_critical_low_thresh ( )
private

Definition at line 54 of file AMSInterface.cpp.

54 {
55 return (HYTECH_low_voltage_ro_fromS(bms_voltages_.low_voltage_ro) < PACK_CHARGE_CRIT_LOWEST_CELL_THRESHOLD);
56}
const unsigned long PACK_CHARGE_CRIT_LOWEST_CELL_THRESHOLD
Definition: AMSInterface.h:16

◆ is_below_pack_charge_critical_low_thresh() [2/2]

bool AMSInterface::is_below_pack_charge_critical_low_thresh ( )
private

◆ is_below_pack_charge_critical_total_thresh() [1/2]

bool AMSInterface::is_below_pack_charge_critical_total_thresh ( )
private

Definition at line 58 of file AMSInterface.cpp.

58 {
59 return (HYTECH_total_voltage_ro_fromS(bms_voltages_.total_voltage_ro) < PACK_CHARGE_CRIT_TOTAL_THRESHOLD);
60}
const unsigned long PACK_CHARGE_CRIT_TOTAL_THRESHOLD
Definition: AMSInterface.h:15

◆ is_below_pack_charge_critical_total_thresh() [2/2]

bool AMSInterface::is_below_pack_charge_critical_total_thresh ( )
private

◆ is_using_em_for_soc() [1/2]

bool AMSInterface::is_using_em_for_soc ( )
inline

Retrieves the current state of the use_em_for_soc member variable.

Returns
True if using EM, false if using ACU shunt measurements.

Definition at line 160 of file AMSInterface.h.

160{return use_em_for_soc_;}

◆ is_using_em_for_soc() [2/2]

bool AMSInterface::is_using_em_for_soc ( )
inline

Definition at line 73 of file AMSInterface.h.

73{return use_em_for_soc_;}

◆ pack_charge_is_critical() [1/2]

bool AMSInterface::pack_charge_is_critical ( )

Definition at line 62 of file AMSInterface.cpp.

62 {
64}
bool is_below_pack_charge_critical_total_thresh()
bool is_below_pack_charge_critical_low_thresh()

◆ pack_charge_is_critical() [2/2]

bool AMSInterface::pack_charge_is_critical ( )
inline

Definition at line 49 of file AMSInterface.h.

49{};

◆ retrieve_current_shunt_CAN() [1/2]

void AMSInterface::retrieve_current_shunt_CAN ( const CAN_message_t &  can_msg)

Reads this CAN message into the acu_shunt_measurements_ member variable. This function does NOT apply the fromS() functions on the data. This function uses the NEW CAN library.

Definition at line 176 of file AMSInterface.cpp.

176 {
177 Unpack_ACU_SHUNT_MEASUREMENTS_hytech(&acu_shunt_measurements_, can_msg.buf, can_msg.len);
178}

◆ retrieve_current_shunt_CAN() [2/2]

void AMSInterface::retrieve_current_shunt_CAN ( const CAN_message_t_mock can_msg)
inline

Definition at line 72 of file AMSInterface.h.

72{};

◆ retrieve_em_measurement_CAN() [1/2]

void AMSInterface::retrieve_em_measurement_CAN ( CAN_message_t &  can_msg)

Reads this CAN message into the em_measurements_ member variable. This function does NOT apply the fromS() functions on the data. This function uses the NEW CAN library.

Definition at line 172 of file AMSInterface.cpp.

172 {
173 Unpack_EM_MEASUREMENT_hytech(&em_measurements_, can_msg.buf, can_msg.len);
174}

◆ retrieve_em_measurement_CAN() [2/2]

void AMSInterface::retrieve_em_measurement_CAN ( CAN_message_t_mock can_msg)
inline

Definition at line 71 of file AMSInterface.h.

71{};

◆ retrieve_status_CAN() [1/2]

void AMSInterface::retrieve_status_CAN ( unsigned long  curr_millis,
CAN_message_t &  recvd_msg 
)

Reads this CAN message into the bms_status_ member variable. This function uses the OLD CAN library.

Definition at line 152 of file AMSInterface.cpp.

152 {
153 bms_status_.load(recvd_msg.buf);
154 set_heartbeat(curr_millis);
155}
BMS_status bms_status_
Definition: AMSInterface.h:203

◆ retrieve_status_CAN() [2/2]

void AMSInterface::retrieve_status_CAN ( unsigned long  curr_millis,
CAN_message_t_mock recvd_msg 
)
inline

Definition at line 66 of file AMSInterface.h.

66{};

◆ retrieve_temp_CAN() [1/2]

void AMSInterface::retrieve_temp_CAN ( CAN_message_t &  recvd_msg)

Reads this CAN message into the bms_temperatures_ member variable. This function uses the OLD CAN library.

Definition at line 157 of file AMSInterface.cpp.

157 {
158 bms_temperatures_.load(recvd_msg.buf);
159}

◆ retrieve_temp_CAN() [2/2]

void AMSInterface::retrieve_temp_CAN ( CAN_message_t_mock recvd_msg)
inline

Definition at line 67 of file AMSInterface.h.

67{};

◆ retrieve_voltage_CAN() [1/2]

void AMSInterface::retrieve_voltage_CAN ( CAN_message_t &  recvd_msg)

Reads this CAN message into the bms_voltages_ member variable. This function does NOT apply the fromS() functions on the data. This function uses the NEW CAN library.

Definition at line 161 of file AMSInterface.cpp.

161 {
162 Unpack_BMS_VOLTAGES_hytech(&bms_voltages_, can_msg.buf, can_msg.len);
163
165 {
168 }
169
170}

◆ retrieve_voltage_CAN() [2/2]

void AMSInterface::retrieve_voltage_CAN ( CAN_message_t_mock recvd_msg)
inline

Definition at line 68 of file AMSInterface.h.

68{};

◆ set_heartbeat() [1/2]

void AMSInterface::set_heartbeat ( unsigned long  curr_millis)

Definition at line 46 of file AMSInterface.cpp.

46 {
47 last_heartbeat_time_ = curr_millis;
48}

◆ set_heartbeat() [2/2]

void AMSInterface::set_heartbeat ( unsigned long  curr_millis)
inline

Definition at line 53 of file AMSInterface.h.

53{last_heartbeat_time_ = curr_millis;};

◆ set_start_state() [1/2]

void AMSInterface::set_start_state ( )

Definition at line 32 of file AMSInterface.cpp.

32 {
33
34 digitalWrite(pin_software_ok_, HIGH);
35
36}

◆ set_start_state() [2/2]

void AMSInterface::set_start_state ( )
inline

Definition at line 47 of file AMSInterface.h.

47{};

◆ set_state_ok_high() [1/2]

void AMSInterface::set_state_ok_high ( bool  ok_high)

Definition at line 39 of file AMSInterface.cpp.

39 {
40 if (ok_high)
41 digitalWrite(pin_software_ok_, HIGH);
42 else
43 digitalWrite(pin_software_ok_, LOW);
44}

◆ set_state_ok_high() [2/2]

void AMSInterface::set_state_ok_high ( bool  ok_high)
inline

Definition at line 52 of file AMSInterface.h.

52{};

◆ set_use_em_for_soc() [1/2]

void AMSInterface::set_use_em_for_soc ( bool  new_use_em_for_soc)
inline

Setter function for the use_em_for_soc_ member variable.

Parameters
new_use_em_for_socThe new value for the variable.

Definition at line 166 of file AMSInterface.h.

166 {
167 use_em_for_soc_ = new_use_em_for_soc;
168 }

◆ set_use_em_for_soc() [2/2]

void AMSInterface::set_use_em_for_soc ( bool  new_use_em_for_soc)
inline

Definition at line 74 of file AMSInterface.h.

74 {
75 use_em_for_soc_ = new_use_em_for_soc;
76 }

◆ tick() [1/2]

void AMSInterface::tick ( const SysTick_s &  tick)

This is AMSInterface's tick() function. It behaves correctly regardless of the since the functions calculate the elapsed time between the given tick and the stored last_tick_.

Parameters
tickThe current system tick.

Definition at line 119 of file AMSInterface.cpp.

119 {
120
121 // Only calculate the updated SoC if charge has been properly initialized.
123 // Do not edit this block! If both calculate_SoC_em AND calculate_SoC_acu are run,
124 // then the charge will be subtracted from the SoC member variable twice.
125 if (use_em_for_soc_) {
127 } else {
129 }
130 }
131
132 // If AMSInterface has a valid reading in bms_voltages_ and enough time has passed since init(), then initialize charge
134
137
138 }
139
140 // Send CAN message
141 // enqueue_state_of_charge_CAN();
142 STATE_OF_CHARGE_t soc_struct;
143 soc_struct.charge_percentage_ro = HYTECH_charge_percentage_ro_toS(SoC_);
144 soc_struct.charge_coulombs_ro = HYTECH_charge_coulombs_ro_toS(charge_);
145 soc_struct.min_cell_voltage_est_ro = HYTECH_min_cell_voltage_est_ro_toS(VOLTAGE_LOOKUP_TABLE[100 - (int) SoC_]);
146 enqueue_new_CAN<STATE_OF_CHARGE_t>(&soc_struct, Pack_STATE_OF_CHARGE_hytech);
147
149}
void calculate_SoC_acu(const SysTick_s &tick)
float initialize_charge()
void calculate_SoC_em(const SysTick_s &tick)
const unsigned long DEFAULT_INITIALIZATION_WAIT_INTERVAL
Definition: AMSInterface.h:23

◆ tick() [2/2]

void AMSInterface::tick ( const SysTick_s &  tick)
inline

Definition at line 64 of file AMSInterface.h.

64{};

Member Data Documentation

◆ acc_derate_factor

float AMSInterface::acc_derate_factor
private

Definition at line 220 of file AMSInterface.h.

◆ acu_shunt_measurements_

ACU_SHUNT_MEASUREMENTS_t AMSInterface::acu_shunt_measurements_
private

Definition at line 205 of file AMSInterface.h.

◆ bms_high_temp

float AMSInterface::bms_high_temp
private

Definition at line 213 of file AMSInterface.h.

◆ bms_low_voltage

float AMSInterface::bms_low_voltage
private

Definition at line 214 of file AMSInterface.h.

◆ bms_status_

BMS_status AMSInterface::bms_status_
private

Definition at line 203 of file AMSInterface.h.

◆ bms_temperatures_

BMS_temperatures AMSInterface::bms_temperatures_
private

Definition at line 204 of file AMSInterface.h.

◆ bms_voltages_

BMS_VOLTAGES_t AMSInterface::bms_voltages_
private

Definition at line 207 of file AMSInterface.h.

◆ cell_temp_alpha

float AMSInterface::cell_temp_alpha
private

Definition at line 217 of file AMSInterface.h.

◆ cell_voltage_alpha

float AMSInterface::cell_voltage_alpha
private

Definition at line 218 of file AMSInterface.h.

◆ charge_

float AMSInterface::charge_
private

The charge stored on the accumulator. Stored in coulombs, ranging from zero to MAX_PACK_CHARGE.

Definition at line 233 of file AMSInterface.h.

◆ em_measurements_

EM_MEASUREMENT_t AMSInterface::em_measurements_
private

Definition at line 206 of file AMSInterface.h.

◆ filtered_max_cell_temp

float AMSInterface::filtered_max_cell_temp
private

Definition at line 215 of file AMSInterface.h.

◆ filtered_min_cell_voltage

float AMSInterface::filtered_min_cell_voltage
private

Definition at line 216 of file AMSInterface.h.

◆ has_initialized_charge_

bool AMSInterface::has_initialized_charge_
private

Stores whether or not this AMSInterface has initialized SoC_ or not.

Definition at line 250 of file AMSInterface.h.

◆ has_received_bms_voltage_

bool AMSInterface::has_received_bms_voltage_
private

Stores whether or not this AMSInterface has properly received a bms_voltage CAN message.

Definition at line 256 of file AMSInterface.h.

◆ last_heartbeat_time_

unsigned long AMSInterface::last_heartbeat_time_
private

Definition at line 210 of file AMSInterface.h.

◆ last_tick_

SysTick_s AMSInterface::last_tick_
private

Stores the last Sys_Tick_s struct from the last time the tick() function is called.

Definition at line 245 of file AMSInterface.h.

◆ msg_queue_ [1/2]

CANBufferType* AMSInterface::msg_queue_
private

CAN line that this AMSInterface should write to. This should be the Telemetry CAN line.

Definition at line 197 of file AMSInterface.h.

◆ msg_queue_ [2/2]

CANBufferType_mock* AMSInterface::msg_queue_
private

Definition at line 98 of file AMSInterface.h.

◆ pin_software_ok_

int AMSInterface::pin_software_ok_
private

Definition at line 200 of file AMSInterface.h.

◆ SoC_

float AMSInterface::SoC_
private

Stores the current state of charge of the accumulator. SoC is stored as a percentage of MAX_PACK_CHARGE. In every location, this is calculated as SoC = (charge / MAX_PACK_CHARGE) * 100;

Definition at line 240 of file AMSInterface.h.

◆ timestamp_start_

unsigned long AMSInterface::timestamp_start_
private

Stores the time, in milliseconds, when this AMSInterface first received a bms voltages CAN message.

Definition at line 261 of file AMSInterface.h.

◆ use_em_for_soc_

bool AMSInterface::use_em_for_soc_ = true
private

If set to TRUE, then SoC will use EM. If set to FALSE, then SoC will use ACU SHUNT. Set to TRUE in constructor by default.

Definition at line 227 of file AMSInterface.h.

◆ VOLTAGE_LOOKUP_TABLE

const float AMSInterface::VOLTAGE_LOOKUP_TABLE
private
Initial value:
= {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,
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,
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,
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,
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,
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}

Helper function to enqueue CAN messages using the new CAN library

Definition at line 187 of file AMSInterface.h.


The documentation for this class was generated from the following files: