Example #1
0
 public void CheckMyApex(uint frame, LapData data)
 {
     lock (locker)
     {
         lastLapData = data;
         lastLapFrame = frame;
         CheckMyApex();
     }
 }
Example #2
0
        internal void AnalyzeApex(LapData lapData, CarTelemetryData carTelemetryData, CarMotionData motionData)
        {
            var nextSpeed = carTelemetryData.speed;
            if ((lastSpeed < 50 || lastSpeed > 230) && (nextSpeed < 50 || nextSpeed > 230))
            {
                // ignore
                Breaking = -1;
                return;
            }
            
           
            lock (Locker)
            {
                var m = motionData;
                var t = carTelemetryData;
                var l = lapData;
                var distance = (int)Math.Round(l.lapDistance, 0);

                if (Breaking == -1 && t.brake > 0 && l.lapDistance > 0)
                {
                    Breaking = l.lapDistance;
                    BreakingSpeed = t.speed;
                    lastCandidate = -1;
                }
                else if (Breaking > 0 && t.speed > 0 && t.brake == 0 && t.throttle > 0.2f)
                {
                    if (lastCandidate == -1)
                    {
                        lastCandidate = l.lapDistance;
                        ApexSpeed = t.speed;
                    }
                }
                
                if (Breaking!=-1 && BreakingSpeed - ApexSpeed > 50 && lastCandidate > 0 && (t.speed - ApexSpeed)> 10)
                {
                    AddApex((int)Math.Round(lastCandidate, 0));
                    Breaking = -1;
                }
            }
            lastSpeed = nextSpeed;
        }
Example #3
0
        public void AddData(LapData lapData, CarMotionData motionData)
        {
            if (lapData.currentLapInvalid == 1 || lapData.lapDistance < 0)
            {
                return;
            }

            // minder dan 5 meter sinds vorig punt
            var samePoints = pointVectors.Where(pv => pv.InPit == (lapData.pitStatus != 0) && 
                                                      lapData.lapDistance - pv.lapDistance < 5 &&  
                                                      lapData.lapDistance - pv.lapDistance > 0);
            if (samePoints.Any())
            {
                return;
                //var nextPoint = samePoints.First();
                //if (samePoints.Count() > 1)
                //{
                //    pointVectors.RemoveAll(pv => lapData.lapDistance != nextPoint.lapDistance &&  
                //                                    pv.InPit == (lapData.pitStatus != 0) &&
                //                                    pv.lapDistance - lapData.lapDistance > 5 &&
                //                                    pv.lapDistance - lapData.lapDistance < 10);
                //}
                //else
                //{
                //    nextPoint.lapDistance = (lapData.lapDistance + nextPoint.lapDistance) / 2;
                //    nextPoint.worldForwardDirX = (ushort)((motionData.worldForwardDirX / 2 + nextPoint.worldForwardDirX) / 2);
                //    nextPoint.worldForwardDirY = (ushort)((motionData.worldForwardDirY / 2 + nextPoint.worldForwardDirY) / 2);
                //    nextPoint.worldForwardDirZ = (ushort)((motionData.worldForwardDirZ / 2 + nextPoint.worldForwardDirZ) / 2);
                //    nextPoint.worldPositionX = (motionData.worldPositionX + nextPoint.worldPositionX) / 2f;
                //    nextPoint.worldPositionY = (motionData.worldPositionY + nextPoint.worldPositionY) / 2f;
                //    nextPoint.worldPositionZ = (motionData.worldPositionZ + nextPoint.worldPositionZ) / 2f;
                //}
            }

            //avg = samePoints.All()
            //    if (pointVectors.Any(pv =>  &&
            //    ((pv.worldPositionX - motionData.worldPositionX) * (pv.worldPositionX - motionData.worldPositionX) +
            //    (pv.worldPositionY - motionData.worldPositionY) * (pv.worldPositionY - motionData.worldPositionY) +
            //    (pv.worldPositionZ - motionData.worldPositionZ) * (pv.worldPositionZ - motionData.worldPositionZ)) < 10))

            else
            {
                pointVectors.Add(new CircuitLocation()
                {
                    InPit = (lapData.pitStatus != 0),
                    worldPositionX = motionData.worldPositionX,
                    worldPositionY = motionData.worldPositionY,
                    worldPositionZ = motionData.worldPositionZ,
                    lapDistance = lapData.lapDistance,
                    surfaceType = 0,
                    worldForwardDirX = motionData.worldForwardDirX,
                    worldForwardDirY = motionData.worldForwardDirY,
                    worldForwardDirZ = motionData.worldForwardDirZ,
                    //worldRightDirX = motionData.worldRightDirX,
                    //worldRightDirY = motionData.worldRightDirY,
                    //worldRightDirZ = motionData.worldRightDirZ
                });
                if (motionData.worldPositionX < minx) minx = motionData.worldPositionX;
                if (motionData.worldPositionX > maxx) maxx = motionData.worldPositionX;
                if (motionData.worldPositionY < miny) miny = motionData.worldPositionY;
                if (motionData.worldPositionY > maxy) maxy = motionData.worldPositionY;
                if (motionData.worldPositionZ < minz) minz = motionData.worldPositionZ;
                if (motionData.worldPositionZ > maxz) maxz = motionData.worldPositionZ;
                pointVectors = pointVectors.OrderBy(pv => pv.lapDistance).ToList();

            }
        }
