LCOV - code coverage report
Current view: top level - src - SteeringUtils.cpp (source / functions) Coverage Total Hit
Test: coverage_filtered.info Lines: 100.0 % 12 12
Test Date: 2026-03-01 21:30:38 Functions: 100.0 % 1 1
Branches: 100.0 % 8 8

             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                 :       12351 : void FFBEngine::calculate_soft_lock(const TelemInfoV01* data, FFBCalculationContext& ctx) {
      14                 :       12351 :     ctx.soft_lock_force = 0.0;
      15         [ +  + ]:       12351 :     if (!m_soft_lock_enabled) return;
      16                 :             : 
      17                 :       12346 :     double steer = data->mUnfilteredSteering;
      18         [ +  + ]:       12346 :     if (!std::isfinite(steer)) return;
      19                 :             : 
      20                 :       12344 :     double abs_steer = std::abs(steer);
      21         [ +  + ]:       12344 :     if (abs_steer > 1.0) {
      22                 :          21 :         double excess = abs_steer - 1.0;
      23         [ +  + ]:          21 :         double sign = (steer > 0.0) ? 1.0 : -1.0;
      24                 :             : 
      25                 :             :         // Spring Force: pushes back to 1.0
      26                 :          21 :         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                 :          21 :         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                 :          21 :         ctx.soft_lock_force = -(spring * sign + damping);
      37                 :             :     }
      38                 :             : }
        

Generated by: LCOV version 2.0-1