Skip to content

Commit 15c8e85

Browse files
committed
feat: add equalizer and handsoff detection
1 parent 9fb72f4 commit 15c8e85

5 files changed

Lines changed: 323 additions & 32 deletions

File tree

Firmware/FFBoard/Inc/Axis.h

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@ struct AxisFlashAddresses
7272

7373
uint16_t speedAccelFilter = ADR_AXIS1_SPEEDACCEL_FILTER;
7474
uint16_t postprocess1 = ADR_AXIS1_POSTPROCESS1;
75+
// NOTE: The following addresses must be defined in constants.h
76+
uint16_t equalizer1 = ADR_AXIS1_EQ1;
77+
uint16_t equalizer2 = ADR_AXIS1_EQ2;
78+
uint16_t equalizer3 = ADR_AXIS1_EQ3;
79+
uint16_t handsOffConfig = ADR_AXIS1_HANDSOFF_CONF;
80+
uint16_t handsOffAccel = ADR_AXIS1_HANDSOFF_ACCEL;
7581
};
7682

7783
/**
@@ -120,7 +126,9 @@ enum class Axis_commands : uint32_t{
120126
maxspeed,slewrate,
121127
calibrate_maxSlewRateDrv,
122128
maxSlewRateDrv,
123-
expo,exposcale
129+
expo,exposcale,
130+
equalizer,eqb1,eqb2,eqb3,eqb4,eqb5,eqb6,
131+
handsoff, handsoff_speed, handsoff_accel
124132
};
125133

126134
/**
@@ -386,6 +394,12 @@ class Axis : public PersistentStorage, public CommandHandler, public ErrorHandle
386394
const float AXIS_INERTIA_RATIO = INTERNAL_SCALER_INERTIA * INTERNAL_AXIS_INERTIA_SCALER / 255.0;
387395

388396
// Private methods
397+
/**
398+
* @brief Sets the gain for a specific equalizer band.
399+
* @param band The equalizer band index (0-4).
400+
* @param gain The gain in 0.1 dB steps (-120 to 120).
401+
*/
402+
void setEqGain(uint8_t band, int8_t gain);
389403
/**
390404
* @brief Sets the degrees of rotation for the axis.
391405
* @param degrees The new range of rotation.
@@ -412,7 +426,7 @@ class Axis : public PersistentStorage, public CommandHandler, public ErrorHandle
412426
*/
413427
void setExpo(int val);
414428

415-
int32_t calculateExpoTorque(int32_t torque);
429+
float calculateExpoTorque(float torque);
416430
/**
417431
* @brief Applies the speed limiter PI controller to the torque.
418432
* @param torque A reference to the torque value to be modified.
@@ -436,6 +450,10 @@ class Axis : public PersistentStorage, public CommandHandler, public ErrorHandle
436450
*/
437451
static uint16_t encodeConfToInt(AxisConfig conf);
438452

453+
/**
454+
* @brief Checks if the user has let go of the wheel and updates the torque accordingly.
455+
*/
456+
void updateHandsOffState();
439457

440458

441459
// Member variables
@@ -525,11 +543,27 @@ class Axis : public PersistentStorage, public CommandHandler, public ErrorHandle
525543
Biquad frictionFilter = Biquad(BiquadType::lowpass, filterFrictionCst.freq/filter_f, filterFrictionCst.q / 100.0, 0.0);
526544
Biquad inertiaFilter = Biquad(BiquadType::lowpass, filterInertiaCst.freq/filter_f, filterInertiaCst.q / 100.0, 0.0);
527545

546+
// Equalizer
547+
static const uint8_t num_eq_bands = 6;
548+
const std::array<uint16_t, num_eq_bands> eq_frequencies = {10, 15, 25, 40, 60, 100};
549+
std::array<Biquad, num_eq_bands> eqFilters;
550+
std::array<int8_t, num_eq_bands> eqGains = {0,0,0,0,0}; // Gains from -120 to 120, represents gain in dB * 10
551+
bool equalizerEnabled = false; //!< Enable/disable the equalizer.
552+
528553
// Post-processing
529554
GearRatio_t gearRatio; //!< Gear ratio between encoder and axis.
530555
int expoValue = 0; //!< Raw integer value for the expo curve. Formula: v = val*2 => v<0 ? 1/-v : v
531556
float expo = 1; //!< Calculated exponent for the torque curve.
532557
float expoScaler = 50; //!< Scaler for the expo calculation : 0.28 to 3.54
558+
559+
// Hands-off detection
560+
bool handsOffCheckEnabled = false;
561+
float handsOffAccelThreshold = 0.1;
562+
uint16_t handsOffSpeedThreshold = 720; // deg/s
563+
bool handsOff = false;
564+
float accel_buffer[16] = {0};
565+
uint8_t accel_buffer_idx = 0;
566+
uint32_t handsOffTimer = 0;
533567
};
534568

535569
#endif /* SRC_AXIS_H_ */

0 commit comments

Comments
 (0)