Branch data Line data Source code
1 : : #include "FFBEngine.h"
2 : : #include <cmath>
3 : : #include <algorithm>
4 : :
5 : : // ---------------------------------------------------------------------------
6 : : // Steering & Wheel Mechanics methods have been moved from FFBEngine.cpp.
7 : : // This includes the Soft Lock logic which prevents the wheel from rotating
8 : : // beyond the car's physical steering rack limits.
9 : : // ---------------------------------------------------------------------------
10 : :
11 : : // Helper: Calculate Soft Lock (v0.7.61 - Issue #117)
12 : : // Provides a progressive spring-damping force when the wheel exceeds 100% lock.
13 : 14666 : void FFBEngine::calculate_soft_lock(const TelemInfoV01* data, FFBCalculationContext& ctx) {
14 : 14666 : ctx.soft_lock_force = 0.0;
15 [ + + ]: 14666 : if (!m_soft_lock_enabled) return;
16 : :
17 : 14661 : double steer = data->mUnfilteredSteering;
18 [ + + ]: 14661 : if (!std::isfinite(steer)) return;
19 : :
20 : 14659 : double abs_steer = std::abs(steer);
21 [ + + ]: 14659 : if (abs_steer > 1.0) {
22 : 23 : double excess = abs_steer - 1.0;
23 [ + + ]: 23 : double sign = (steer > 0.0) ? 1.0 : -1.0;
24 : :
25 : : // Spring Force: pushes back to 1.0
26 : 23 : double spring = excess * m_soft_lock_stiffness * (double)BASE_NM_SOFT_LOCK;
27 : :
28 : : // Damping Force: opposes movement to prevent bouncing
29 : : // Uses m_steering_velocity_smoothed which is in rad/s
30 : 23 : double damping = m_steering_velocity_smoothed * m_soft_lock_damping * (double)BASE_NM_SOFT_LOCK;
31 : :
32 : : // Total Soft Lock force (opposing the steering direction)
33 : : // Note: damping already has a sign from m_steering_velocity_smoothed.
34 : : // If moving further away from limit, damping should oppose it.
35 : : // If returning to center, damping should also oppose it (slowing down the return).
36 : 23 : ctx.soft_lock_force = -(spring * sign + damping);
37 : : }
38 : : }
|