diff --git a/AMSInterface_8cpp_source.html b/AMSInterface_8cpp_source.html index 861fba701..f27fab378 100644 --- a/AMSInterface_8cpp_source.html +++ b/AMSInterface_8cpp_source.html @@ -98,7 +98,7 @@
20
21 last_tick_ = initial_tick;
22
-
23 timestamp_start_ = last_tick_.millis;
+
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.
@@ -156,93 +156,93 @@
78
79float AMSInterface::initialize_charge() {
80 int i = 0;
-
81 while (HYTECH_low_voltage_ro_fromS(bms_voltages_.low_voltage_ro) - VOLTAGE_LOOKUP_TABLE[i] < 0) {
-
82 i++;
-
83 }
-
84 charge_ = ( (100 - i) / 100.0) * MAX_PACK_CHARGE;
-
85 SoC_ = (charge_ / MAX_PACK_CHARGE) * 100;
-
86
-
87 return charge_;
-
88}
-
89
-
90void AMSInterface::calculate_SoC_em(const SysTick_s &tick) {
-
91 unsigned long delta_time_micros = tick.micros - last_tick_.micros;
-
92
-
93 float current = HYTECH_em_current_ro_fromS(em_measurements_.em_current_ro); // Current in amps
+
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}
+
91
+
92void AMSInterface::calculate_SoC_em(const SysTick_s &tick) {
+
93 unsigned long delta_time_micros = tick.micros - last_tick_.micros;
94
-
95 // coulombs = amps * microseconds * (1sec / 1000000 microsec)
-
96 charge_ -= (current * delta_time_micros) / 1000000;
-
97
-
98 SoC_ = (charge_ / MAX_PACK_CHARGE) * 100;
-
99}
-
100
-
101void AMSInterface::calculate_SoC_acu(const SysTick_s &tick) {
-
102 unsigned long delta_time_micros = tick.micros - last_tick_.micros;
-
103
-
104 // Converts analog read (from 0 to 4095) into some value (0.0 to 3.3)
-
105 // float current = HYTECH_current_shunt_read_ro_fromS(acu_shunt_measurements_.current_shunt_read_ro);
-
106
-
107 // shunt_voltage ranges from -3.33 to 2.635
-
108 // float shunt_voltage = (current * (9.22 / 5.1)) - 3.3 - 0.03;
-
109
-
110 // calc_current ranges from -666 to 527.176
-
111 // float calc_current = (shunt_voltage / 0.005);
-
112 charge_ -= (HYTECH_current_shunt_read_ro_fromS(acu_shunt_measurements_.current_shunt_read_ro) * delta_time_micros) / 1000000;
-
113
-
114 SoC_ = (charge_ / MAX_PACK_CHARGE) * 100;
-
115}
-
116
-
117void AMSInterface::tick(const SysTick_s &tick) {
+
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}
+
102
+
103void AMSInterface::calculate_SoC_acu(const SysTick_s &tick) {
+
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}
118
-
119 // If AMSInterface has a valid reading in bms_voltages_ and the charge is not
-
120 // yet initialized, then call initialize_charge.
-
121 if ((!has_initialized_charge_) && (has_received_bms_voltage_) && ((tick.millis - timestamp_start_) > initialization_startup_interval_)) {
-
122
-
123 bool bms_voltages_is_invalid = bms_voltages_.low_voltage_ro == 0xFFFFU && bms_voltages_.high_voltage_ro == 0x1111U;
-
124
-
125 if (!bms_voltages_is_invalid) {
-
126 initialize_charge();
-
127 has_initialized_charge_ = true;
-
128 }
-
129
+
119void AMSInterface::tick(const SysTick_s &tick) {
+
120
+
121 // Only calculate the updated SoC if charge has been properly initialized.
+
122 if (has_initialized_charge_) {
+
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_) {
+
126 calculate_SoC_em(tick);
+
127 } else {
+
128 calculate_SoC_acu(tick);
+
129 }
130 }
131
-
132 // Only calculate the updated SoC if charge has been properly initialized.
-
133 if (has_initialized_charge_) {
-
134 // Do not edit this block! If both calculate_SoC_em AND calculate_SoC_acu are run,
-
135 // then the charge will be subtracted from the SoC member variable twice.
-
136 if (use_em_for_soc_) {
-
137 calculate_SoC_em(tick);
-
138 } else {
-
139 calculate_SoC_acu(tick);
-
140 }
-
141 }
-
142
-
143 // Send CAN message
-
144 // enqueue_state_of_charge_CAN();
-
145 STATE_OF_CHARGE_t soc_struct;
-
146 soc_struct.charge_percentage_ro = HYTECH_charge_percentage_ro_toS(SoC_);
-
147 soc_struct.charge_coulombs_ro = HYTECH_charge_coulombs_ro_toS(charge_);
-
148 enqueue_new_CAN<STATE_OF_CHARGE_t>(&soc_struct, Pack_STATE_OF_CHARGE_hytech);
-
149
-
150 last_tick_ = tick;
-
151}
-
152
-
153//RETRIEVE CAN MESSAGES//
-
154void AMSInterface::retrieve_status_CAN(unsigned long curr_millis, CAN_message_t &recvd_msg) {
-
155 bms_status_.load(recvd_msg.buf);
-
156 set_heartbeat(curr_millis);
-
157}
-
158
-
159void AMSInterface::retrieve_temp_CAN(CAN_message_t &recvd_msg) {
-
160 bms_temperatures_.load(recvd_msg.buf);
-
161}
-
162
-
163void AMSInterface::retrieve_voltage_CAN(CAN_message_t &can_msg) {
-
164 Unpack_BMS_VOLTAGES_hytech(&bms_voltages_, can_msg.buf, can_msg.len);
-
165 if (!has_received_bms_voltage_)
-
166 {
-
167 has_received_bms_voltage_ = true;
+
132 // If AMSInterface has a valid reading in bms_voltages_ and enough time has passed since init(), then initialize charge
+
133 if (!has_initialized_charge_ && ((tick.millis - timestamp_start_) >= DEFAULT_INITIALIZATION_WAIT_INTERVAL)) {
+
134
+
135 initialize_charge();
+
136 has_initialized_charge_ = true;
+
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
+
148 last_tick_ = tick;
+
149}
+
150
+
151//RETRIEVE CAN MESSAGES//
+
152void AMSInterface::retrieve_status_CAN(unsigned long curr_millis, CAN_message_t &recvd_msg) {
+
153 bms_status_.load(recvd_msg.buf);
+
154 set_heartbeat(curr_millis);
+
155}
+
156
+
157void AMSInterface::retrieve_temp_CAN(CAN_message_t &recvd_msg) {
+
158 bms_temperatures_.load(recvd_msg.buf);
+
159}
+
160
+
161void AMSInterface::retrieve_voltage_CAN(CAN_message_t &can_msg) {
+
162 Unpack_BMS_VOLTAGES_hytech(&bms_voltages_, can_msg.buf, can_msg.len);
+
163
+
164 if (!has_received_bms_voltage_)
+
165 {
+
166 has_received_bms_voltage_ = true;
+
167 timestamp_start_ = last_tick_.millis;
168 }
169
170}
@@ -254,87 +254,87 @@
176void AMSInterface::retrieve_current_shunt_CAN(const CAN_message_t &can_msg) {
177 Unpack_ACU_SHUNT_MEASUREMENTS_hytech(&acu_shunt_measurements_, can_msg.buf, can_msg.len);
178}
-
179void AMSInterface::calculate_acc_derate_factor() {
-
180 float voltage_lim_factor = 1.0;
-
181 float startDerateVoltage = 3.5;
-
182 float endDerateVoltage = 3.2;
-
183 float voltage_lim_max = 1;
-
184 float voltage_lim_min = 0.2;
-
185
-
186 float temp_lim_factor = 1.0;
-
187 float startDerateTemp = 50;
-
188 float stopDerateTemp = 58;
-
189 float temp_lim_max = 1;
-
190 float temp_lim_min = 0.2;
-
191
-
192 float filtered_min_cell_voltage = get_filtered_min_cell_voltage();
-
193 //float_map equivalient because new code is bad
-
194 voltage_lim_factor = (filtered_min_cell_voltage - startDerateVoltage) * (voltage_lim_min - voltage_lim_max) / (endDerateVoltage - startDerateVoltage) + voltage_lim_max;
-
195 voltage_lim_factor = max(min(voltage_lim_max, voltage_lim_factor), voltage_lim_min);
-
196
-
197 temp_lim_factor = (filtered_max_cell_temp - startDerateTemp) * (temp_lim_min - temp_lim_max) / (stopDerateTemp - startDerateTemp) + temp_lim_max;
-
198 temp_lim_factor = max(min(temp_lim_factor, temp_lim_max), temp_lim_min);
-
199
-
200 acc_derate_factor = min(temp_lim_factor,voltage_lim_factor);
-
201}
-
202
-
203float AMSInterface::get_acc_derate_factor() {
-
204 calculate_acc_derate_factor();
-
205 return acc_derate_factor;
-
206
+
179
+
180void AMSInterface::calculate_acc_derate_factor() {
+
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
+
193 float filtered_min_cell_voltage = get_filtered_min_cell_voltage();
+
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}
+
203
+
204float AMSInterface::get_acc_derate_factor() {
+
205 calculate_acc_derate_factor();
+
206 return acc_derate_factor;
207}
208
209
-
AMSInterface::get_acc_derate_factor
float get_acc_derate_factor()
Definition: AMSInterface.cpp:203
-
AMSInterface::has_initialized_charge_
bool has_initialized_charge_
Definition: AMSInterface.h:251
-
AMSInterface::cell_voltage_alpha
float cell_voltage_alpha
Definition: AMSInterface.h:219
-
AMSInterface::tick
void tick(const SysTick_s &tick)
Definition: AMSInterface.cpp:117
-
AMSInterface::charge_
float charge_
Definition: AMSInterface.h:234
-
AMSInterface::bms_voltages_
BMS_VOLTAGES_t bms_voltages_
Definition: AMSInterface.h:208
-
AMSInterface::acc_derate_factor
float acc_derate_factor
Definition: AMSInterface.h:221
-
AMSInterface::filtered_min_cell_voltage
float filtered_min_cell_voltage
Definition: AMSInterface.h:217
+
AMSInterface::get_acc_derate_factor
float get_acc_derate_factor()
Definition: AMSInterface.cpp:204
+
AMSInterface::has_initialized_charge_
bool has_initialized_charge_
Definition: AMSInterface.h:250
+
AMSInterface::cell_voltage_alpha
float cell_voltage_alpha
Definition: AMSInterface.h:218
+
AMSInterface::tick
void tick(const SysTick_s &tick)
Definition: AMSInterface.cpp:119
+
AMSInterface::charge_
float charge_
Definition: AMSInterface.h:233
+
AMSInterface::bms_voltages_
BMS_VOLTAGES_t bms_voltages_
Definition: AMSInterface.h:207
+
AMSInterface::acc_derate_factor
float acc_derate_factor
Definition: AMSInterface.h:220
+
AMSInterface::filtered_min_cell_voltage
float filtered_min_cell_voltage
Definition: AMSInterface.h:216
AMSInterface::retrieve_current_shunt_CAN
void retrieve_current_shunt_CAN(const CAN_message_t &can_msg)
Definition: AMSInterface.cpp:176
AMSInterface::set_heartbeat
void set_heartbeat(unsigned long curr_millis)
Definition: AMSInterface.cpp:46
-
AMSInterface::last_tick_
SysTick_s last_tick_
Definition: AMSInterface.h:246
-
AMSInterface::bms_temperatures_
BMS_temperatures bms_temperatures_
Definition: AMSInterface.h:205
+
AMSInterface::last_tick_
SysTick_s last_tick_
Definition: AMSInterface.h:245
+
AMSInterface::bms_temperatures_
BMS_temperatures bms_temperatures_
Definition: AMSInterface.h:204
AMSInterface::get_filtered_min_cell_voltage
float get_filtered_min_cell_voltage()
Definition: AMSInterface.cpp:73
-
AMSInterface::bms_low_voltage
float bms_low_voltage
Definition: AMSInterface.h:215
-
AMSInterface::acu_shunt_measurements_
ACU_SHUNT_MEASUREMENTS_t acu_shunt_measurements_
Definition: AMSInterface.h:206
+
AMSInterface::bms_low_voltage
float bms_low_voltage
Definition: AMSInterface.h:214
+
AMSInterface::acu_shunt_measurements_
ACU_SHUNT_MEASUREMENTS_t acu_shunt_measurements_
Definition: AMSInterface.h:205
AMSInterface::is_below_pack_charge_critical_total_thresh
bool is_below_pack_charge_critical_total_thresh()
Definition: AMSInterface.cpp:58
AMSInterface::init
void init(SysTick_s &initial_tick)
Definition: AMSInterface.cpp:14
-
AMSInterface::retrieve_status_CAN
void retrieve_status_CAN(unsigned long curr_millis, CAN_message_t &recvd_msg)
Definition: AMSInterface.cpp:154
-
AMSInterface::retrieve_temp_CAN
void retrieve_temp_CAN(CAN_message_t &recvd_msg)
Definition: AMSInterface.cpp:159
-
AMSInterface::bms_high_temp
float bms_high_temp
Definition: AMSInterface.h:214
+
AMSInterface::retrieve_status_CAN
void retrieve_status_CAN(unsigned long curr_millis, CAN_message_t &recvd_msg)
Definition: AMSInterface.cpp:152
+
AMSInterface::retrieve_temp_CAN
void retrieve_temp_CAN(CAN_message_t &recvd_msg)
Definition: AMSInterface.cpp:157
+
AMSInterface::bms_high_temp
float bms_high_temp
Definition: AMSInterface.h:213
AMSInterface::enqueue_new_CAN
void enqueue_new_CAN(U *structure, uint32_t(*pack_function)(U *, uint8_t *, uint8_t *, uint8_t *))
Definition: AMSInterface.cpp:6
-
AMSInterface::last_heartbeat_time_
unsigned long last_heartbeat_time_
Definition: AMSInterface.h:211
+
AMSInterface::last_heartbeat_time_
unsigned long last_heartbeat_time_
Definition: AMSInterface.h:210
AMSInterface::heartbeat_received
bool heartbeat_received(unsigned long curr_millis)
Definition: AMSInterface.cpp:50
-
AMSInterface::calculate_SoC_acu
void calculate_SoC_acu(const SysTick_s &tick)
Definition: AMSInterface.cpp:101
-
AMSInterface::use_em_for_soc_
bool use_em_for_soc_
Definition: AMSInterface.h:228
-
AMSInterface::cell_temp_alpha
float cell_temp_alpha
Definition: AMSInterface.h:218
+
AMSInterface::calculate_SoC_acu
void calculate_SoC_acu(const SysTick_s &tick)
Definition: AMSInterface.cpp:103
+
AMSInterface::use_em_for_soc_
bool use_em_for_soc_
Definition: AMSInterface.h:227
+
AMSInterface::cell_temp_alpha
float cell_temp_alpha
Definition: AMSInterface.h:217
AMSInterface::get_filtered_max_cell_temp
float get_filtered_max_cell_temp()
Definition: AMSInterface.cpp:67
-
AMSInterface::timestamp_start_
unsigned long timestamp_start_
Definition: AMSInterface.h:257
-
AMSInterface::pin_software_ok_
int pin_software_ok_
Definition: AMSInterface.h:201
+
AMSInterface::timestamp_start_
unsigned long timestamp_start_
Definition: AMSInterface.h:261
+
AMSInterface::pin_software_ok_
int pin_software_ok_
Definition: AMSInterface.h:200
AMSInterface::set_state_ok_high
void set_state_ok_high(bool ok_high)
Definition: AMSInterface.cpp:39
-
AMSInterface::VOLTAGE_LOOKUP_TABLE
const float VOLTAGE_LOOKUP_TABLE[101]
Definition: AMSInterface.h:188
-
AMSInterface::has_received_bms_voltage_
bool has_received_bms_voltage_
Definition: AMSInterface.h:253
-
AMSInterface::bms_status_
BMS_status bms_status_
Definition: AMSInterface.h:204
+
AMSInterface::has_received_bms_voltage_
bool has_received_bms_voltage_
Definition: AMSInterface.h:256
+
AMSInterface::bms_status_
BMS_status bms_status_
Definition: AMSInterface.h:203
AMSInterface::is_below_pack_charge_critical_low_thresh
bool is_below_pack_charge_critical_low_thresh()
Definition: AMSInterface.cpp:54
-
AMSInterface::retrieve_voltage_CAN
void retrieve_voltage_CAN(CAN_message_t &recvd_msg)
Definition: AMSInterface.cpp:163
-
AMSInterface::em_measurements_
EM_MEASUREMENT_t em_measurements_
Definition: AMSInterface.h:207
-
AMSInterface::initialization_startup_interval_
unsigned long initialization_startup_interval_
Definition: AMSInterface.h:255
-
AMSInterface::msg_queue_
CANBufferType * msg_queue_
Definition: AMSInterface.h:198
+
AMSInterface::retrieve_voltage_CAN
void retrieve_voltage_CAN(CAN_message_t &recvd_msg)
Definition: AMSInterface.cpp:161
+
AMSInterface::em_measurements_
EM_MEASUREMENT_t em_measurements_
Definition: AMSInterface.h:206
+
AMSInterface::msg_queue_
CANBufferType * msg_queue_
Definition: AMSInterface.h:197
AMSInterface::initialize_charge
float initialize_charge()
Definition: AMSInterface.cpp:79
AMSInterface::set_start_state
void set_start_state()
Definition: AMSInterface.cpp:32
-
AMSInterface::SoC_
float SoC_
Definition: AMSInterface.h:241
-
AMSInterface::filtered_max_cell_temp
float filtered_max_cell_temp
Definition: AMSInterface.h:216
+
AMSInterface::SoC_
float SoC_
Definition: AMSInterface.h:240
+
AMSInterface::filtered_max_cell_temp
float filtered_max_cell_temp
Definition: AMSInterface.h:215
AMSInterface::retrieve_em_measurement_CAN
void retrieve_em_measurement_CAN(CAN_message_t &can_msg)
Definition: AMSInterface.cpp:172
+
AMSInterface::VOLTAGE_LOOKUP_TABLE
const float VOLTAGE_LOOKUP_TABLE[101]
Definition: AMSInterface.h:187
AMSInterface::pack_charge_is_critical
bool pack_charge_is_critical()
Definition: AMSInterface.cpp:62
-
AMSInterface::calculate_acc_derate_factor
void calculate_acc_derate_factor()
Definition: AMSInterface.cpp:179
-
AMSInterface::calculate_SoC_em
void calculate_SoC_em(const SysTick_s &tick)
Definition: AMSInterface.cpp:90
-
MAX_PACK_CHARGE
const uint16_t MAX_PACK_CHARGE
Definition: AMSInterface.h:21
-
PACK_CHARGE_CRIT_LOWEST_CELL_THRESHOLD
const unsigned long PACK_CHARGE_CRIT_LOWEST_CELL_THRESHOLD
Definition: AMSInterface.h:8
-
PACK_CHARGE_CRIT_TOTAL_THRESHOLD
const unsigned long PACK_CHARGE_CRIT_TOTAL_THRESHOLD
Definition: AMSInterface.h:7
-
HEARTBEAT_INTERVAL
const unsigned long HEARTBEAT_INTERVAL
Definition: AMSInterface.h:6
+
AMSInterface::calculate_acc_derate_factor
void calculate_acc_derate_factor()
Definition: AMSInterface.cpp:180
+
AMSInterface::calculate_SoC_em
void calculate_SoC_em(const SysTick_s &tick)
Definition: AMSInterface.cpp:92
+
MAX_PACK_CHARGE
const unsigned short MAX_PACK_CHARGE
Definition: AMSInterface.h:21
+
PACK_CHARGE_CRIT_LOWEST_CELL_THRESHOLD
const unsigned long PACK_CHARGE_CRIT_LOWEST_CELL_THRESHOLD
Definition: AMSInterface.h:15
+
PACK_CHARGE_CRIT_TOTAL_THRESHOLD
const unsigned long PACK_CHARGE_CRIT_TOTAL_THRESHOLD
Definition: AMSInterface.h:14
+
DEFAULT_INITIALIZATION_WAIT_INTERVAL
const unsigned long DEFAULT_INITIALIZATION_WAIT_INTERVAL
Definition: AMSInterface.h:22
+
HEARTBEAT_INTERVAL
const unsigned long HEARTBEAT_INTERVAL
Definition: AMSInterface.h:13