Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion include/ACU_Constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ namespace ACUSystems
constexpr const volt VOLTAGE_DIFF_TO_INIT_CB = 0.02; // differential with lowest cell voltage to enable cell balancing for a cell
constexpr const celsius BALANCE_TEMP_LIMIT_C = 50.0;
constexpr const celsius BALANCE_ENABLE_TEMP_THRESH_C = 35.0; // Celsius
constexpr const volt TS_ISOLATION_VOLTAGE = 0.2; // Volts
}

namespace ACUInterfaces {
Expand All @@ -32,7 +33,8 @@ namespace ACUInterfaces {
const size_t SERIAL_BAUDRATE = 115200;

constexpr const size_t TEENSY_OK_PIN = 3; // > Needs to stay HIGH while wd_kick_pin flips to keep BMS_OK high
constexpr const size_t WD_KICK_PIN = 4; // > Needs to flip at 100 Hz to keep BMS_OK high
constexpr const size_t WD_KICK_PIN = 4; // > Needs to flip at 100 Hz to keep BMS_OK high
constexpr const size_t SW_NOT_OK_PIN = 5;
constexpr const size_t N_LATCH_EN_PIN = 6; // > Input to Safety Light, true when teensy is not in FAULT state
constexpr const size_t TS_OUT_FILTERED_PIN = 17;
constexpr const size_t PACK_OUT_FILTERED_PIN = 18;
Expand Down
3 changes: 3 additions & 0 deletions include/ACU_SystemTasks.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ extern ::etl::delegate<bool()> has_imd_fault;
extern ::etl::delegate<bool()> received_valid_shdn_out;
extern ::etl::delegate<void()> enable_cell_balancing;
extern ::etl::delegate<void()> disable_cell_balancing;
extern ::etl::delegate<bool()> contactor_welded;
extern ::etl::delegate<void()> disable_watchdog;
extern ::etl::delegate<void()> reinitialize_watchdog;
extern ::etl::delegate<void()> disable_n_latch_en;
Expand All @@ -39,4 +40,6 @@ ::HT_TASK::TaskResponse evaluate_accumulator(const unsigned long &sysMicros, con

::HT_TASK::TaskResponse tick_state_machine(const unsigned long &sysMicros, const HT_TASK::TaskInfo &taskInfo);



#endif
5 changes: 5 additions & 0 deletions lib/interfaces/include/ADCInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ struct ADCPinout_s
pin teensy_pack_out_filtered_pin;
pin teensy_bspd_current_pin;
pin teensy_scaled_24V_pin;
pin teensy_sw_not_ok_pin;
};

struct ADCConversions_s
Expand Down Expand Up @@ -155,6 +156,10 @@ class ADCInterface
*/
bool is_in_imd_startup_period() const;

void set_sw_not_ok_pin_high();

void set_sw_not_ok_pin_low();

private:
const ADCInterfaceParams_s _adc_parameters = {};

Expand Down
1 change: 1 addition & 0 deletions lib/interfaces/src/ACUEthernetInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ hytech_msgs_ACUCoreData ACUEthernetInterface::make_acu_core_data_msg(const ACUCo
out.min_measured_pack_voltage = shared_state.min_measured_pack_out_voltage;
out.min_measured_tractive_system_voltage = shared_state.min_measured_ts_out_voltage;
out.min_measured_shdn_out_voltage = shared_state.min_shdn_out_voltage;


return out;
}
Expand Down
9 changes: 9 additions & 0 deletions lib/interfaces/src/ADCInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ void ADCInterface::init(uint32_t init_millis) {
pinMode(_adc_parameters.pinout.teensy_pack_out_filtered_pin, INPUT);
pinMode(_adc_parameters.pinout.teensy_bspd_current_pin, INPUT);
pinMode(_adc_parameters.pinout.teensy_scaled_24V_pin, INPUT);
pinMode(_adc_parameters.pinout.teensy_sw_not_ok_pin, OUTPUT);

_init_millis = init_millis;
_in_imd_startup_period = true;
Expand Down Expand Up @@ -80,4 +81,12 @@ const ADCInterfaceParams_s& ADCInterface::get_adc_params() const {

bool ADCInterface::is_in_imd_startup_period() const {
return _in_imd_startup_period;
}

void ADCInterface::set_sw_not_ok_pin_high() {
digitalWrite(_adc_parameters.pinout.teensy_sw_not_ok_pin, HIGH);
}

void ADCInterface::set_sw_not_ok_pin_low() {
digitalWrite(_adc_parameters.pinout.teensy_sw_not_ok_pin, LOW);
}
1 change: 1 addition & 0 deletions lib/interfaces/src/WatchdogInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ void WatchdogInterface::init() {
pinMode(_watchdog_parameters.pinout.teensy_ok_pin, OUTPUT);
pinMode(_watchdog_parameters.pinout.teensy_wd_kick_pin, OUTPUT);
pinMode(_watchdog_parameters.pinout.teensy_n_latch_en_pin, OUTPUT);


// Initial Pin States for OUTPUT pins
digitalWrite(_watchdog_parameters.pinout.teensy_ok_pin, HIGH);
Expand Down
18 changes: 16 additions & 2 deletions lib/state_machine/include/ACUStateMachine.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ enum class ACUState_e
STARTUP = 0,
ACTIVE = 1,
CHARGING = 2,
FAULTED = 3,
FAULTED = 3,
WELDED = 4,
WELDPASSED = 5
};

class ACUStateMachine
Expand All @@ -23,6 +25,9 @@ class ACUStateMachine
etl::delegate<bool()> charge_state_requested,
etl::delegate<bool()> has_bms_fault,
etl::delegate<bool()> has_imd_fault,
etl::delegate<bool()> contactor_welded,
etl::delegate<void()> set_sw_not_ok_pin_high,
etl::delegate<void()> set_sw_not_ok_pin_low,
etl::delegate<bool()> received_valid_shdn_out,
etl::delegate<void()> enable_cell_balancing,
etl::delegate<void()> disable_cell_balancing,
Expand All @@ -35,6 +40,9 @@ class ACUStateMachine
_charge_state_requested(charge_state_requested),
_has_bms_fault(has_bms_fault),
_has_imd_fault(has_imd_fault),
_contactor_welded(contactor_welded),
_set_sw_not_ok_pin_high(set_sw_not_ok_pin_high),
_set_sw_not_ok_pin_low(set_sw_not_ok_pin_low),
_received_valid_shdn_out(received_valid_shdn_out),
_enable_cell_balancing(enable_cell_balancing),
_disable_cell_balancing(disable_cell_balancing),
Expand All @@ -54,6 +62,8 @@ class ACUStateMachine
*/
ACUState_e get_state() { return _current_state; }



private:

void _set_state(ACUState_e new_state, unsigned long curr_millis);
Expand All @@ -72,11 +82,15 @@ class ACUStateMachine

ACUState_e _current_state;
unsigned long _last_state_changed_time; // time of last state change



// Lamdas for state machine abstraction, functions defined in main
etl::delegate<bool()> _charge_state_requested;
etl::delegate<bool()> _has_bms_fault;
etl::delegate<bool()> _has_imd_fault;
etl::delegate<bool()> _contactor_welded;
etl::delegate<void()> _set_sw_not_ok_pin_high;
etl::delegate<void()> _set_sw_not_ok_pin_low;
etl::delegate<bool()> _received_valid_shdn_out;
/// @brief setters
etl::delegate<void()> _enable_cell_balancing;
Expand Down
46 changes: 39 additions & 7 deletions lib/state_machine/src/ACUStateMachine.cpp
Original file line number Diff line number Diff line change
@@ -1,19 +1,37 @@
#include "ACUStateMachine.h"
#include <iostream>
using namespace std;


void ACUStateMachine::tick_state_machine(unsigned long current_millis) {
switch(_current_state) {
case ACUState_e::STARTUP:
{
if (_received_valid_shdn_out()) {
_set_state(ACUState_e::ACTIVE, current_millis);
break;
if (current_millis - _last_state_changed_time >= 1000) {
if (_contactor_welded()) {
_set_state(ACUState_e::WELDED, current_millis);
break;
}
else {
_set_state(ACUState_e::WELDPASSED, current_millis);
break;
}
}
if ((current_millis - _last_state_changed_time > 2000) && (_has_bms_fault() || _has_imd_fault())) {
_set_state(ACUState_e::FAULTED, current_millis);

break;
}
case ACUState_e::WELDPASSED:
{
if (_received_valid_shdn_out()) {
_set_state(ACUState_e::ACTIVE, current_millis);
break;
}
break;
}
case ACUState_e::WELDED:
{

}

case ACUState_e::ACTIVE:
{
if (_charge_state_requested()) {
Expand Down Expand Up @@ -84,6 +102,8 @@ void ACUStateMachine::_handle_exit_logic(ACUState_e prev_state, unsigned long cu
}
case ACUState_e::STARTUP:
case ACUState_e::ACTIVE:
case ACUState_e::WELDPASSED:
case ACUState_e::WELDED:
default:
break;
}
Expand All @@ -94,9 +114,20 @@ void ACUStateMachine::_handle_entry_logic(ACUState_e new_state, unsigned long cu
switch(new_state) {
case ACUState_e::STARTUP:
{
_last_state_changed_time = curr_millis;
_reinitialize_watchdog();
break;
}
case ACUState_e::WELDPASSED:
{
_set_sw_not_ok_pin_low();
break;
}
case ACUState_e::WELDED:
{
_set_sw_not_ok_pin_high();
break;
}
case ACUState_e::CHARGING:
{
_enable_cell_balancing();
Expand All @@ -113,4 +144,5 @@ void ACUStateMachine::_handle_entry_logic(ACUState_e new_state, unsigned long cu
default:
break;
}
}
}

17 changes: 15 additions & 2 deletions lib/systems/include/ACUController.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef ACUCONTROLLER_H
#define ACUCONTROLLER_H

#include <Arduino.h>
#include <array>
#include <stddef.h>
#include <stdio.h>
Expand All @@ -20,6 +21,8 @@ namespace acu_controller_default_parameters
constexpr const float PACK_MAX_VOLTAGE = 529.2; // from data sheet https://wiki.hytechracing.org/books/ht09-design/page/molicel-pack-investigation
constexpr const float PACK_MIN_VOLTAGE = 378.0; // from data sheet^ but just assume 126 * 3.0V
constexpr const float PACK_INTERNAL_RESISTANCE = 0.246; // Ohms (measured)


}
struct ACUControllerData_s
{
Expand All @@ -37,6 +40,9 @@ struct ACUControllerData_s
uint32_t last_bms_not_ok_eval;
bool charging_enabled;
bool balancing_enabled;
bool high_side_contactor_welded;
bool low_side_contactor_welded;

};

struct ACUControllerThresholds_s
Expand All @@ -50,6 +56,7 @@ struct ACUControllerThresholds_s
volt v_diff_to_init_cb = 0;
celsius balance_temp_limit_c = 0;
celsius balance_enable_temp_c = 0;
volt ts_isolation_voltage = 0;
};

struct ACUControllerFaultDurations_s
Expand Down Expand Up @@ -99,8 +106,10 @@ class ACUController
.pack_nominal_capacity = acu_controller_default_parameters::PACK_NOMINAL_CAPACITY_AH,
.pack_max_voltage = acu_controller_default_parameters::PACK_MAX_VOLTAGE,
.pack_min_voltage = acu_controller_default_parameters::PACK_MIN_VOLTAGE,
.pack_internal_resistance = acu_controller_default_parameters::PACK_INTERNAL_RESISTANCE
}) : _acu_parameters{thresholds, invalid_packet_count_thresh, fault_durations, pack_specs} {};
.pack_internal_resistance = acu_controller_default_parameters::PACK_INTERNAL_RESISTANCE}


) : _acu_parameters{thresholds, invalid_packet_count_thresh, fault_durations, pack_specs} {};

/**
* @brief Initialize the status time stamps because we don't want accidental sudden faults
Expand All @@ -118,6 +127,7 @@ class ACUController
* Calculate Cell Balancing values
* @pre cell charging is enabled
* @post output will have the new values
* check TS isolation
*/
void calculate_cell_balance_statuses(bool* output, const volt* voltages, size_t num_of_voltage_cells, volt min_voltage);

Expand All @@ -136,6 +146,9 @@ class ACUController
{
_acu_state.charging_enabled = false;
}

bool check_ts_isolation(volt pack_voltage_adc, volt ts_voltage_adc);

private:


Expand Down
15 changes: 14 additions & 1 deletion lib/systems/src/ACUController.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "ACUController.h"



void ACUController::init(time_ms system_start_time, volt pack_voltage)
{
_acu_state.last_time_ov_fault_not_present = system_start_time;
Expand All @@ -12,6 +13,8 @@ void ACUController::init(time_ms system_start_time, volt pack_voltage)
_acu_state.prev_bms_time_stamp = system_start_time;
_acu_state.SoC = (pack_voltage <= _acu_parameters.pack_specs.pack_min_voltage) ? 0.0f : ((pack_voltage - _acu_parameters.pack_specs.pack_min_voltage) / (_acu_parameters.pack_specs.pack_max_voltage - _acu_parameters.pack_specs.pack_min_voltage));
_acu_state.balancing_enabled = false;
_acu_state.high_side_contactor_welded = false;
_acu_state.low_side_contactor_welded = false;
}


Expand Down Expand Up @@ -100,7 +103,6 @@ ACUControllerData_s ACUController::evaluate_accumulator(time_ms current_millis,
// Determine if bms is ok
_acu_state.bms_ok = _check_bms_ok(current_millis);


return _acu_state;
}

Expand Down Expand Up @@ -173,4 +175,15 @@ bool ACUController::_check_invalid_packet_faults(time_ms current_millis)
{
bool invalid_packet_fault = (current_millis - _acu_state.last_time_invalid_packet_present) > _acu_parameters.fault_durations.max_allowed_invalid_packet_fault_dur;
return invalid_packet_fault;
}

bool ACUController::check_ts_isolation(volt pack_voltage_adc, volt ts_voltage_adc)
{


_acu_state.low_side_contactor_welded = !(pack_voltage_adc < _acu_parameters.thresholds.ts_isolation_voltage);
_acu_state.high_side_contactor_welded = !(ts_voltage_adc < _acu_parameters.thresholds.ts_isolation_voltage);

bool sw_not_ok = _acu_state.low_side_contactor_welded || _acu_state.high_side_contactor_welded;
return sw_not_ok;
}
2 changes: 1 addition & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[common]
lib_deps_shared =
https://github.com/hytech-racing/shared_firmware_systems.git
https://github.com/hytech-racing/shared_firmware_types.git#9525cc8b5778567afee9d9121f8f8933367e13b3
https://github.com/hytech-racing/shared_firmware_types.git#7a3684f9501d672b8229476644b8ee5556f0adb5
Embedded Template Library@^20.39.4

; Teensy41 Environment. This environment is the primary environment for uploading code to the car.
Expand Down
9 changes: 7 additions & 2 deletions src/ACU_InterfaceTasks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ static ACUAllDataType_s make_acu_all_data()
out.core_data.min_measured_ts_out_voltage = watchdog.min_measured_ts_out_voltage;
out.core_data.min_shdn_out_voltage = watchdog.min_shdn_out_voltage;
// SoC/SoH placeholders (leave unchanged here)
out.SoC = ACUControllerInstance::instance().get_status().SoC;
auto ACUStatus = ACUControllerInstance::instance().get_status();

out.SoC = ACUStatus.SoC;
out.core_data.high_side_contactor_welded = ACUStatus.high_side_contactor_welded;
out.core_data.low_side_contactor_welded = ACUStatus.low_side_contactor_welded;

return out;
}
Expand Down Expand Up @@ -94,7 +98,8 @@ void initialize_all_interfaces()
ACUInterfaces::TS_OUT_FILTERED_PIN,
ACUInterfaces::PACK_OUT_FILTERED_PIN,
ACUInterfaces::BSPD_CURRENT_PIN,
ACUInterfaces::SCALED_24V_PIN},
ACUInterfaces::SCALED_24V_PIN,
ACUInterfaces::SW_NOT_OK_PIN},
ADCConversions_s {ACUInterfaces::SHUTDOWN_CONV_FACTOR,
ACUInterfaces::PRECHARGE_CONV_FACTOR,
ACUInterfaces::PACK_AND_TS_OUT_CONV_FACTOR,
Expand Down
Loading
Loading