Пример #1
0
        public Offtrack RegisterTrackStatus(TrackSurfaces status, double sessionTime)
        {
            if (status == TrackSurfaces.OffTrack)
            {
                // Currently offtrack
                if (_currentOfftrack == null)
                {
                    // Was not offtrack before - check how long ago they went ontrack again

                    // Is the previous offtrack long enough ago?
                    if (_previousOfftrack != null && _previousOfftrack.EndTime.HasValue &&
                        _previousOfftrack.EndTime.Value <= sessionTime - Properties.Settings.Default.OfftrackTimeout * 1000)
                    {
                        // Previous offtrack was less than OfftrackTimeout ago: ignore
                        return(null);
                    }

                    // Is the speed high enough? > 35 mph = 56.327
                    if (this.Driver.Live.Speed < MIN_OFFTRACK_SPEED)
                    {
                        // Too slow - ignore
                        return(null);
                    }

                    this.StartOfftrack(sessionTime);
                    return(_currentOfftrack);
                }
                else
                {
                    // Was already offtrack - ignore
                    return(null);
                }
            }
            else
            {
                // Not currently offtrack
                if (_currentOfftrack != null)
                {
                    // Driver just returned to track - set end time
                    _currentOfftrack.EndTime = sessionTime;

                    var cur = _currentOfftrack;
                    _currentOfftrack = null;
                    return(cur);
                }
            }
            return(null);
        }
Пример #2
0
        public Offtrack RegisterTrackStatus(TrackSurfaces status, double sessionTime)
        {
            if (status == TrackSurfaces.OffTrack)
            {
                // Currently offtrack
                if (_currentOfftrack == null)
                {
                    // Was not offtrack before - check how long ago they went ontrack again

                    // Is the previous offtrack long enough ago?
                    if (_previousOfftrack != null && _previousOfftrack.EndTime.HasValue &&
                        _previousOfftrack.EndTime.Value <= sessionTime - Properties.Settings.Default.OfftrackTimeout * 1000)
                    {
                        // Previous offtrack was less than OfftrackTimeout ago: ignore
                        return null;
                    }

                    // Is the speed high enough? > 35 mph = 56.327
                    if (this.Driver.Live.Speed < MIN_OFFTRACK_SPEED)
                    {
                        // Too slow - ignore
                        return null;
                    }

                    this.StartOfftrack(sessionTime);
                    return _currentOfftrack;
                }
                else
                {
                    // Was already offtrack - ignore
                    return null;
                }
            }
            else
            {
                // Not currently offtrack
                if (_currentOfftrack != null)
                {
                    // Driver just returned to track - set end time
                    _currentOfftrack.EndTime = sessionTime;

                    var cur = _currentOfftrack;
                    _currentOfftrack = null;
                    return cur;
                }
            }
            return null;
        }
Пример #3
0
        // Example method that adds some data such as your lap distance and track surface to the string builder
        private void ArrayExample(StringBuilder sb, SdkWrapper.TelemetryUpdatedEventArgs e)
        {
            // Get your own CarIdx:
            int myId = wrapper.DriverId;

            // Get the arrays you want
            float[]         lapDistances = e.TelemetryInfo.CarIdxLapDistPct.Value;
            TrackSurfaces[] surfaces     = e.TelemetryInfo.CarIdxTrackSurface.Value;

            // Your car data is at your id index;
            float         myLapDistance = lapDistances[myId];
            TrackSurfaces mySurface     = surfaces[myId];

            sb.AppendLine("My lap distance: " + myLapDistance);
            sb.AppendLine("My track surface: " + mySurface.ToString());
        }
Пример #4
0
        public void ParseTelemetry(TelemetryInfo e)
        {
            this.Lap = e.CarIdxLap.Value[this.Driver.Id];
            this.LapDistance = e.CarIdxLapDistPct.Value[this.Driver.Id];
            this.TrackSurface = e.CarIdxTrackSurface.Value[this.Driver.Id];

            this.Gear = e.CarIdxGear.Value[this.Driver.Id];
            this.Rpm = e.CarIdxRPM.Value[this.Driver.Id];
            this.SteeringAngle = e.CarIdxSteer.Value[this.Driver.Id];

            this.Driver.PitInfo.CalculatePitInfo();
        }
