dualsense_tools/tilt_estimator/config.rs
1/// Configuration for a [crate::TiltEstimator]; the `SAMPLES` constant will determine
2/// how big a buffer of accelerometer readings to keep in order to compute
3/// the accelerometer's average over time.
4#[derive(Copy, Clone, Debug, PartialEq)]
5pub struct TiltEstimatorConfig<const SAMPLES: usize> {
6 /// Value in [0..1] where 0 is purely accelerometer and 1 purely integrated gyro
7 pub correction_alpha: f32,
8 /// Used to scale the gyro force strenght when integrating gyro values
9 pub integration_alpha: f32,
10 /// Whether to integrate gyro values or only use accelerometer averages
11 pub use_gyro_integration: bool,
12}
13
14impl<const SAMPLES: usize> TiltEstimatorConfig<SAMPLES> {
15 pub fn new() -> TiltEstimatorConfig<SAMPLES> {
16 TiltEstimatorConfig::<SAMPLES>::default()
17 }
18}
19
20impl<const N: usize> Default for TiltEstimatorConfig<N> {
21 fn default() -> Self {
22 Self {
23 // Give more weight to the accelerometer as less noisy overall
24 correction_alpha: 0.25,
25 // Dampen gyroscope to avoid overshooting/instability
26 integration_alpha: 0.7,
27 // Enable gyro integration to strive for both reactivity and precision
28 use_gyro_integration: true,
29 }
30 }
31}