public void EndSession()
        {
            session.PropertyChanged -= OnNewControllerDataReceived;
            session = null;
            yawDataSeries = null;
            tiltDataSeries = null;

            Log.Debug("Stopping PID Charting");
        }
        public void StartNewSession(Session newSession)
        {
            session = newSession;
            yawDataSeries = session.YawDataSeries;
            tiltDataSeries = session.TiltDataSeries;

            session.PropertyChanged += OnNewControllerDataReceived;

            ClearDataSeries();

            yawAngles = new XyDataSeries<double, double>() { FifoCapacity = FifoSampleSize, SeriesName = "Yaw Angle" };
            yawSetPoints = new XyDataSeries<double, double>() { FifoCapacity = FifoSampleSize, SeriesName = "Yaw Set Point" };
            tiltAngles = new XyDataSeries<double, double>() { FifoCapacity = FifoSampleSize, SeriesName = "Tilt Angle" };
            tiltSetPoints = new XyDataSeries<double, double>() { FifoCapacity = FifoSampleSize, SeriesName = "Tilt Set Point" };

            YawAngleSeries.DataSeries = yawAngles;
            YawSetPointSeries.DataSeries = yawSetPoints;
            TiltAngleSeries.DataSeries = tiltAngles;
            TiltSetPointSeries.DataSeries = tiltSetPoints;

            Log.Debug("Starting PID Charting");
        }
        private void ResetSession()
        {
            Session = new Session(HelicopterController, HelicopterSettings.PidThreadRefreshIntervalMilliseconds);
            Session.ClearControllerData();

            IsSessionComplete = false;
        }
        public static SessionRecord CreateNewSessionRecord(Session session, HelicopterSettings settings)
        {
            SessionRecord sessionRecord;
            var yaw = session.YawDataSeries;
            var tilt = session.TiltDataSeries;

            using (var context = new HelicopterModelEntities())
            {
                var settingsRecordId = UpdateSettingsRecord(settings, context);

                sessionRecord = new SessionRecord
                {
                    SettingsId = settingsRecordId,
                    StartTime = session.StartTime,
                    EndTime = session.EndTime,
                    Comment = String.Empty
                };

                var yawRecord = new ControllerRecord
                {
                    MotorType = yaw.MotorType.ToString(),
                    DriverType = yaw.MotorDriver.ToString(),
                    CWProportionalGain = yaw.CWProportionalGain,
                    CWIntegralGain = yaw.CWIntegralGain,
                    CWDerivativeGain = yaw.CWDerivativeGain,
                    CCWProportionalGain = yaw.CCWProportionalGain,
                    CCWIntegralGain = yaw.CCWIntegralGain,
                    CCWDerivativeGain = yaw.CCWDerivativeGain,
                    IntegralWindupThreshold = yaw.IWindupThreshold,
                    OutputRateLimit = yaw.OutputRateLimit,
                    MeasurementRecords = yaw.ControllerData.Select(x => new MeasurementRecord
                    {
                        TimeStamp = x.TimeStamp,
                        SetPoint = x.SetPoint,
                        CurrentAngle = x.CurrentAngle
                    }).ToList()
                };

                var tiltRecord = new ControllerRecord
                {
                    MotorType = tilt.MotorType.ToString(),
                    DriverType = tilt.MotorDriver.ToString(),
                    CWProportionalGain = tilt.CWProportionalGain,
                    CWIntegralGain = tilt.CWIntegralGain,
                    CWDerivativeGain = tilt.CWDerivativeGain,
                    IntegralWindupThreshold = tilt.IWindupThreshold,
                    OutputRateLimit = tilt.OutputRateLimit,
                    MeasurementRecords = tilt.ControllerData.Select(x => new MeasurementRecord
                    {
                        TimeStamp = x.TimeStamp,
                        SetPoint = x.SetPoint,
                        CurrentAngle = x.CurrentAngle
                    }).ToList()
                };

                sessionRecord.ControllerRecords.Add(yawRecord);
                sessionRecord.ControllerRecords.Add(tiltRecord);

                context.SessionRecords.Add(sessionRecord);
                context.SaveChanges();
                Log.Debug("Created and saved new session with ID");
            }

            return sessionRecord;
        }