Пример #5
0
 private void FuelTelemetry(SdkWrapper.TelemetryUpdatedEventArgs e, TrackSurfaces mySurface)
 {
     bool update = false;
     float currentLapDistPct = e.TelemetryInfo.LapDistPct.Value;
     if (currentLapDistPct <= 0.15 && this.SavedTelemetry.Fuel.LastLapDistPct > 0.85)
     {
         if (mySurface != TrackSurfaces.AproachingPits && mySurface != TrackSurfaces.InPitStall)
         {
             //crossed line therefore update fuel
             update = true;
         }
     }
     else
     {
         //didn't cross line therefore check if crossed quarter points
         if (currentLapDistPct >= 0.25 && this.SavedTelemetry.Fuel.LastLapDistPct < 0.25)
         {
             update = true;
         }
         else if (currentLapDistPct >= 0.5 && this.SavedTelemetry.Fuel.LastLapDistPct < 0.5)
         {
             update = true;
         }
         else if (currentLapDistPct >= 0.75 && this.SavedTelemetry.Fuel.LastLapDistPct < 0.75)
         {
             update = true;
         }
     }
     this.SavedTelemetry.Fuel.LastLapDistPct = currentLapDistPct;
     if (update)
     {
         this.SavedTelemetry.Fuel.FuelHistory.Push(e.TelemetryInfo.FuelLevel.Value);
     }
     if (this.SavedTelemetry.Fuel.CurrentFuelLevel - e.TelemetryInfo.FuelLevel.Value > 0.05f && e.TelemetryInfo.Speed.Value <= 1 && (mySurface == TrackSurfaces.AproachingPits || mySurface == TrackSurfaces.InPitStall))
     {
         this.SavedTelemetry.Fuel.ResetFuel();
     }
     else
     {
         this.SavedTelemetry.Fuel.CurrentFuelLevel = e.TelemetryInfo.FuelLevel.Value;
         this.SavedTelemetry.Fuel.UpdateCalculatedFuelValues();
     }
 }
Пример #6
0
 private void FirstTelemetryUpdate()
 {
     this.SetDCVarsList();
     this.lastTrackSurface = TrackSurfaces.NotInWorld;
     this._2NdLastTrackSurface = TrackSurfaces.NotInWorld;
     this.firstTelemetryUpdate = false;
 }
Пример #7
0
        /// <summary>
        ///     Called everytime telemetry is updated. Starting point for cycles
        /// </summary>
        /// <param name="e"></param>
        public void TelemetryUpdate(SdkWrapper.TelemetryUpdatedEventArgs e)
        {
            if (this.firstTelemetryUpdate)
            {
                this.FirstTelemetryUpdate();
            }
            if (this.SavedTelemetry.CurrentSessionNum != e.TelemetryInfo.SessionNum.Value)
            {
                this.NewTelemetrySession(e);
            }
            double updateTime = e.UpdateTime;
            TrackSurfaces[] surfaces = e.TelemetryInfo.CarIdxTrackSurface.Value;
            TrackSurfaces mySurface = surfaces[Wrapper.DriverId]; // Your car data is at your id index;
            if (refreshCount % 15 == 0)
            {
                this._2NdLastTrackSurface = this.lastTrackSurface; //used for DC Vars
            }
            this.lastTrackSurface = mySurface;
            if (useLapTiming)
            {
                updateTime = this.TelemetryLapTimer(e, mySurface, updateTime);
            }

            if (this.refreshCount % 30 == 0)
            {
                if (mySurface == TrackSurfaces.InPitStall || mySurface == TrackSurfaces.NotInWorld)
                {
                    this.SavedTelemetry.LapLastPited = e.TelemetryInfo.Lap.Value;
                }
            }

            //store delta times
            if (useDeltaTiming)
            {
                this.SavedTelemetry.DeltaBest = e.TelemetryInfo.LapDeltaToBestLap.Value;
                this.SavedTelemetry.DeltaBestOK = e.TelemetryInfo.LapDeltaToBestLap_OK.Value;
                this.SavedTelemetry.DeltaHistory[0].Push(
                        e.TelemetryInfo.LapDeltaToBestLap_OK.Value ? e.TelemetryInfo.LapDeltaToBestLap.Value : 500f);
                this.SavedTelemetry.DeltaOpt = e.TelemetryInfo.LapDeltaToOptimalLap.Value;
                this.SavedTelemetry.DeltaOptOK = e.TelemetryInfo.LapDeltaToOptimalLap_OK.Value;
                this.SavedTelemetry.DeltaHistory[1].Push(
                        e.TelemetryInfo.LapDeltaToOptimalLap_OK.Value ? e.TelemetryInfo.LapDeltaToOptimalLap.Value : 500f);
                this.SavedTelemetry.DeltaSesBest = e.TelemetryInfo.LapDeltaToSessionBestLap.Value;
                this.SavedTelemetry.DeltaSesBestOK = e.TelemetryInfo.LapDeltaToSessionBestLap_OK.Value;
                this.SavedTelemetry.DeltaHistory[2].Push(
                        e.TelemetryInfo.LapDeltaToSessionBestLap_OK.Value ? e.TelemetryInfo.LapDeltaToSessionBestLap.Value : 500f);
                this.SavedTelemetry.DeltaSesOpt = e.TelemetryInfo.LapDeltaToSessionOptimalLap.Value;
                this.SavedTelemetry.DeltaSesOptOK = e.TelemetryInfo.LapDeltaToSessionOptimalLap_OK.Value;
                this.SavedTelemetry.DeltaHistory[3].Push(
                        e.TelemetryInfo.LapDeltaToSessionOptimalLap_OK.Value ? e.TelemetryInfo.LapDeltaToSessionOptimalLap.Value : 500f);
            }

            if (this.refreshCount % 30 == 0 && useFuelCalcs) //Only Check Fuel Consumption Stuff Once a Second
            {
                this.FuelTelemetry(e, mySurface);
            }
            if (this.refreshCount % DisplayRefreshRate == 0)
            {
                UpdateDisplayString(e);
                if (this.useDC)
                {
                    UpdateDCVars(e);
                }
            }

            this.SavedTelemetry.LastTelemetryUpdate = updateTime;
            this.SavedTelemetry.CurrentLap = e.TelemetryInfo.Lap.Value;
            this.SavedTelemetry.CurrentFuelPCT = e.TelemetryInfo.FuelLevelPct.Value;
            this.SavedTelemetry.OnTrack = e.TelemetryInfo.IsOnTrack.Value;

            if (useEngineWarnings && (mySurface == TrackSurfaces.OnTrack || mySurface == TrackSurfaces.OffTrack))
            {
                this.EngineWarningsDisplayUpdate(e);
            }
            if (this.CurrentConfiguration.DisplayConfigurations.Count > 0)
            {
                if (this.refreshCount % LEDRefreshRate == 0)
                {
                    UpdateLEDs(e);
                    SendTMLEDS();
                }
                if (this.refreshCount % displayRefreshRateFactor == 0)
                {
                    SendTMDisplay();
                }
            }
            this.refreshCount++;
            if (this.refreshCount >= 2000000000) //well before overflow
            {
                this.refreshCount = 0;
            }
        }
