Avalon Firmware
 
Loading...
Searching...
No Matches
supercap_controllers.hpp
Go to the documentation of this file.
1
11
12#ifndef STM_UTILS_INC_SUPERCAP_CONTROLLERS_HPP_
13#define STM_UTILS_INC_SUPERCAP_CONTROLLERS_HPP_
14
15#include "adc_utils.hpp"
16#include "hrtim.h"
17
25
39
43typedef enum {
47
52#define HRTIM_PERIOD 34000
53#define HRTIM_HALF_PERIOD 17000
54
63public:
70 supercap_control_manager(ADC_HandleTypeDef* adc_cap, ADC_HandleTypeDef* adc_bat, ADC_HandleTypeDef* adc_temp) :
71 adc_manager(adc_cap, adc_bat, adc_temp) {};
72
75
80 HAL_StatusTypeDef init_loop();
81
86
91 void set_ref_chassis_power(float ref_power_);
92
101 void loop_update(float Icap_, float Ibat_, float Vcap_, float Ichassis_, float Vbat_);
102
106 void stop_loop();
107
112 HAL_StatusTypeDef start_loop();
113
119 HAL_StatusTypeDef start_gates_pwm(float init_duty_cycle);
120
125
130
133
134private:
136 float ref_power = 60.0f;
137};
138
142void softwareReset();
143
147extern uint8_t safetyItemLevel[8];
148
153extern float chassis_voltage;
154extern float battery_current;
155
156#endif /* STM_UTILS_INC_SUPERCAP_CONTROLLERS_HPP_ */
Header file for managing ADC sampling, compensation, and filtering for the supercapacitor control boa...
adc_manager(ADC_HandleTypeDef *adc_cap, ADC_HandleTypeDef *adc_bat, ADC_HandleTypeDef *adc_temp)
Constructor.
Definition adc_utils.hpp:159
void set_ref_chassis_power(float ref_power_)
Sets the desired reference power draw (in watts) for the chassis.
Definition supercap_controllers.cpp:428
void loop_update(float Icap_, float Ibat_, float Vcap_, float Ichassis_, float Vbat_)
Performs a full control loop update using current sensor inputs.
void stop_loop()
Stops the control loop and disables gate driving.
Definition supercap_controllers.cpp:289
HAL_StatusTypeDef start_gates_pwm(float init_duty_cycle)
Initializes the gate PWM output using a given starting duty cycle.
Definition supercap_controllers.cpp:384
safetyLevelDef safetyLevel
Current system safety level status.
Definition supercap_controllers.hpp:132
HAL_StatusTypeDef start_loop()
Starts the supercap control loop (if not in calibration mode).
Definition supercap_controllers.cpp:259
HAL_StatusTypeDef init_loop()
Initializes the control loop by setting up the PID controllers.
Definition supercap_controllers.cpp:69
supercap_control_manager(ADC_HandleTypeDef *adc_cap, ADC_HandleTypeDef *adc_bat, ADC_HandleTypeDef *adc_temp)
Constructor for the supercap controller.
Definition supercap_controllers.hpp:70
void all_safety_checks()
Executes all defined safety checks (voltage, current).
~supercap_control_manager()
Destructor (default)
Definition supercap_controllers.hpp:74
void silent_mode()
Manually forces system into a silent mode (e.g., for emergency recovery).
void setup_pid_controllers()
Configures PID controllers for power, current, and voltage regulation.
Definition supercap_controllers.cpp:104
This file contains all the function prototypes for the hrtim.c file.
uint8_t safetyItemLevel[8]
Tracks safety status per monitored item.
Definition supercap_controllers.cpp:46
float battery_current
Definition supercap_controllers.cpp:31
float chassis_voltage
Extern global values for chassis voltage and battery current (used across control loops and diagnosti...
Definition supercap_controllers.cpp:29
safetyLevelDef
Safety level definitions for runtime system checks.
Definition supercap_controllers.hpp:32
@ wtf
Dangerous state; enters idle.
Definition supercap_controllers.hpp:35
@ itsJoever
Catastrophic failure (system shutdown trigger)
Definition supercap_controllers.hpp:37
@ warning
Mild error, could recover automatically.
Definition supercap_controllers.hpp:34
@ safe
Normal operation.
Definition supercap_controllers.hpp:33
@ runAway
Reserved for runaway behavior.
Definition supercap_controllers.hpp:36
void softwareReset()
Software-triggered MCU reset function (called on fatal error or remote command).
Definition supercap_controllers.cpp:312
Mode_ModeTypedef
Modes for the supercap control loop.
Definition supercap_controllers.hpp:43
@ idle
Supercap system inactive.
Definition supercap_controllers.hpp:44
@ normal
Supercap active and managing power.
Definition supercap_controllers.hpp:45
Safety_DetectItemTypedef
Enumerates the various error detection sources used for safety monitoring.
Definition supercap_controllers.hpp:21
@ voltageErr
Detected unsafe or unstable voltage conditions.
Definition supercap_controllers.hpp:22
@ currentErr
Detected unsafe current draw or injection.
Definition supercap_controllers.hpp:23