Skip to content

Commit

Permalink
Remove Inputtilt smoothing
Browse files Browse the repository at this point in the history
  • Loading branch information
lukash committed Oct 21, 2024
1 parent 33a1559 commit 2257f84
Showing 1 changed file with 4 additions and 27 deletions.
31 changes: 4 additions & 27 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -895,34 +895,11 @@ static void apply_inputtilt(data *d) {

float input_tiltback_target_diff = input_tiltback_target - d->inputtilt_interpolated;

// Smoothen changes in tilt angle by ramping the step size
const float smoothing_factor = 0.02;

// Within X degrees of Target Angle, start ramping down step size
if (fabsf(input_tiltback_target_diff) < 2.0f) {
// Target step size is reduced the closer to center you are (needed for smoothly
// transitioning away from center)
d->inputtilt_ramped_step_size =
(smoothing_factor * d->inputtilt_step_size * (input_tiltback_target_diff / 2)) +
((1 - smoothing_factor) * d->inputtilt_ramped_step_size);
// Linearly ramped down step size is provided as minimum to prevent overshoot
float centering_step_size =
fminf(
fabsf(d->inputtilt_ramped_step_size),
fabsf(input_tiltback_target_diff / 2) * d->inputtilt_step_size
) *
sign(input_tiltback_target_diff);
if (fabsf(input_tiltback_target_diff) < fabsf(centering_step_size)) {
d->inputtilt_interpolated = input_tiltback_target;
} else {
d->inputtilt_interpolated += centering_step_size;
}
// Constant step size; no smoothing
if (fabsf(input_tiltback_target_diff) < d->inputtilt_step_size) {
d->inputtilt_interpolated = input_tiltback_target;
} else {
// Ramp up step size until the configured tilt speed is reached
d->inputtilt_ramped_step_size =
(smoothing_factor * d->inputtilt_step_size * sign(input_tiltback_target_diff)) +
((1 - smoothing_factor) * d->inputtilt_ramped_step_size);
d->inputtilt_interpolated += d->inputtilt_ramped_step_size;
d->inputtilt_interpolated += d->inputtilt_step_size * sign(input_tiltback_target_diff);
}
}

Expand Down

0 comments on commit 2257f84

Please sign in to comment.