Пример #8
0
 private double TelemetryLapTimer(
     SdkWrapper.TelemetryUpdatedEventArgs e, TrackSurfaces mySurface, double updateTime)
 {
     if ((((e.TelemetryInfo.LapCurrentLapTime.Value - SavedTelemetry.LastMeasuredCurrentLapTime) < -5) || (this.SavedTelemetry.LastLapTimeAPI < 1 && e.TelemetryInfo.LapLastLapTime.Value > 5)) && (mySurface == TrackSurfaces.OnTrack || mySurface == TrackSurfaces.OffTrack))
     {
         //crossed line
         this.SavedTelemetry.LastLapTimeMeasured = e.TelemetryInfo.LapLastLapTime.Value;
             this.ShowLapTimeDisplay();
             foreach (Stack<float> t in this.SavedTelemetry.DeltaHistory)
             {
                 t.Push(500f);
             }
     }
     this.SavedTelemetry.PersonalBestLap = e.TelemetryInfo.LapBestLapTime.Value;
     this.SavedTelemetry.LastMeasuredCurrentLapTime = e.TelemetryInfo.LapCurrentLapTime.Value;
     this.SavedTelemetry.LastLapTimeAPI = e.TelemetryInfo.LapLastLapTime.Value;
     return updateTime;
 }
