Main control class for managing the supercapacitor charge/discharge behavior. More...
#include <supercap_controllers.hpp>
Public Member Functions | |
| supercap_control_manager (ADC_HandleTypeDef *adc_cap, ADC_HandleTypeDef *adc_bat, ADC_HandleTypeDef *adc_temp) | |
| Constructor for the supercap controller. | |
| ~supercap_control_manager () | |
| Destructor (default) | |
| HAL_StatusTypeDef | init_loop () |
| Initializes the control loop by setting up the PID controllers. | |
| void | setup_pid_controllers () |
| Configures PID controllers for power, current, and voltage regulation. | |
| void | set_ref_chassis_power (float ref_power_) |
| Sets the desired reference power draw (in watts) for the chassis. | |
| 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. | |
| HAL_StatusTypeDef | start_loop () |
| Starts the supercap control loop (if not in calibration mode). | |
| HAL_StatusTypeDef | start_gates_pwm (float init_duty_cycle) |
| Initializes the gate PWM output using a given starting duty cycle. | |
| void | all_safety_checks () |
| Executes all defined safety checks (voltage, current). | |
| void | silent_mode () |
| Manually forces system into a silent mode (e.g., for emergency recovery). | |
Public Member Functions inherited from adc_manager | |
| adc_manager (ADC_HandleTypeDef *adc_cap, ADC_HandleTypeDef *adc_bat, ADC_HandleTypeDef *adc_temp) | |
| Constructor. | |
| HAL_StatusTypeDef | adc_init (uint8_t *filters_length) |
| Initializes ADCs and filter states. | |
| float | get_temperature () |
| Reads temperature using onboard NTC. | |
Data Fields | |
| safetyLevelDef | safetyLevel |
| Current system safety level status. | |
Data Fields inherited from adc_manager | |
| bool | calibration_ready = false |
| Optional flag for calibration flow. | |
Main control class for managing the supercapacitor charge/discharge behavior.
Inherits from adc_manager to reuse ADC data collection logic. This class manages PID-based power balancing, duty cycle generation, and safety enforcement logic.
|
inline |
Constructor for the supercap controller.
| adc_cap | Pointer to ADC for supercap measurements |
| adc_bat | Pointer to ADC for battery-side measurements |
| adc_temp | Pointer to ADC used for temperature sensing |
|
inline |
Destructor (default)
| void supercap_control_manager::all_safety_checks | ( | ) |
Executes all defined safety checks (voltage, current).
| HAL_StatusTypeDef supercap_control_manager::init_loop | ( | ) |
Initializes the control loop by setting up the PID controllers.
Initializes the supercapacitor control loop.
This function is the main entry point for setting up all the PID controllers used in power, current, and voltage regulation of the supercapacitor buck-boost control system. It prepares the system to safely start PWM generation and transitions into active loop mode.
| void supercap_control_manager::loop_update | ( | float | Icap_, |
| float | Ibat_, | ||
| float | Vcap_, | ||
| float | Ichassis_, | ||
| float | Vbat_ ) |
Performs a full control loop update using current sensor inputs.
| Icap_ | Current into the supercap |
| Ibat_ | Current from the battery |
| Vcap_ | Voltage of the supercap bank |
| Ichassis_ | Current drawn by the chassis |
| Vbat_ | Voltage of the battery |
| void supercap_control_manager::set_ref_chassis_power | ( | float | ref_power_ | ) |
Sets the desired reference power draw (in watts) for the chassis.
Sets the chassis power reference for the outermost control loop.
| ref_power_ | The power target. |
Used by the application layer to define the desired output power level that the control system should regulate around.
| ref_power_ | Desired chassis power reference in watts. |
| void supercap_control_manager::setup_pid_controllers | ( | ) |
Configures PID controllers for power, current, and voltage regulation.
Initializes all PID controllers used in the control loop.
This sets up the PID control parameters for:
For each loop, the gain parameters and min/max output ranges are set. The controller states are initialized using arm_pid_init_f32, and duty ratio is precomputed based on real-time readings to avoid unstable startup behavior.
If CALIBRATION_MODE is disabled, this also starts the PWM gates using the computed initial duty ratio and marks the system as initialized.
| void supercap_control_manager::silent_mode | ( | ) |
Manually forces system into a silent mode (e.g., for emergency recovery).
| HAL_StatusTypeDef supercap_control_manager::start_gates_pwm | ( | float | init_duty_cycle | ) |
Initializes the gate PWM output using a given starting duty cycle.
Starts the high-resolution PWM gate outputs with an initial duty cycle.
| init_duty_cycle | Duty ratio to apply |
This function is typically called after PID controllers are initialized. It updates the gate PWM duty cycle and starts all 4 gate signals using the STM32 HRTIM peripheral.
| init_duty_cycle | The duty cycle to start with, based on Vcap / Vbat ratio. |
| HAL_StatusTypeDef supercap_control_manager::start_loop | ( | ) |
Starts the supercap control loop (if not in calibration mode).
Starts the control loop by re-enabling PWM gates and computing the initial duty ratio.
Only runs if not in calibration mode. Reads current capacitor and battery voltages to estimate a stable initial duty cycle for the buck-boost circuit, then starts gate switching.
| void supercap_control_manager::stop_loop | ( | ) |
Stops the control loop and disables gate driving.
Halts the control loop and disables PWM gate signals.
This is the object method version. Sets loop flags to false and stops PWM via stop_gates_pwm.
| safetyLevelDef supercap_control_manager::safetyLevel |
Current system safety level status.