示例#1
0
        private void Start_Click(object sender, RoutedEventArgs e)
        {
            Start.IsEnabled = false;

            if (!bmp.begin())
            {
                /* There was a problem detecting the BMP085 ... check your connections */
                Debug.WriteLine("Ooops, no BMP085 detected ... Check your wiring or I2C ADDR!");
                while (true)
                {
                    ;
                }
            }
            Pressevent = bmp.getSensorEventObj();

            if (!gyro.begin())
            {
                /* There was a problem detecting the BMP085 ... check your connections */
                Debug.WriteLine("Ooops, no L3GD20 detected ... Check your wiring or I2C ADDR!");
                while (true)
                {
                    ;
                }
            }
            Gyroevent = gyro.getSensorEventObj();

            if (!accel.begin())
            {
                /* There was a problem detecting the BMP085 ... check your connections */
                Debug.WriteLine("Ooops, no LSM303 detected ... Check your wiring or I2C ADDR!");
                while (true)
                {
                    ;
                }
            }
            Accelevent = accel.getSensorEventObj();

            if (!mag.begin())
            {
                /* There was a problem detecting the BMP085 ... check your connections */
                Debug.WriteLine("Ooops, no LSM303 detected ... Check your wiring or I2C ADDR!");
                while (true)
                {
                    ;
                }
            }
            Magevent = mag.getSensorEventObj();

            // Start Timer every 1 seconds
            ReadSensorTimer          = new DispatcherTimer();
            ReadSensorTimer.Interval = TimeSpan.FromMilliseconds(1000);
            ReadSensorTimer.Tick    += Timer_Tick;
            ReadSensorTimer.Start();
        }
示例#2
0
        private async void Start()
        {
            if (!started)
            {
                started = true;
                if (!bmp.begin())
                {
                    /* There was a problem detecting the BMP085 ... check your connections */
                    Debug.WriteLine("Ooops, no BMP085 detected ... Check your wiring or I2C ADDR!");
                    while (true)
                    {
                        ;
                    }
                }
                Pressevent = bmp.getSensorEventObj();

                if (!gyro.begin())
                {
                    /* There was a problem detecting the BMP085 ... check your connections */
                    Debug.WriteLine("Ooops, no L3GD20 detected ... Check your wiring or I2C ADDR!");
                    while (true)
                    {
                        ;
                    }
                }
                Gyroevent = gyro.getSensorEventObj();

                if (!accel.begin())
                {
                    /* There was a problem detecting the BMP085 ... check your connections */
                    Debug.WriteLine("Ooops, no LSM303 detected ... Check your wiring or I2C ADDR!");
                    while (true)
                    {
                        ;
                    }
                }
                Accelevent = accel.getSensorEventObj();

                //if (!mag.begin())
                //{
                //    /* There was a problem detecting the BMP085 ... check your connections */
                //    Debug.WriteLine("Ooops, no LSM303 detected ... Check your wiring or I2C ADDR!");
                //    while (true) ;
                //}
                //Magevent = mag.getSensorEventObj();

                // Start Timer every 1 seconds
                //ReadSensorTimer = new DispatcherTimer();
                //ReadSensorTimer.Interval = TimeSpan.FromMilliseconds(timerMS);
                //ReadSensorTimer.Tick += Timer_Tick;
                //ReadSensorTimer.Start();

                Stopwatch loopDelay = Stopwatch.StartNew();
                Stopwatch sendDelay = Stopwatch.StartNew();
                string    calcXStr, calcZStr, calcYStr;
                try
                {
                    while (true)
                    {
                        accel.getEvent(ref Accelevent);
                        gyro.getEvent(ref Gyroevent);

                        //calcX = XkalmanCalculate((float)(Math.Atan2(Accelevent.acceleration.y, Accelevent.acceleration.z) * Pi180), Gyroevent.gyro.x, elapsed);
                        //calcY = YkalmanCalculate((float)(Math.Atan2(-Accelevent.acceleration.x, Math.Sqrt(Accelevent.acceleration.y * Accelevent.acceleration.y + Accelevent.acceleration.x * Accelevent.acceleration.z)) * Pi180), Gyroevent.gyro.y, elapsed);
                        //calcZ = ZkalmanCalculate((float)(Math.Atan2(Accelevent.acceleration.z, Accelevent.acceleration.y) * Pi180), Gyroevent.gyro.z, elapsed);
                        //COULD USE THE CALIBRATE FOR SQUARE ON THE LOAD THEN USE THE YAW (Z) TO MEASURE HOOK SPIN


                        calcXStr = String.Format("{0:0.0}", XkalmanCalculate((float)(Math.Atan2(Accelevent.acceleration.y, Accelevent.acceleration.z) * Pi180), Gyroevent.gyro.x, (int)loopDelay.ElapsedMilliseconds));
                        calcYStr = String.Format("{0:0.0}", YkalmanCalculate((float)(-Math.Atan2(Accelevent.acceleration.x, Math.Sqrt(Accelevent.acceleration.y * Accelevent.acceleration.y + Accelevent.acceleration.z * Accelevent.acceleration.z)) * Pi180), Gyroevent.gyro.y, (int)loopDelay.ElapsedMilliseconds));
                        //calcZStr = String.Format("{0:0.0}", ZkalmanCalculate((float)(Math.Atan2(Accelevent.acceleration.z, Accelevent.acceleration.y) * (180 / Math.PI)), Gyroevent.gyro.z, (int)loopDelay.ElapsedMilliseconds));
                        loopDelay.Restart();
                        if (sendDelay.ElapsedMilliseconds > 200)
                        {
                            sendDelay.Restart();
                            bmp.getEvent(ref Pressevent);
                            //bmp.getTemperature(ref temperature);
                            //float altitude = bmp.pressureToAltitude(Adafruit_BMP085_Unified.SENSORS_PRESSURE_SEALEVELHPA, Pressevent.pressure);
                            mySocket.Send(calcXStr + ":" + calcYStr + ":" + 0);
                            Status.Text      = loopDelay.ElapsedMilliseconds.ToString();
                            AccelXaxisC.Text = calcXStr;
                            AccelYaxisC.Text = calcYStr;
                        }
                        await Task.Delay(10);
                    }
                }
                catch (Exception ex)
                {
                    var tt = ex;
                    throw;
                }
            }
        }