Пример #9
0
        // this method will compare the previous and current states and figure out what's going on in transition
        public CarState updateState(TrackSurfaces ts_state, bool between_cones)
        {
            // kick the states along a tick
            PreviousState        = CurrentState;
            PreviousBetweenCones = BetweenCones;
            BetweenCones         = between_cones;

            InTransition = false;
            switch (ts_state)
            {
            case TrackSurfaces.NotInWorld:
            {
                // the state we care about is if previous was not, NotInWorld that means we just got kicked out of the world
                if (PreviousState == CarState.NotInWorld)
                {
                    // already out, yawn
                }
                else if (PreviousState == CarState.ExitingWorld)
                {
                    // just left the world, now flip to out
                    setCurrentState(CarState.NotInWorld);
                }
                else
                {
                    // in transition, leaving the world
                    InTransition = true;
                    setCurrentState(CarState.ExitingWorld);
                }
            }
            break;

            case TrackSurfaces.OffTrack:
            {
                if ((PreviousState != CarState.OnTrack) && (PreviousState != CarState.NotInWorld))
                {
                    setCurrentState(CarState.OnTrack);
                }
            }
            break;

            case TrackSurfaces.InPitStall:
            {
                BetweenCones = true;

                // transitions are dropping in the world and coming into the pits after approaching
                if (PreviousState == CarState.NotInWorld)
                {
                    // just dropped in
                    setCurrentState(CarState.EnteringWorld);
                    InTransition = true;
                }
                else if (PreviousState == CarState.EnteringWorld)
                {
                    // just dropped in and now sitting in pits
                    setCurrentState(CarState.InStall);
                }
                else if (PreviousState == CarState.EnteringStall)
                {
                    // now stopping in pit stall
                    setCurrentState(CarState.InStall);
                    InTransition = true;
                }
                else if (PreviousState == CarState.EnteringPits)
                {
                    // driving up to the stall
                    setCurrentState(CarState.EnteringStall);
                    InTransition = true;
                }
                else
                {
                    // best guess default
                    if (PreviousState != CarState.InStall)
                    {
                        setCurrentState(CarState.InStall);
                    }
                }

                // drop through to special handling for changing tires
            }
            break;

            // complication here is we need to watch out for crossing the cone boundaries and capture that
            case TrackSurfaces.AproachingPits:
            {
                // this state is both entering and exiting the pit lane
                if (PreviousState == CarState.InStall)
                {
                    // just exited the stall
                    setCurrentState(CarState.ExitingStall);
                    InTransition = true;
                }
                else if (PreviousState == CarState.ExitingStall)
                {
                    // driving out the stall
                    setCurrentState(CarState.ExitingPits);
                    InTransition = true;
                }
                else if (PreviousState == CarState.OnTrack)
                {
                    // entering the pits
                    setCurrentState(CarState.EnteringPits);
                    InTransition = true;
                }
                else if (PreviousState == CarState.EnteringPits)
                {
                }
                else if (PreviousState == CarState.ExitingPits)
                {
                }
                else if (PreviousState == CarState.PassingEntryCones)
                {
                }
                else if (PreviousState == CarState.PassingExitCones)
                {
                }
                else if (PreviousState == CarState.NotInWorld)
                {
                    // entering the pits
                    setCurrentState(CarState.EnteringWorld);
                    InTransition = true;
                }
                else
                {
                    // best guess default
                    if (PreviousState != CarState.ExitingPits)
                    {
                        setCurrentState(CarState.ExitingPits);
                    }
                }

                // the cones override the standard states this is a bit ugly but meh
                // hitting the cones on entry
                if ((PreviousBetweenCones == false) && (between_cones == true) && (PreviousState != CarState.NotInWorld))       // might be qualy dropping right in
                {
                    setCurrentState(CarState.PassingEntryCones);
                    InTransition = true;
                    BetweenCones = true;
                }

                // passing the cones on exit
                else if ((PreviousBetweenCones == true) && (between_cones == false))
                {
                    setCurrentState(CarState.PassingExitCones);
                    InTransition = true;
                    BetweenCones = false;
                }
            }
            break;

            case TrackSurfaces.OnTrack:
            {
                if (PreviousState == CarState.ExitingPits)
                {
                    // just exited the pits
                    setCurrentState(CarState.EnteringTrack);
                    InTransition = true;
                }
                else if (PreviousState == CarState.EnteringTrack)
                {
                    // just exited the pits
                    setCurrentState(CarState.OnTrack);
                    InTransition = true;
                }
                else if (PreviousState == CarState.PassingExitCones)
                {
                    // just exited the pits
                    setCurrentState(CarState.OnTrack);
                    InTransition = true;
                }
                else if (PreviousState == CarState.NotInWorld)
                {
                    // entering the pits
                    setCurrentState(CarState.EnteringWorld);
                    InTransition = true;
                }
                else
                {
                    // best guess default
                    if (PreviousState != CarState.OnTrack)
                    {
                        setCurrentState(CarState.OnTrack);
                    }
                }
            }
            break;
            }

            return(CurrentState);
        }
