public async void NewGyro(Gyrometer sender, GyrometerReadingChangedEventArgs args)
        {
            var reading = args == null?sender?.GetCurrentReading() : args.Reading;

            await this.dispatcher.RunAsync(
                CoreDispatcherPriority.Normal,
                () =>
            {
                this[GYROSCOPE] = reading == null
                                              ? this[GYROSCOPE].New(0, 0, 0, 0)
                                              : this[GYROSCOPE].New(
                    reading.AngularVelocityX,
                    reading.AngularVelocityY,
                    reading.AngularVelocityZ,
                    0);
                if (this[GYROSCOPE].IsChanged)
                {
                    this.OnPropertyChanged(new PropertyChangedEventArgs("ItemsList"));
                    this.OnSensorUpdated?.Invoke(this[GYROSCOPE]);
                }
            });

            if (this.SensorSwitches.G.HasValue && (this.SensorSwitches.G.Value == 1 || this.SensorSwitches.G.Value == 3))
            {
                this.SensorSwitches.G = 0;
            }
        }
Beispiel #2
0
        /// <summary>
        /// Invoked when 'Get Sample' button is pressed.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void GetGyrometerSample(object sender, RoutedEventArgs e)
        {
            GyrometerReading wpReading;
            GyrometerReading windowsReading;

            GetSampleButton.IsEnabled = false;

            // Establish the report interval
            gyrometerWP.ReportInterval      = gyrometerWindows.MinimumReportInterval;
            gyrometerWindows.ReportInterval = gyrometerWindows.MinimumReportInterval;

            wpReading      = gyrometerWP.GetCurrentReading();
            windowsReading = gyrometerWindows.GetCurrentReading();

            if (null != wpReading)
            {
                ScenarioOutput_X_WP.Text = wpReading.AngularVelocityX.ToString();
                ScenarioOutput_Y_WP.Text = wpReading.AngularVelocityY.ToString();
                ScenarioOutput_Z_WP.Text = wpReading.AngularVelocityZ.ToString();
            }

            if (null != windowsReading)
            {
                ScenarioOutput_X_Windows.Text = windowsReading.AngularVelocityX.ToString();
                ScenarioOutput_Y_Windows.Text = windowsReading.AngularVelocityY.ToString();
                ScenarioOutput_Z_Windows.Text = windowsReading.AngularVelocityZ.ToString();
            }

            gyrometerWP.ReportInterval      = 0;
            gyrometerWindows.ReportInterval = 0;

            GetSampleButton.IsEnabled = true;
        }
Beispiel #3
0
        private void OnGetGyrometer(object sender, RoutedEventArgs e)
        {
            Gyrometer        gyrometer = Gyrometer.GetDefault();
            GyrometerReading reading   = gyrometer.GetCurrentReading();

            this.DefaultViewModel["GyrometerResult"] = GetGyrometerResult(reading);
        }
        void updateHeadTracking()
        {
            TrackingNode head = trackingNodes[TrackingNode.HEAD];

            Vector3 screenRotation = new Vector3(-90, 0, 90);
            Vector3 rotationRate   = Vector3.zero;
            Vector3 accel          = default(Vector3);

            var raw = gyro.GetCurrentReading();

            rotationRate  = new Vector3((float)-raw.AngularVelocityX, (float)-raw.AngularVelocityY, (float)raw.AngularVelocityZ) * Time.deltaTime;
            head.Rotation = head.Rotation * Quaternion.Euler(-rotationRate.x, -rotationRate.y, rotationRate.z);

            if (accel == default(Vector3))
            {
                accel = Input.acceleration;
            }

            //perform orientation transform for landscape left
            accel = new Vector3(-accel.x, accel.y, accel.z);

            Vector3 pitchVector = Vector3.ProjectOnPlane(accel, Vector3.right).normalized;
            Vector3 rollVector  = Vector3.ProjectOnPlane(accel, Vector3.forward).normalized;

            float pitch = Mathf.Atan2(-pitchVector.y, pitchVector.z) * Mathf.Rad2Deg;
            float roll  = Mathf.Atan2(rollVector.y, rollVector.x) * Mathf.Rad2Deg;

            Quaternion rotation = Quaternion.Euler(new Vector3(pitch, head.Rotation.eulerAngles.y, roll) + screenRotation);

            //This represents a basic complimentary filter, it's not good long term we should use a Kalman filter here [ld]
            head.Rotation = Quaternion.Slerp(head.Rotation, rotation, 1.0F * Time.deltaTime);
        }
