public override void Calibrate(CalibrationParams calibParams, params object[] pObjects)
 {
     StopMeasurement();
     if (calibParams == null)
     {
         _zeroCorrection       = false;
         _startupCalib         = (bool)pObjects[0];
         _zeroCalibrationCount = (int)pObjects[1];
         ParseDone            += ZeroCalibrationHandler;
     }
     else
     {
         if (!(bool)pObjects[0])
         {
             ParseDone            += WeightCalibrationHandler;
             _calibrationParams    = calibParams;
             _periodBuf            = ExchangeConfig.Period;
             ExchangeConfig.Period = _calibrationParams.Period;
         }
         else
         {
             ParseDone         += FastWeightCalibrationHandler;
             _calibrationParams = calibParams;
         }
     }
     StartMeasurement();
 }
Beispiel #2
0
        private void btnSubmit_Click(object sender, EventArgs e)
        {
            try
            {
                double decibel = double.Parse(textBoxDecibel.Text);
                if (decibel < 0 || decibel > MAX_SOUND_LEVEL)
                {
                    return;
                }

                double avgSample = 0;

                foreach (var sample in rmsSamples)
                {
                    avgSample += sample;
                }

                avgSample = avgSample / rmsSamples.Count;

                CalibrationParams        = new CalibrationParams();
                CalibrationParams.Noise  = decibel;
                CalibrationParams.Sample = (short)avgSample;

                Close();
            }
            catch (Exception)
            {
                return;
            }
        }
Beispiel #3
0
        private void OnCommand(string cmd, string payload)
        {
            switch (cmd)
            {
            case "admin-cmd-set-corner":
                if (DisplayCalibration)
                {
                    var corner = (Corner)(int.Parse(payload.Replace("\"", "")));
                    DisplayCalibration.CurrentCorner = corner;
                    DisplayCalibration.StartCalibration();
                    SendUpdates();
                }
                break;

            case "admin-cmd-set-surface":
                if (DisplayCalibration)
                {
                    DisplayCalibration.CommitFixedDisplay();
                }
                break;

            case "admin-cmd-reset-calibration":
                CalibrationParams.Reset();
                break;

            case "admin-cmd-save-surfaces":
                SurfaceFileLoader.SaveToFile("default_displays.json");
                break;
            }
        }
Beispiel #4
0
        public override void PreparePose()
        {
            var pose = OptitrackListener.GetPose(TrackedName);

            if (pose != null)
            {
                _position = CalibrationParams.GetCalibratedPosition(pose.Position, pose.Rotation);
                //_rotation = CalibrationParams.GetCalibratedRotation(pose.Rotation);
                _rotation = pose.Rotation; // rotation is calibrated 'against' VR tracker
            }
        }
Beispiel #5
0
        public MainForm()
        {
            InitializeComponent();
            InitializeWaveOut();
            double lat, lng;

            GetLatLong(out lat, out lng);
            if (lat == -1 && lng == -1)
            {
                gMap.Enabled = false;
                return;
            }
            deviceGeoLocation = new PointLatLng(lat, lng);
            SqlServerTypes.Utilities.LoadNativeAssemblies(AppDomain.CurrentDomain.BaseDirectory);
            dbUpdater = new DBUpdater(deviceGeoLocation);
            InitializeGMap();
            recording     = new Recording.Recording(4);
            timeAveraging = new Averaging.TimeAveraging(lblLavgValue, lblTWAValue, lblDoseValue);
            comboBoxTimeWeight.SelectedIndex = 0;
            recording.OnDataAvaliable       += UpdateTimeDomain;
            recording.OnDataAvaliable       += UpdateVUMeter;
            recording.OnDataAvaliable       += timeAveraging.GatherNewData;

            CalibrationParams = new CalibrationParams
            {
                Sample = (short)Properties.Settings.Default["calibration_sample"],
                Noise  = (double)Properties.Settings.Default["calibration_noise"]
            };

            freqDomain.ChartAreas[0].AxisX.ScaleView.Zoomable       = true;
            freqDomain.ChartAreas[0].CursorX.AutoScroll             = true;
            freqDomain.ChartAreas[0].CursorX.IsUserSelectionEnabled = true;

            octaveFreqDomain.ChartAreas[0].AxisX.ScaleView.Zoomable       = true;
            octaveFreqDomain.ChartAreas[0].CursorX.AutoScroll             = true;
            octaveFreqDomain.ChartAreas[0].CursorX.IsUserSelectionEnabled = true;

            octavesVisualisation.ChartAreas[0].AxisX.ScaleView.Zoomable       = true;
            octavesVisualisation.ChartAreas[0].CursorX.AutoScroll             = true;
            octavesVisualisation.ChartAreas[0].CursorX.IsUserSelectionEnabled = true;

            timeDomain.ChartAreas[0].AxisY.Maximum     = short.MaxValue;
            timeDomain.ChartAreas[0].AxisY.Minimum     = short.MinValue;
            sensorReadings.ChartAreas[0].AxisY.Maximum = 140;
            sensorReadings.ChartAreas[0].AxisY.Minimum = 0;

            AppDomain.CurrentDomain.UnhandledException += OnUnhandledException;
            recording.IsRecording = true;
        }
