@@ -71,6 +71,12 @@ struct AxisFlashAddresses
7171
7272 uint16_t speedAccelFilter = ADR_AXIS1_SPEEDACCEL_FILTER;
7373 uint16_t postprocess1 = ADR_AXIS1_POSTPROCESS1;
74+ // NOTE: The following addresses must be defined in constants.h
75+ uint16_t equalizer1 = ADR_AXIS1_EQ1;
76+ uint16_t equalizer2 = ADR_AXIS1_EQ2;
77+ uint16_t equalizer3 = ADR_AXIS1_EQ3;
78+ uint16_t handsOffConfig = ADR_AXIS1_HANDSOFF_CONF;
79+ uint16_t handsOffAccel = ADR_AXIS1_HANDSOFF_ACCEL;
7480};
7581
7682/* *
@@ -119,7 +125,9 @@ enum class Axis_commands : uint32_t{
119125 maxspeed,slewrate,
120126 calibrate_maxSlewRateDrv,
121127 maxSlewRateDrv,
122- expo,exposcale
128+ expo,exposcale,
129+ equalizer,eqb1,eqb2,eqb3,eqb4,eqb5,eqb6,
130+ handsoff, handsoff_speed, handsoff_accel
123131};
124132
125133/* *
@@ -385,6 +393,12 @@ class Axis : public PersistentStorage, public CommandHandler, public ErrorHandle
385393 const float AXIS_INERTIA_RATIO = INTERNAL_SCALER_INERTIA * INTERNAL_AXIS_INERTIA_SCALER / 255.0 ;
386394
387395 // Private methods
396+ /* *
397+ * @brief Sets the gain for a specific equalizer band.
398+ * @param band The equalizer band index (0-4).
399+ * @param gain The gain in 0.1 dB steps (-120 to 120).
400+ */
401+ void setEqGain (uint8_t band, int8_t gain);
388402 /* *
389403 * @brief Sets the degrees of rotation for the axis.
390404 * @param degrees The new range of rotation.
@@ -411,7 +425,7 @@ class Axis : public PersistentStorage, public CommandHandler, public ErrorHandle
411425 */
412426 void setExpo (int val);
413427
414- int32_t calculateExpoTorque (int32_t torque);
428+ float calculateExpoTorque (float torque);
415429 /* *
416430 * @brief Applies the speed limiter PI controller to the torque.
417431 * @param torque A reference to the torque value to be modified.
@@ -435,6 +449,10 @@ class Axis : public PersistentStorage, public CommandHandler, public ErrorHandle
435449 */
436450 static uint16_t encodeConfToInt (AxisConfig conf);
437451
452+ /* *
453+ * @brief Checks if the user has let go of the wheel and updates the torque accordingly.
454+ */
455+ void updateHandsOffState ();
438456
439457
440458 // Member variables
@@ -524,11 +542,27 @@ class Axis : public PersistentStorage, public CommandHandler, public ErrorHandle
524542 Biquad frictionFilter = Biquad(BiquadType::lowpass, filterFrictionCst.freq/filter_f, filterFrictionCst.q / 100.0 , 0.0 );
525543 Biquad inertiaFilter = Biquad(BiquadType::lowpass, filterInertiaCst.freq/filter_f, filterInertiaCst.q / 100.0 , 0.0 );
526544
545+ // Equalizer
546+ static const uint8_t num_eq_bands = 6 ;
547+ const std::array<uint16_t , num_eq_bands> eq_frequencies = {10 , 15 , 25 , 40 , 60 , 100 };
548+ std::array<Biquad, num_eq_bands> eqFilters;
549+ std::array<int8_t , num_eq_bands> eqGains = {0 ,0 ,0 ,0 ,0 }; // Gains from -120 to 120, represents gain in dB * 10
550+ bool equalizerEnabled = false ; // !< Enable/disable the equalizer.
551+
527552 // Post-processing
528553 GearRatio_t gearRatio; // !< Gear ratio between encoder and axis.
529554 int expoValue = 0 ; // !< Raw integer value for the expo curve. Formula: v = val*2 => v<0 ? 1/-v : v
530555 float expo = 1 ; // !< Calculated exponent for the torque curve.
531556 float expoScaler = 50 ; // !< Scaler for the expo calculation : 0.28 to 3.54
557+
558+ // Hands-off detection
559+ bool handsOffCheckEnabled = false ;
560+ float handsOffAccelThreshold = 0.1 ;
561+ uint16_t handsOffSpeedThreshold = 720 ; // deg/s
562+ bool handsOff = false ;
563+ float accel_buffer[16 ] = {0 };
564+ uint8_t accel_buffer_idx = 0 ;
565+ uint32_t handsOffTimer = 0 ;
532566};
533567
534568#endif /* SRC_AXIS_H_ */
0 commit comments