Beispiel #5
0
        public SensorReading Get()
        {
            var reading = new SensorReading();

            if (lightSensor != null)
            {
                reading.Lux = lightSensor.GetCurrentReading().IlluminanceInLux;
            }
            if (gyroMeter != null)
            {
                var gyroReading = gyroMeter.GetCurrentReading();
                reading.GyroValue = new XYZValue
                {
                    X = gyroReading.AngularVelocityX,
                    Y = gyroReading.AngularVelocityY,
                    Z = gyroReading.AngularVelocityZ
                };
            }
            if (magnetometer != null)
            {
                var magReading = magnetometer.GetCurrentReading();
                reading.MagnetoValue = new XYZValue
                {
                    X = magReading.MagneticFieldX,
                    Y = magReading.MagneticFieldY,
                    Z = magReading.MagneticFieldZ
                };
            }
            Console.WriteLine("returning sensor reading: " + JsonConvert.SerializeObject(reading));

            return(reading);
        }
Beispiel #6
0
        public void PrintSensors(bool fast = false)
        {
            //BarometerReading read = baro.GetCurrentReading();
            var accR = acc.GetCurrentReading();
            //Debug.WriteLine(Math.Sqrt(Math.Pow(accR.AccelerationX; 2) + Math.Pow(accR.AccelerationY; 2) + Math.Pow(accR.AccelerationZ; 2)) + " (" + accR.AccelerationX + "/" + accR.AccelerationX + "/" + accR.AccelerationX + ")");
            //var actR = act.GetCurrentReadingAsync().GetResults();
            //Debug.WriteLine(actR.Activity + " (" + actR.Confidence + ")");
            //Debug.WriteLine(alt.GetCurrentReading().AltitudeChangeInMeters);
            //Debug.WriteLine(baro.GetCurrentReading().StationPressureInHectopascals);
            var compR = comp.GetCurrentReading();
            //Debug.WriteLine(compR.HeadingMagneticNorth + " (+/-" + compR.HeadingAccuracy + ")");
            var gyroR = gyro.GetCurrentReading();
            //Debug.WriteLine("(" + gyroR.AngularVelocityX + "/" + gyroR.AngularVelocityY + "/" + gyroR.AngularVelocityZ + ")");
            var incR = inc.GetCurrentReading();
            //Debug.WriteLine("(" + incR.PitchDegrees + "/" + incR.RollDegrees + "/" + incR.YawDegrees + ")");
            //var psR=ps.GetCurrentReading();
            //Debug.WriteLine(psR.IsDetected + ": " + psR.DistanceInMillimeters);
            //Debug.WriteLine(sos.GetCurrentOrientation());



            String csv = (Math.Sqrt(Math.Pow(accR.AccelerationX, 2) + Math.Pow(accR.AccelerationY, 2) + Math.Pow(accR.AccelerationZ, 2)) + ";" + accR.AccelerationX + ";" + accR.AccelerationY + ";" + accR.AccelerationZ + ";"
                          + alt.GetCurrentReading().AltitudeChangeInMeters + ";" + baro.GetCurrentReading().StationPressureInHectopascals + ";" + compR.HeadingMagneticNorth + ";" + compR.HeadingTrueNorth + ";" + compR.HeadingAccuracy
                          + ";" + gyroR.AngularVelocityX + ";" + gyroR.AngularVelocityY + ";" + gyroR.AngularVelocityZ + ";" + incR.PitchDegrees + ";" + incR.RollDegrees + ";" + incR.YawDegrees + ";" + sos.GetCurrentOrientation() + ";" + accR.Timestamp.ToUnixTimeMilliseconds() + ";" + fast);

            Debug.WriteLine(csv);
            StorageInterface.AppendToKnownStorageFile(Token, csv + "\r\n").GetAwaiter();
            OUT.Text += csv + "\r\n";
        }
        /// <summary>
        /// This is the dispatcher callback.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        private void DisplayCurrentReading(object sender, object args)
        {
            GyrometerReading reading = _gyrometer.GetCurrentReading();

            if (reading != null)
            {
                ScenarioOutput_X.Text = String.Format("{0,5:0.00}", reading.AngularVelocityX);
                ScenarioOutput_Y.Text = String.Format("{0,5:0.00}", reading.AngularVelocityY);
                ScenarioOutput_Z.Text = String.Format("{0,5:0.00}", reading.AngularVelocityZ);
            }
        }
        /// <summary>
        /// Update Gyrometer readings event and update UI
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">The <see cref="object"/> instance containing the event data.</param>
        private void UpdateGyrometer(object sender, EventArgs e)
        {
            try
            {
                Gyrometer gyrometer = Gyrometer.GetDefault();
                if (gyrometer != null)
                {
                    XPanel.Text = LocRM.GetString("XAxis") + ": " +
                                  String.Format("{0,5:0.00}", gyrometer.GetCurrentReading().AngularVelocityX) + "(°)/s";
                    YPanel.Text = LocRM.GetString("YAxis") + ": " +
                                  String.Format("{0,5:0.00}", gyrometer.GetCurrentReading().AngularVelocityY) + "(°)/s";
                    ZPanel.Text = LocRM.GetString("ZAxis") + ": " +
                                  String.Format("{0,5:0.00}", gyrometer.GetCurrentReading().AngularVelocityZ) + "(°)/s";

                    pictureBoxX.Image = Rotate(imageX, Math.Max(-135, Math.Min(135, gyrometer.GetCurrentReading().AngularVelocityX)));
                    pictureBoxY.Image = Rotate(imageY, Math.Max(-135, Math.Min(135, gyrometer.GetCurrentReading().AngularVelocityY)));
                    pictureBoxZ.Image = Rotate(imageZ, Math.Max(-135, Math.Min(135, gyrometer.GetCurrentReading().AngularVelocityZ)));
                }
                else
                {
                    XPanel.Text = LocRM.GetString("NotFound");
                    _timer.Stop();
                }
            }
            catch (Exception ex)
            {
                Log.LogError(ex.ToString());
                XPanel.Text = LocRM.GetString("Error");
                _timer.Stop();
            }
        }
 void ReadGyrometerData()
 {
     if (gyroSensor != null)
     {
         GyrometerReading reading = gyroSensor.GetCurrentReading();
         if (reading != null)
         {
             gyroX.Value = reading.AngularVelocityX;
             gyroY.Value = reading.AngularVelocityY;
             gyroZ.Value = reading.AngularVelocityZ;
         }
     }
 }
