Avalon Firmware
 
Loading...
Searching...
No Matches
supercap_control_manager Class Reference

Main control class for managing the supercapacitor charge/discharge behavior. More...

#include <supercap_controllers.hpp>

Inheritance diagram for supercap_control_manager:
adc_manager

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.
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ supercap_control_manager()

supercap_control_manager::supercap_control_manager ( ADC_HandleTypeDef * adc_cap,
ADC_HandleTypeDef * adc_bat,
ADC_HandleTypeDef * adc_temp )
inline

Constructor for the supercap controller.

Parameters
adc_capPointer to ADC for supercap measurements
adc_batPointer to ADC for battery-side measurements
adc_tempPointer to ADC used for temperature sensing

◆ ~supercap_control_manager()

supercap_control_manager::~supercap_control_manager ( )
inline

Destructor (default)

Member Function Documentation

◆ all_safety_checks()

void supercap_control_manager::all_safety_checks ( )

Executes all defined safety checks (voltage, current).

◆ init_loop()

HAL_StatusTypeDef supercap_control_manager::init_loop ( )

Initializes the control loop by setting up the PID controllers.

Initializes the supercapacitor control loop.

Returns
HAL_OK if setup is successful

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.

Returns
HAL_OK if initialization was successful.

◆ loop_update()

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.

Parameters
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

◆ set_ref_chassis_power()

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.

Parameters
ref_power_The power target.

Used by the application layer to define the desired output power level that the control system should regulate around.

Parameters
ref_power_Desired chassis power reference in watts.

◆ setup_pid_controllers()

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:

  • pid[0]: Battery power control loop (P_bat)
  • pid[2]: Supercapacitor current control loop (I_capa)
  • pid[3]: Supercap upper voltage limit clamp (V_cap_max)
  • pid[4]: Supercap lower voltage limit clamp (V_cap_min)

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.

◆ silent_mode()

void supercap_control_manager::silent_mode ( )

Manually forces system into a silent mode (e.g., for emergency recovery).

◆ start_gates_pwm()

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.

Parameters
init_duty_cycleDuty ratio to apply
Returns
HAL_OK if successful

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.

Parameters
init_duty_cycleThe duty cycle to start with, based on Vcap / Vbat ratio.
Returns
HAL_OK if HRTIM started successfully.

◆ start_loop()

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.

Returns
HAL_OK on success, HAL_ERROR otherwise

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.

Returns
HAL_OK if started successfully, HAL_ERROR otherwise.

◆ stop_loop()

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.

Field Documentation

◆ safetyLevel

safetyLevelDef supercap_control_manager::safetyLevel

Current system safety level status.


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