Beispiel #1
0
    private float ComputeError()
    {
        // this function implements the mathematical description of path tracking error. this is quite complicated in order to handle many edge cases.

        if (pathObservations.jumprulesflag)  // in jump rules the error is geometric, based on the track bounds
        {
            if (pathObservations.traction)
            {
                if (pathObservations.sideslipAngle >= maxSideSlipSum)
                {
                    Log(TrackingError.JumpTractionLoss);
                    return(errorThreshold + 1f);
                }
            }
            else
            {
                var trackposition = navigator.GetTrackPosition();
                if (Mathf.Abs(trackposition.offset) > 1.0f)
                {
                    Log(TrackingError.JumpExceededBounds);
                    return(errorThreshold + 1f);
                }
            }
        }

        if (pathObservations.direction < 0)
        {
            Log(TrackingError.Spin);
            return(errorThreshold + 1f);
        }

        if (pathObservations.PopCollision())
        {
            Log(TrackingError.Collision);
            return(errorThreshold + 1f);
        }

        if (Vector3.Dot(pathObservations.transform.up, Vector3.up) < 0)
        {
            Log(TrackingError.Flip);
            return(errorThreshold + 1f);
        }

        var error         = pathObservations.understeer;
        var errorGradient = Gradient(error, lastUndersteerError);

        lastUndersteerError = error;

        if (errorGradient <= 0)
        {
            error = 0;
        }

        if (error > errorThreshold)
        {
            Log(TrackingError.Understeer);
        }

        return(error);
    }