From 21012d9a4f986733a61ba1bedcfb94107417267d Mon Sep 17 00:00:00 2001 From: Local user Date: Mon, 4 May 2026 19:32:26 -0600 Subject: [PATCH 1/4] add untested airbrakes driver --- AirbrakesDriver/Inc/airbrakes.hpp | 45 ++++++++++ AirbrakesDriver/airbrakes.cpp | 139 ++++++++++++++++++++++++++++++ 2 files changed, 184 insertions(+) create mode 100644 AirbrakesDriver/Inc/airbrakes.hpp create mode 100644 AirbrakesDriver/airbrakes.cpp diff --git a/AirbrakesDriver/Inc/airbrakes.hpp b/AirbrakesDriver/Inc/airbrakes.hpp new file mode 100644 index 0000000..7495a20 --- /dev/null +++ b/AirbrakesDriver/Inc/airbrakes.hpp @@ -0,0 +1,45 @@ +#ifndef _AIRBRAKES_HPP_ +#define _AIRBRAKES_HPP_ + +#include "stm32g4xx.h" +#define AIRBRAKES_NUM_DEPLOYMENT_LEVELS 10 +#define AIRBRAKES_MAX_CURRENT_AMPS 1.0 + +class AirbrakesDriver { +public: + AirbrakesDriver(TIM_HandleTypeDef* servoPWMTimer, ADC_HandleTypeDef* servoADCHandle, + GPIO_TypeDef* servoENPort, uint16_t servoENPin, + GPIO_TypeDef* servoLatchResetPort, uint16_t servoLatchResetPin, + GPIO_TypeDef* comparatorPort, uint16_t comparatorPin); + + void Enable(); + void Disable(); + bool SetTargetLevel(uint8_t level); + bool SetTargetCurrent(float current); + uint32_t ReadRawADC(); + float ReadVoltsADC(); + bool Adjust(); + + +private: + TIM_HandleTypeDef* servoPWMTimer; + ADC_HandleTypeDef* servoADCHandle; + GPIO_TypeDef* servoENPort; + uint16_t servoENPin; + GPIO_TypeDef* servoLatchResetPort; + uint16_t servoLatchResetPin; + GPIO_TypeDef* comparatorPort; + uint16_t comparatorPin; + + float targetVoltage = 0; + + float ADCVoltsToCurrent(float v) const; + float CurrentToADCVolts(float c) const; + + bool CheckComparatorGood() const; + + float currentDutyCycle = 0; + +}; + +#endif diff --git a/AirbrakesDriver/airbrakes.cpp b/AirbrakesDriver/airbrakes.cpp new file mode 100644 index 0000000..2a61c30 --- /dev/null +++ b/AirbrakesDriver/airbrakes.cpp @@ -0,0 +1,139 @@ +#include "airbrakes.hpp" + +// The PWM timer is a handle to whatever timer controls the PWM output pin (e.g. "&htim3") +// The ADC timer is a handle to whatever ADC controls the servo ADC input pin (e.g. "&hadc2"); +AirbrakesDriver::AirbrakesDriver(TIM_HandleTypeDef* servoPWMTimerHandle, + ADC_HandleTypeDef* servoADCHandle, GPIO_TypeDef* servoENPort, uint16_t servoENPin, + GPIO_TypeDef* servoLatchResetPort, uint16_t servoLatchResetPin, + GPIO_TypeDef* comparatorPort, uint16_t comparatorPin) : servoPWMTimer(servoPWMTimerHandle), servoADCHandle(servoADCHandle), + servoENPort(servoENPort),servoENPin(servoENPin),servoLatchResetPort(servoLatchResetPort),servoLatchResetPin(servoLatchResetPin), + comparatorPort(comparatorPort),comparatorPin(comparatorPin){ + + HAL_GPIO_WritePin(servoLatchResetPort, servoLatchResetPin, GPIO_PIN_RESET); // put SR latch in known position + Disable(); +} + +/* @brief Enables the driver. Starts ADC sampling and PWM output. + * Resets current latch and monitors for runaway current for 250ms. + */ +void AirbrakesDriver::Enable() { + HAL_TIM_PWM_Start(servoPWMTimer, TIM_CHANNEL_1); + HAL_ADC_Start(servoADCHandle); + HAL_GPIO_WritePin(servoENPort, servoENPin, GPIO_PIN_SET); + HAL_GPIO_WritePin(servoLatchResetPort, servoLatchResetPin, GPIO_PIN_SET); + HAL_Delay(10); + HAL_GPIO_WritePin(servoLatchResetPort, servoLatchResetPin, GPIO_PIN_RESET); + // Immediately stop if current starts running away + for(uint16_t i = 0; i < 250; i++) { + if(!CheckComparatorGood()) { + Disable(); + return; + } + HAL_Delay(1); + } +} + +/* @brief Disables the driver. Stops ADC sampling and PWM output and disables current. + */ +void AirbrakesDriver::Disable() { + HAL_GPIO_WritePin(servoENPort, servoENPin, GPIO_PIN_RESET); + HAL_TIM_PWM_Stop(servoPWMTimer, TIM_CHANNEL_1); + HAL_ADC_Stop(servoADCHandle); + HAL_GPIO_WritePin(servoLatchResetPort, servoLatchResetPin, GPIO_PIN_RESET); +} + +/* @brief Set the airbrake PWM level from fully off to fully on. + * @param level The airbrake level from 0 to (AIRBRAKES_NUM_DEPLOYMENT_LEVELS-1) inclusive. For example, if there are 10 levels, accepts 0-9. + * @return true if successful. + */ +bool AirbrakesDriver::SetTargetLevel(uint8_t level) { + if(level >= AIRBRAKES_NUM_DEPLOYMENT_LEVELS) { + return false; + } + return SetTargetCurrent(((float)AIRBRAKES_MAX_CURRENT_AMPS)*level/(AIRBRAKES_NUM_DEPLOYMENT_LEVELS-1)); +} + +/* @brief Set the airbrake target current directly. + * @param current The current in amps to request. + * @return true if successful. + */ +bool AirbrakesDriver::SetTargetCurrent(float current) { + + float targetvoltcalc = CurrentToADCVolts(current); + if(targetvoltcalc > 3.3 || targetvoltcalc < 0) { + return false; + } + targetVoltage = targetvoltcalc; + return true; +} + +/* @brief Read the ADC value in raw counts. + * @return The value in counts from 0 to the max value of the ADC inclusive (4095 for 12-bit resolution). + */ +uint32_t AirbrakesDriver::ReadRawADC() { + return HAL_ADC_GetValue(servoADCHandle); +} + +/* @brief Read the ADC value in voltage assuming 12-bit resolution. + * @return The ADC value in volts. + */ +float AirbrakesDriver::ReadVoltsADC() { + return float(ReadRawADC())/((1<<12)-1)*3.3f; +} + +/* @brief Run the active current ramping loop. Will smooth PWM changes and check latch status. + * @return true if successful. false if PWM either hits the rails or the current comparator trips. + */ +bool AirbrakesDriver::Adjust() { + + if(HAL_GPIO_ReadPin(comparatorPort, comparatorPin) == GPIO_PIN_SET) { + Disable(); + return false; + } + float currentV = ReadVoltsADC(); + float diff = (targetVoltage-currentV); + + // if we're trying to force the pwm beyond 100% or 0% even though it's already there return false + if((currentDutyCycle >= 1.0 && diff > 0) || (currentDutyCycle <= 0.0 && diff < 0)) { + return false; + } + + currentDutyCycle += diff * 0.1; + if(currentDutyCycle > 1.0) { + currentDutyCycle = 1.0; + } + else if(currentDutyCycle < 0.0) { + currentDutyCycle = 0.0; + } + + servoPWMTimer->Instance->CCR1 = servoPWMTimer->Instance->ARR * currentDutyCycle; + + return true; + +} + +/* @brief Converts a voltage measured by the ADC into the corresponding current through the servo + * Assumes 0.132V/A from the ACS725LLCTR-10AB datasheet + * @param v Voltage to convert (V) + * @return Calculated servo current (A) + */ +float AirbrakesDriver::ADCVoltsToCurrent(float v) const { + return (v-1.6)/0.132; +} + +/* @brief Converts a current through the servo into the corresponding voltage measured by the ADC + * Assumes 0.132V/A from the ACS725LLCTR-10AB datasheet + * @param c Current to convert (A) + * @return Calculated ADC voltage (V) + */ +float AirbrakesDriver::CurrentToADCVolts(float c) const { + return c*0.132+1.6; +} + +/* @brief Checks the state of the hardware failsafe latch. + * @return true if the latch is good, i.e. current limit has not been triggered + */ +bool AirbrakesDriver::CheckComparatorGood() const { + + return HAL_GPIO_ReadPin(comparatorPort, comparatorPin) == GPIO_PIN_RESET; +} From ae1d04b2241b99c563ee52bdc002780f960ea202 Mon Sep 17 00:00:00 2001 From: Local user Date: Mon, 4 May 2026 20:44:47 -0600 Subject: [PATCH 2/4] added airbrakes driver and fixed an OSD chip include --- AirbrakesDriver/Inc/airbrakes.hpp | 20 ++++++++++-- AirbrakesDriver/airbrakes.cpp | 51 ++++++++++++++++--------------- MAX7456/MAX7456.cpp | 6 ++-- MAX7456/MAX7456.hpp | 6 ++-- 4 files changed, 49 insertions(+), 34 deletions(-) diff --git a/AirbrakesDriver/Inc/airbrakes.hpp b/AirbrakesDriver/Inc/airbrakes.hpp index 7495a20..394359e 100644 --- a/AirbrakesDriver/Inc/airbrakes.hpp +++ b/AirbrakesDriver/Inc/airbrakes.hpp @@ -3,7 +3,7 @@ #include "stm32g4xx.h" #define AIRBRAKES_NUM_DEPLOYMENT_LEVELS 10 -#define AIRBRAKES_MAX_CURRENT_AMPS 1.0 +#define AIRBRAKES_MAX_CURRENT_AMPS 3.0 class AirbrakesDriver { public: @@ -15,11 +15,15 @@ class AirbrakesDriver { void Enable(); void Disable(); bool SetTargetLevel(uint8_t level); - bool SetTargetCurrent(float current); + bool SetTargetDutyCycle(float current); uint32_t ReadRawADC(); float ReadVoltsADC(); bool Adjust(); + inline bool IsEnabled() const { + return enabled; + } + private: TIM_HandleTypeDef* servoPWMTimer; @@ -31,15 +35,25 @@ class AirbrakesDriver { GPIO_TypeDef* comparatorPort; uint16_t comparatorPin; - float targetVoltage = 0; + float targetDutyCycle = 0; float ADCVoltsToCurrent(float v) const; float CurrentToADCVolts(float c) const; + bool CurrentGood(); bool CheckComparatorGood() const; float currentDutyCycle = 0; + static inline uint32_t round(float v) { + if(v > 0) + return static_cast(v+0.5f); + else + return static_cast(v-0.5f); + } + + bool enabled = false; + }; #endif diff --git a/AirbrakesDriver/airbrakes.cpp b/AirbrakesDriver/airbrakes.cpp index 2a61c30..1c2bf33 100644 --- a/AirbrakesDriver/airbrakes.cpp +++ b/AirbrakesDriver/airbrakes.cpp @@ -25,12 +25,13 @@ void AirbrakesDriver::Enable() { HAL_GPIO_WritePin(servoLatchResetPort, servoLatchResetPin, GPIO_PIN_RESET); // Immediately stop if current starts running away for(uint16_t i = 0; i < 250; i++) { - if(!CheckComparatorGood()) { + if(!CurrentGood()) { Disable(); return; } HAL_Delay(1); } + enabled = true; } /* @brief Disables the driver. Stops ADC sampling and PWM output and disables current. @@ -40,9 +41,10 @@ void AirbrakesDriver::Disable() { HAL_TIM_PWM_Stop(servoPWMTimer, TIM_CHANNEL_1); HAL_ADC_Stop(servoADCHandle); HAL_GPIO_WritePin(servoLatchResetPort, servoLatchResetPin, GPIO_PIN_RESET); + enabled = false; } -/* @brief Set the airbrake PWM level from fully off to fully on. +/* @brief Set the airbrake level from fully off to fully on. * @param level The airbrake level from 0 to (AIRBRAKES_NUM_DEPLOYMENT_LEVELS-1) inclusive. For example, if there are 10 levels, accepts 0-9. * @return true if successful. */ @@ -50,20 +52,20 @@ bool AirbrakesDriver::SetTargetLevel(uint8_t level) { if(level >= AIRBRAKES_NUM_DEPLOYMENT_LEVELS) { return false; } - return SetTargetCurrent(((float)AIRBRAKES_MAX_CURRENT_AMPS)*level/(AIRBRAKES_NUM_DEPLOYMENT_LEVELS-1)); + + return SetTargetDutyCycle(static_cast(level)/(AIRBRAKES_NUM_DEPLOYMENT_LEVELS-1)); } -/* @brief Set the airbrake target current directly. - * @param current The current in amps to request. +/* @brief Set the airbrake target duty cycle directly. + * @param dutyFrac Duty cycle between 0.0 and 1.0. * @return true if successful. */ -bool AirbrakesDriver::SetTargetCurrent(float current) { +bool AirbrakesDriver::SetTargetDutyCycle(float dutyFrac) { - float targetvoltcalc = CurrentToADCVolts(current); - if(targetvoltcalc > 3.3 || targetvoltcalc < 0) { + if(dutyFrac > 1.0f || dutyFrac < 0.0f) { return false; } - targetVoltage = targetvoltcalc; + targetDutyCycle = dutyFrac; return true; } @@ -82,31 +84,22 @@ float AirbrakesDriver::ReadVoltsADC() { } /* @brief Run the active current ramping loop. Will smooth PWM changes and check latch status. - * @return true if successful. false if PWM either hits the rails or the current comparator trips. + * @return true if successful. false if the current exceeds limits or the driver is disabled. */ bool AirbrakesDriver::Adjust() { - if(HAL_GPIO_ReadPin(comparatorPort, comparatorPin) == GPIO_PIN_SET) { + if(!CurrentGood() || !IsEnabled()) { Disable(); return false; } - float currentV = ReadVoltsADC(); - float diff = (targetVoltage-currentV); - // if we're trying to force the pwm beyond 100% or 0% even though it's already there return false - if((currentDutyCycle >= 1.0 && diff > 0) || (currentDutyCycle <= 0.0 && diff < 0)) { - return false; - } - currentDutyCycle += diff * 0.1; - if(currentDutyCycle > 1.0) { - currentDutyCycle = 1.0; - } - else if(currentDutyCycle < 0.0) { - currentDutyCycle = 0.0; - } - servoPWMTimer->Instance->CCR1 = servoPWMTimer->Instance->ARR * currentDutyCycle; + float diff = targetDutyCycle - currentDutyCycle; + + currentDutyCycle += diff*0.1; + + servoPWMTimer->Instance->CCR1 = round(servoPWMTimer->Instance->ARR * currentDutyCycle); return true; @@ -130,6 +123,14 @@ float AirbrakesDriver::CurrentToADCVolts(float c) const { return c*0.132+1.6; } +/* @brief Checks that the hardware failsafe has not triggered and the measured current is within limits. + * @return true is current is safely within range. + */ +bool AirbrakesDriver::CurrentGood() { + return CheckComparatorGood() && (ADCVoltsToCurrent(ReadVoltsADC()) <= AIRBRAKES_MAX_CURRENT_AMPS); +} + + /* @brief Checks the state of the hardware failsafe latch. * @return true if the latch is good, i.e. current limit has not been triggered */ diff --git a/MAX7456/MAX7456.cpp b/MAX7456/MAX7456.cpp index 7482b21..9c5505a 100644 --- a/MAX7456/MAX7456.cpp +++ b/MAX7456/MAX7456.cpp @@ -51,7 +51,7 @@ void MAX7456::_OSD_WriteReg(uint8_t addr, uint8_t val) { HAL_GPIO_WritePin(csport, cspin, GPIO_PIN_SET); HAL_GPIO_WritePin(csport, cspin, GPIO_PIN_RESET); const uint8_t data[2] = {(uint8_t)(addr & 0b01111111),val}; - HAL_SPI_Transmit(&hspi2, data, 2, 1000); + HAL_SPI_Transmit(hspi, data, 2, 1000); HAL_GPIO_WritePin(csport, cspin, GPIO_PIN_SET); } @@ -65,7 +65,7 @@ uint8_t MAX7456::_OSD_ReadReg(uint8_t addr) { HAL_Delay(1); const uint8_t data[2] = {(uint8_t)(addr | 0b10000000),0x00}; uint8_t rxdata[2] = {0x00,0x00}; - if(HAL_SPI_TransmitReceive(&hspi2, data, rxdata, 2, 1000) != HAL_OK) { + if(HAL_SPI_TransmitReceive(hspi, data, rxdata, 2, 1000) != HAL_OK) { HAL_GPIO_WritePin(csport, cspin, GPIO_PIN_SET); return 0x00; } @@ -267,6 +267,6 @@ void MAX7456::OSD_DrawLogo(uint8_t startCharIndex, uint8_t x, uint8_t y, uint8_t } -MAX7456::MAX7456(GPIO_TypeDef* csgpio, uint16_t cspin) : csport(csgpio),cspin(cspin) { +MAX7456::MAX7456(GPIO_TypeDef* csgpio, uint16_t cspin, SPI_HandleTypeDef* hspi) : csport(csgpio),cspin(cspin),hspi(hspi) { } diff --git a/MAX7456/MAX7456.hpp b/MAX7456/MAX7456.hpp index aa035ef..ed1d4e0 100644 --- a/MAX7456/MAX7456.hpp +++ b/MAX7456/MAX7456.hpp @@ -8,8 +8,7 @@ #ifndef INC_WET_OIL_H_ #define INC_WET_OIL_H_ -#include "gpio.h" -#include "spi.h" +#include "stm32g4xx.h" @@ -74,7 +73,7 @@ class MAX7456 { public: - MAX7456(GPIO_TypeDef* csgpio, uint16_t cspin); + MAX7456(GPIO_TypeDef* csgpio, uint16_t cspin, SPI_HandleTypeDef* hspi); enum OSD_STANDARD { OSD_STANDARD_NTSC, OSD_STANDARD_PAL @@ -178,6 +177,7 @@ class MAX7456 { GPIO_TypeDef* csport; const uint16_t cspin; + SPI_HandleTypeDef* hspi; }; From 4fc338528f2566b4e20724e503c66713c277bf66 Mon Sep 17 00:00:00 2001 From: Local user Date: Tue, 5 May 2026 19:21:04 -0600 Subject: [PATCH 3/4] smoothed out servo pwm to not instantly trip the current detector now calcs min and max pulse from servo datasheet takes timer hz value to calculate the above --- AirbrakesDriver/Inc/airbrakes.hpp | 6 +++- AirbrakesDriver/airbrakes.cpp | 50 +++++++++++++++++++++++++++---- 2 files changed, 49 insertions(+), 7 deletions(-) diff --git a/AirbrakesDriver/Inc/airbrakes.hpp b/AirbrakesDriver/Inc/airbrakes.hpp index 394359e..21023d2 100644 --- a/AirbrakesDriver/Inc/airbrakes.hpp +++ b/AirbrakesDriver/Inc/airbrakes.hpp @@ -10,7 +10,7 @@ class AirbrakesDriver { AirbrakesDriver(TIM_HandleTypeDef* servoPWMTimer, ADC_HandleTypeDef* servoADCHandle, GPIO_TypeDef* servoENPort, uint16_t servoENPin, GPIO_TypeDef* servoLatchResetPort, uint16_t servoLatchResetPin, - GPIO_TypeDef* comparatorPort, uint16_t comparatorPin); + GPIO_TypeDef* comparatorPort, uint16_t comparatorPin, float timerHz); void Enable(); void Disable(); @@ -44,6 +44,7 @@ class AirbrakesDriver { bool CheckComparatorGood() const; float currentDutyCycle = 0; + float vel = 0.0; static inline uint32_t round(float v) { if(v > 0) @@ -54,6 +55,9 @@ class AirbrakesDriver { bool enabled = false; + const float hz; + + }; #endif diff --git a/AirbrakesDriver/airbrakes.cpp b/AirbrakesDriver/airbrakes.cpp index 1c2bf33..fa412f4 100644 --- a/AirbrakesDriver/airbrakes.cpp +++ b/AirbrakesDriver/airbrakes.cpp @@ -1,13 +1,14 @@ #include "airbrakes.hpp" +#include // The PWM timer is a handle to whatever timer controls the PWM output pin (e.g. "&htim3") // The ADC timer is a handle to whatever ADC controls the servo ADC input pin (e.g. "&hadc2"); AirbrakesDriver::AirbrakesDriver(TIM_HandleTypeDef* servoPWMTimerHandle, ADC_HandleTypeDef* servoADCHandle, GPIO_TypeDef* servoENPort, uint16_t servoENPin, GPIO_TypeDef* servoLatchResetPort, uint16_t servoLatchResetPin, - GPIO_TypeDef* comparatorPort, uint16_t comparatorPin) : servoPWMTimer(servoPWMTimerHandle), servoADCHandle(servoADCHandle), + GPIO_TypeDef* comparatorPort, uint16_t comparatorPin, float timerHz) : servoPWMTimer(servoPWMTimerHandle), servoADCHandle(servoADCHandle), servoENPort(servoENPort),servoENPin(servoENPin),servoLatchResetPort(servoLatchResetPort),servoLatchResetPin(servoLatchResetPin), - comparatorPort(comparatorPort),comparatorPin(comparatorPin){ + comparatorPort(comparatorPort),comparatorPin(comparatorPin),hz(timerHz){ HAL_GPIO_WritePin(servoLatchResetPort, servoLatchResetPin, GPIO_PIN_RESET); // put SR latch in known position Disable(); @@ -19,10 +20,19 @@ AirbrakesDriver::AirbrakesDriver(TIM_HandleTypeDef* servoPWMTimerHandle, void AirbrakesDriver::Enable() { HAL_TIM_PWM_Start(servoPWMTimer, TIM_CHANNEL_1); HAL_ADC_Start(servoADCHandle); + + HAL_GPIO_WritePin(servoLatchResetPort, servoLatchResetPin, GPIO_PIN_SET); + HAL_Delay(10); + HAL_GPIO_WritePin(servoLatchResetPort, servoLatchResetPin, GPIO_PIN_RESET); + HAL_GPIO_WritePin(servoENPort, servoENPin, GPIO_PIN_SET); + HAL_GPIO_WritePin(servoLatchResetPort, servoLatchResetPin, GPIO_PIN_SET); HAL_Delay(10); HAL_GPIO_WritePin(servoLatchResetPort, servoLatchResetPin, GPIO_PIN_RESET); + + HAL_Delay(10); + // Immediately stop if current starts running away for(uint16_t i = 0; i < 250; i++) { if(!CurrentGood()) { @@ -53,7 +63,7 @@ bool AirbrakesDriver::SetTargetLevel(uint8_t level) { return false; } - return SetTargetDutyCycle(static_cast(level)/(AIRBRAKES_NUM_DEPLOYMENT_LEVELS-1)); + return SetTargetDutyCycle(static_cast(level)/(AIRBRAKES_NUM_DEPLOYMENT_LEVELS-1)*(0.0025*hz-0.0005*hz)+0.0005*hz); } /* @brief Set the airbrake target duty cycle directly. @@ -94,10 +104,35 @@ bool AirbrakesDriver::Adjust() { } + const static float MAX_VELOCITY = 0.04; + const static float MAX_ACCEL = 0.0007; + + float distance = targetDutyCycle - currentDutyCycle; + float ideal_vel = sqrtf(2.0 * MAX_ACCEL * fabsf(distance))-MAX_ACCEL; + + if (distance < 0) { + ideal_vel = -ideal_vel; + } - float diff = targetDutyCycle - currentDutyCycle; + if (ideal_vel > MAX_VELOCITY) { + ideal_vel = MAX_VELOCITY; + } + else if (ideal_vel < -MAX_VELOCITY) { + ideal_vel = -MAX_VELOCITY; + } - currentDutyCycle += diff*0.1; + float vel_error = ideal_vel - vel; + if (vel_error > MAX_ACCEL) { + vel += MAX_ACCEL; + } + else if (vel_error < -MAX_ACCEL) { + vel -= MAX_ACCEL; + } + else { + vel = ideal_vel; + } + + currentDutyCycle += vel; servoPWMTimer->Instance->CCR1 = round(servoPWMTimer->Instance->ARR * currentDutyCycle); @@ -127,6 +162,7 @@ float AirbrakesDriver::CurrentToADCVolts(float c) const { * @return true is current is safely within range. */ bool AirbrakesDriver::CurrentGood() { + //return CheckComparatorGood(); return CheckComparatorGood() && (ADCVoltsToCurrent(ReadVoltsADC()) <= AIRBRAKES_MAX_CURRENT_AMPS); } @@ -136,5 +172,7 @@ bool AirbrakesDriver::CurrentGood() { */ bool AirbrakesDriver::CheckComparatorGood() const { - return HAL_GPIO_ReadPin(comparatorPort, comparatorPin) == GPIO_PIN_RESET; + return HAL_GPIO_ReadPin(comparatorPort, comparatorPin) == GPIO_PIN_SET; } + + From 8af17c3d5e3c917c096278dd96f33948b44098db Mon Sep 17 00:00:00 2001 From: Local user Date: Wed, 6 May 2026 19:36:57 -0600 Subject: [PATCH 4/4] renamed Adjust to TickControlLoop --- AirbrakesDriver/Inc/airbrakes.hpp | 2 +- AirbrakesDriver/airbrakes.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/AirbrakesDriver/Inc/airbrakes.hpp b/AirbrakesDriver/Inc/airbrakes.hpp index 21023d2..9ec3b31 100644 --- a/AirbrakesDriver/Inc/airbrakes.hpp +++ b/AirbrakesDriver/Inc/airbrakes.hpp @@ -18,7 +18,7 @@ class AirbrakesDriver { bool SetTargetDutyCycle(float current); uint32_t ReadRawADC(); float ReadVoltsADC(); - bool Adjust(); + bool TickControlLoop(); inline bool IsEnabled() const { return enabled; diff --git a/AirbrakesDriver/airbrakes.cpp b/AirbrakesDriver/airbrakes.cpp index fa412f4..4c51d22 100644 --- a/AirbrakesDriver/airbrakes.cpp +++ b/AirbrakesDriver/airbrakes.cpp @@ -96,7 +96,7 @@ float AirbrakesDriver::ReadVoltsADC() { /* @brief Run the active current ramping loop. Will smooth PWM changes and check latch status. * @return true if successful. false if the current exceeds limits or the driver is disabled. */ -bool AirbrakesDriver::Adjust() { +bool AirbrakesDriver::TickControlLoop() { if(!CurrentGood() || !IsEnabled()) { Disable();