Beispiel #10
0
        public void OnGetGyrometer()
        {
            Gyrometer sensor = Gyrometer.GetDefault();

            if (sensor != null)
            {
                GyrometerReading reading = sensor.GetCurrentReading();
                GyrometerInfo = $"X: {reading.AngularVelocityX} Y: {reading.AngularVelocityY} Z: {reading.AngularVelocityZ}";
            }
            else
            {
                GyrometerInfo = "Gyrometer not found";
            }
        }
Beispiel #11
0
        public GyrometerReading GetGyrometerReading()
        {
            if (_gyrometer == null)
            {
                throw new InvalidOperationException("The gyrometer is either not present or has not been initialized");
            }

            var reading = _gyrometer.GetCurrentReading();

            return(reading);
            // Available reading values include:
            //reading.AngularVelocityX
            //reading.AngularVelocityY
            //reading.AngularVelocityZ
            //reading.Timestamp
        }
        private void IMUTimer_Tick(object StateObject)
        {
            string timeStamp = nanoTime().ToString();

            if (DEBUG)
            {
                writerCSV.WriteLine(timeStamp + "," + "omega_x" + "," + "omega_y" + "," + "omega_z" + "," + "alpha_x" + "," + "alpha_y" + "," + "alpha_z");
            }
            else
            {
                AccelerometerReading readingAccl = _accelerometer.GetCurrentReading();
                GyrometerReading     readingGyro = _gyrometer.GetCurrentReading();

                writerCSV.WriteLine(timeStamp + ","
                                    + readingGyro.AngularVelocityX + "," + readingGyro.AngularVelocityY + "," + readingGyro.AngularVelocityZ
                                    + "," + readingAccl.AccelerationX + "," + readingAccl.AccelerationY + "," + readingAccl.AccelerationZ);
            }
        }
        async void initialize()
        {
            //-----------------------------------------------------------------------------陀螺仪部分
            string errMessage = "";

            try
            {
                //获取默认的陀螺仪对象
                gyrometer = Gyrometer.GetDefault();
                if (gyrometer == null)
                {
                    await new MessageDialog("不支持陀螺仪").ShowAsync();
                    return;
                }
                //设置读取数据的时间间隔
                gyrometer.ReportInterval  = 1000;
                gyrometer.ReadingChanged += gyrometer_ReadingChanged;
                gyrometerReading          = gyrometer.GetCurrentReading();
            }

            catch (Exception err)
            {
                errMessage = err.Message;
            }

            if (errMessage != "")
            {
                await new MessageDialog(errMessage).ShowAsync();
            }

            //-------------------------------------------------------------
            GetLocation();
            ShowData();
            starclient = new StarClient(GetTime()[0], GetTime()[1], GetTime()[2], GetTime()[3], weidu, jingdu,
                                        Double.Parse(currentX), Double.Parse(currentY), Double.Parse(currentZ));
            number = starclient.planetnumber();

            //MySqlite = new mysqlite();
            //MySqlite.creatTable();
        }