Beispiel #6
0
        private void calibrateToolStripMenuItem_Click(object sender, EventArgs e)
        {
            CalibrationForm calibrationForm = new CalibrationForm(16, CalibrationParams.Sample,
                                                                  CalibrationParams.Noise, recording);

            calibrationForm.ShowDialog();

            if (calibrationForm.CalibrationParams != null)
            {
                CalibrationParams = calibrationForm.CalibrationParams;
                Properties.Settings.Default["calibration_sample"] = CalibrationParams.Sample;
                Properties.Settings.Default["calibration_noise"]  = CalibrationParams.Noise;
                Properties.Settings.Default.Save();
            }
        }
    void OnEnable()
    {
        //	try and load calibration
        try
        {
            var CalibrationJson = System.IO.File.ReadAllText(CalibrationFilePath);
            CalibrationData  = JsonUtility.FromJson <CalibrationParams>(CalibrationJson);
            CalibrationState = CalibrationStates.Finished;
        }
        catch (System.Exception e) {
            Debug.LogError("Didn't load calibration from " + CalibrationFilePath + ", exception=" + e.Message);
        }

        UpdateCalibrationTarget();
        CreateScreenQuad();
    }
Beispiel #8
0
        private void ApplyNewPose()
        {
            //DelayedPose pose = null;

            //var currentTime = Time.unscaledTime;
            //while (_trackedPoses.Count > 0 && _trackedPoses.Peek().TimeOfPose + TrackingDelay <= currentTime)
            //{
            //pose = _trackedPoses.Dequeue();
            //}

            //if (pose != null)
            //{
            //    _position = CalibrationParams.GetCalibratedPosition(pose.Position, pose.Rotation);
            //    _rotation = CalibrationParams.GetCalibratedRotation(pose.Rotation);
            //    //_rotation = pose.Rotation; //CalibrationParams.GetCalibratedRotation(pose.Rotation);
            //}

            _position = CalibrationParams.GetCalibratedPosition(VRListener.CurrentPosition, VRListener.CurrentRotation);
            _rotation = CalibrationParams.GetCalibratedRotation(VRListener.CurrentRotation);
        }
 private void WeightCalibrationHandler(object o, EventArgs eventArgs)
 {
     if (_adcList.Count < _calibrationParams.EntryCount)
     {
         _adcList.Add((double[])CurrAdcVals.Clone());
     }
     else
     {
         ParseDone -= WeightCalibrationHandler;
         var    aver = _adcList.Average(val => val[_calibrationParams.TenzNumber]);
         double koef = _calibrationParams.Weight / aver;
         WeightKoefs[_calibrationParams.TenzNumber] = koef;
         if (CalibrationDone != null)
         {
             CalibrationDone.Invoke(null, null);
         }
         _adcList.Clear();
         _calibrationParams    = null;
         ExchangeConfig.Period = _periodBuf;
     }
 }
Beispiel #10
0
        public void GatherNewData(short[] buffer)
        {
            double alfa = 0;

            foreach (var sample in buffer)
            {
                for (int i = 0; i < currentValues.Length; i++)
                {
                    alfa              = GetAlfa(timeWeightings[i]);
                    currentValues[i]  = (1 - alfa) * Math.Abs((double)sample) + alfa * previousValues[i];
                    previousValues[i] = currentValues[i];
                }
            }

            DateTime currentTime = DateTime.Now;

            CalibrationParams = new CalibrationParams
            {
                Sample = (short)Properties.Settings.Default["calibration_sample"],
                Noise  = (double)Properties.Settings.Default["calibration_noise"]
            };
            double calibrated_sample = CalibrationParams.Sample;
            double calibrated_noise  = CalibrationParams.Noise;

            double lavg      = calibrated_noise + 20.0 * Math.Log10(currentValues[TimeWeightIndex] / calibrated_sample);
            double Tn        = 8.0 / Math.Pow(2, (lavg - 90) / 5.0);
            var    time_diff = currentTime - timestamp;

            Dose     += 100 * time_diff.TotalSeconds / Tn;
            timestamp = currentTime;
            double TWA = 16.61 * Math.Log10(Dose / 100) + 90;

            UpdateLabel(labelDose, Math.Round(Dose, 5) + " %");
            UpdateLabel(labelLavg, Math.Round(lavg, 5) + " dB");
            UpdateLabel(labelTwa, Math.Round(TWA, 5) + " dB/day");
        }
        private void FastWeightCalibrationHandler(object o, EventArgs eventArgs)
        {
            if (_adcList.Count < _calibrationParams.EntryCount)
            {
                _adcList.Add((double[])CurrAdcVals.Clone());
            }
            else
            {
                ParseDone -= FastWeightCalibrationHandler;
                for (int i = 0; i < 4; i++)
                {
                    var    aver = _adcList.Average(val => val[i]);
                    double koef = _calibrationParams.Weight / aver;
                    WeightKoefs[i] = koef;
                }

                if (CalibrationDone != null)
                {
                    CalibrationDone.Invoke(null, null);
                }
                _adcList.Clear();
                _calibrationParams = null;
            }
        }
Beispiel #12
0
 public virtual void Calibrate(CalibrationParams calibParams, params object[] pObjects)
 {
     throw new NotImplementedException();
 }