@@ -27,6 +27,19 @@ void remote_init(Remote *remote) {
2727
2828void remote_configure (Remote * remote , const RefloatConfig * config ) {
2929 remote -> step_size = config -> inputtilt_speed / config -> hertz ;
30+ smooth_target_configure (
31+ & remote -> smooth_target ,
32+ & config -> target_filter ,
33+ config -> inputtilt_speed ,
34+ config -> inputtilt_speed ,
35+ config -> hertz
36+ );
37+ ema_filter_configure (
38+ & remote -> ema_target ,
39+ & config -> target_filter ,
40+ config -> inputtilt_speed ,
41+ config -> inputtilt_speed
42+ );
3043}
3144
3245void remote_input (Remote * remote , const RefloatConfig * config ) {
@@ -67,37 +80,45 @@ void remote_input(Remote *remote, const RefloatConfig *config) {
6780 remote -> input = value ;
6881}
6982
70- void remote_update (Remote * remote , const State * state , const RefloatConfig * config ) {
83+ void remote_update (Remote * remote , const State * state , const RefloatConfig * config , float dt ) {
7184 float target = remote -> input * config -> inputtilt_angle_limit ;
7285
7386 if (state -> darkride ) {
7487 target = - target ;
7588 }
7689
77- float target_diff = target - remote -> setpoint ;
90+ if (config -> target_filter .it_type == SFT_EMA3 ) {
91+ ema_filter_update (& remote -> ema_target , target , dt );
92+ remote -> setpoint = remote -> ema_target .value ;
93+ } else if (config -> target_filter .it_type == SFT_THREE_STAGE ) {
94+ smooth_target_update (& remote -> smooth_target , target );
95+ remote -> setpoint = remote -> smooth_target .value ;
96+ } else {
97+ float target_diff = target - remote -> setpoint ;
7898
79- // Smoothen changes in tilt angle by ramping the step size
80- const float smoothing_factor = 0.02 ;
99+ // Smoothen changes in tilt angle by ramping the step size
100+ const float smoothing_factor = 0.02 ;
81101
82- // Within X degrees of Target Angle, start ramping down step size
83- if (fabsf (target_diff ) < 2.0f ) {
84- // Target step size is reduced the closer to center you are (needed for smoothly
85- // transitioning away from center)
86- remote -> ramped_step_size = smoothing_factor * remote -> step_size * target_diff / 2 +
87- (1 - smoothing_factor ) * remote -> ramped_step_size ;
88- // Linearly ramped down step size is provided as minimum to prevent overshoot
89- float centering_step_size =
90- fminf (fabsf (remote -> ramped_step_size ), fabsf (target_diff / 2 ) * remote -> step_size ) *
91- sign (target_diff );
92- if (fabsf (target_diff ) < fabsf (centering_step_size )) {
93- remote -> setpoint = target ;
102+ // Within X degrees of Target Angle, start ramping down step size
103+ if (fabsf (target_diff ) < 2.0f ) {
104+ // Target step size is reduced the closer to center you are (needed for smoothly
105+ // transitioning away from center)
106+ remote -> ramped_step_size = smoothing_factor * remote -> step_size * target_diff / 2 +
107+ (1 - smoothing_factor ) * remote -> ramped_step_size ;
108+ // Linearly ramped down step size is provided as minimum to prevent overshoot
109+ float centering_step_size =
110+ fminf (fabsf (remote -> ramped_step_size ), fabsf (target_diff / 2 ) * remote -> step_size ) *
111+ sign (target_diff );
112+ if (fabsf (target_diff ) < fabsf (centering_step_size )) {
113+ remote -> setpoint = target ;
114+ } else {
115+ remote -> setpoint += centering_step_size ;
116+ }
94117 } else {
95- remote -> setpoint += centering_step_size ;
118+ // Ramp up step size until the configured tilt speed is reached
119+ remote -> ramped_step_size = smoothing_factor * remote -> step_size * sign (target_diff ) +
120+ (1 - smoothing_factor ) * remote -> ramped_step_size ;
121+ remote -> setpoint += remote -> ramped_step_size ;
96122 }
97- } else {
98- // Ramp up step size until the configured tilt speed is reached
99- remote -> ramped_step_size = smoothing_factor * remote -> step_size * sign (target_diff ) +
100- (1 - smoothing_factor ) * remote -> ramped_step_size ;
101- remote -> setpoint += remote -> ramped_step_size ;
102123 }
103124}
0 commit comments