Пример #10
0
        // this method will compare the previous and current states and figure out what's going on in transition
        public CarState updateState(TrackSurfaces ts_state, bool between_cones)
        {
            // kick the states along a tick
            PreviousState = CurrentState;
            PreviousBetweenCones = BetweenCones;
            BetweenCones = between_cones;

            InTransition = false;
            switch (ts_state)
            {
                case TrackSurfaces.NotInWorld:
                {
                    // the state we care about is if previous was not, NotInWorld that means we just got kicked out of the world
                    if (PreviousState == CarState.NotInWorld)
                    {
                        // already out, yawn
                    }
                    else if (PreviousState == CarState.ExitingWorld)
                    {
                        // just left the world, now flip to out
                        setCurrentState(CarState.NotInWorld);
                    }
                    else
                    {
                        // in transition, leaving the world
                        InTransition = true;
                        setCurrentState(CarState.ExitingWorld);
                    }
                }
                break;

                case TrackSurfaces.OffTrack:
                {
                    if ((PreviousState != CarState.OnTrack)&&(PreviousState != CarState.NotInWorld))
                        setCurrentState(CarState.OnTrack);
                }
                break;

                case TrackSurfaces.InPitStall:
                {
                    BetweenCones = true;

                    // transitions are dropping in the world and coming into the pits after approaching
                    if (PreviousState == CarState.NotInWorld)
                    {
                        // just dropped in
                        setCurrentState(CarState.EnteringWorld);
                        InTransition = true;
                    }
                    else if (PreviousState == CarState.EnteringWorld)
                    {
                        // just dropped in and now sitting in pits
                        setCurrentState(CarState.InStall);
                    }
                    else if (PreviousState == CarState.EnteringStall)
                    {
                        // now stopping in pit stall
                        setCurrentState(CarState.InStall);
                        InTransition = true;
                    }
                    else if (PreviousState == CarState.EnteringPits)
                    {
                        // driving up to the stall
                        setCurrentState(CarState.EnteringStall);
                        InTransition = true;
                    }
                    else
                    {
                        // best guess default
                        if (PreviousState != CarState.InStall)
                            setCurrentState(CarState.InStall);
                    }

                    // drop through to special handling for changing tires

                }
                break;

                // complication here is we need to watch out for crossing the cone boundaries and capture that
                case TrackSurfaces.AproachingPits:
                {
                    // this state is both entering and exiting the pit lane
                    if (PreviousState == CarState.InStall)
                    {
                        // just exited the stall
                        setCurrentState(CarState.ExitingStall);
                        InTransition = true;
                    }
                    else if (PreviousState == CarState.ExitingStall)
                    {
                        // driving out the stall
                        setCurrentState(CarState.ExitingPits);
                        InTransition = true;
                    }
                    else if (PreviousState == CarState.OnTrack)
                    {
                        // entering the pits
                        setCurrentState(CarState.EnteringPits);
                        InTransition = true;
                    }
                    else if (PreviousState == CarState.EnteringPits)
                    {
                    }
                    else if (PreviousState == CarState.ExitingPits)
                    {
                    }
                    else if (PreviousState == CarState.PassingEntryCones)
                    {
                    }
                    else if (PreviousState == CarState.PassingExitCones)
                    {
                    }
                    else if (PreviousState == CarState.NotInWorld)
                    {
                        // entering the pits
                        setCurrentState(CarState.EnteringWorld);
                        InTransition = true;
                    }
                    else
                    {
                        // best guess default
                        if (PreviousState != CarState.ExitingPits)
                            setCurrentState(CarState.ExitingPits);
                    }

                    // the cones override the standard states this is a bit ugly but meh
                    // hitting the cones on entry
                    if ((PreviousBetweenCones == false) && (between_cones == true) && (PreviousState != CarState.NotInWorld))   // might be qualy dropping right in
                    {
                        setCurrentState(CarState.PassingEntryCones);
                        InTransition = true;
                        BetweenCones = true;
                    }

                    // passing the cones on exit
                    else if ((PreviousBetweenCones == true) && (between_cones == false))
                    {
                        setCurrentState(CarState.PassingExitCones);
                        InTransition = true;
                        BetweenCones = false;
                    }

                }
                break;

                case TrackSurfaces.OnTrack:
                {
                    if (PreviousState == CarState.ExitingPits)
                    {
                        // just exited the pits
                        setCurrentState(CarState.EnteringTrack);
                        InTransition = true;
                    }
                    else if (PreviousState == CarState.EnteringTrack)
                    {
                        // just exited the pits
                        setCurrentState(CarState.OnTrack);
                        InTransition = true;
                    }
                    else if (PreviousState == CarState.PassingExitCones)
                    {
                        // just exited the pits
                        setCurrentState(CarState.OnTrack);
                        InTransition = true;
                    }
                    else if (PreviousState == CarState.NotInWorld)
                    {
                        // entering the pits
                        setCurrentState(CarState.EnteringWorld);
                        InTransition = true;
                    }
                    else
                    {
                        // best guess default
                        if (PreviousState != CarState.OnTrack)
                        setCurrentState(CarState.OnTrack);
                    }

                }
                break;

            }

            return CurrentState;
        }