Example #4
0
        internal LapRecording AddLapData(PacketHeader context, LapData lapData)
        {
            LapRecording completedLap = null;

            // uint8 m_resultStatus;
            // Result status - 0 = invalid, 1 = inactive, 2 = active
            // 3 = finished, 4 = disqualified, 5 = not classified
            // 6 = retired
            // Status of driver - 0 = in garage, 1 = flying lap
            // 2 = in lap, 3 = out lap, 4 = on track)
            if (lapData.driverStatus == 0 || lapData.driverStatus == 3 || lapData.driverStatus == 2)
            {
                // In garage
                return(null);
            }
            LapRecording activeLap = GetLap(lapData.currentLapNum);

            if (lapData.resultStatus == 3)
            {
                if (activeLap.lapTime > 0 && activeLap.lapMotion.Count > 100)
                {
                    activeLap.valid    = true;
                    activeLap.complete = true;
                    completedLap       = activeLap;
                }
                else
                {
                    return(null);
                }
            }
            if (currentLapIndex != lapData.currentLapNum)
            {
                // New lap? Starting Lap? Something else?
                if (currentLapIndex > lapData.currentLapNum)
                {
                    currentLapIndex = lapData.currentLapNum;
                }
                else if (currentLapIndex > 0)
                {
                    var previousLap = GetLap(currentLapIndex);

                    var lastLap = previousLap.lapTimings;
                    if (lastLap.currentLapInvalid == 0)
                    {
                        // Sanity check. Packages with ResultStatus 3 are missing, so calculate if it is a valid lap
                        //  by checking sinsible sector and lap times.
                        previousLap.complete =
                            previousLap.started && lastLap.sector1TimeInMS > 0 && lastLap.sector2TimeInMS > 0 &&
                            (lastLap.currentLapTimeInMS) > (lastLap.sector1TimeInMS + lastLap.sector2TimeInMS);
                        if (previousLap.complete)
                        {
                            previousLap.lapTimeInMs = lapData.lastLapTimeInMS;
                            completedLap            = previousLap;
                        }
                    }
                    else
                    {
                        previousLap.valid = false;
                    }
                }
                currentLapIndex = lapData.currentLapNum;
            }
            if (!activeLap.started)
            {
                activeLap.FirstTiming = lapData;
                if (lapData.lapDistance < 10)
                {
                    activeLap.started = true;
                }
            }
            activeLap.lapTimings = lapData;
            activeLap.lapData.Add(new LapDataInContext()
            {
                context = context, lapData = lapData
            });
            // GetLap(lapData.currentLapNum).started |= (lapData.sector == 0);

            return(completedLap);
        }