Beispiel #1
0
        public void Start()
        {
            _motionManager = new CMMotionManager();
            _motionManager.StartDeviceMotionUpdates(NSOperationQueue.CurrentQueue, (data, error) =>
            {
                var xMotion = new XMotion
                {
                    Pitch = data.Attitude.Pitch,
                    Roll  = data.Attitude.Roll,
                    Yaw   = data.Attitude.Yaw
                };

                CurrentMotion = xMotion;

                if (MotionUpdated != null)
                {
                    MotionUpdated(this, EventArgs.Empty);
                }
            });
        }
Beispiel #2
0
        private void computeOrientation()
        {
            if (SensorManager.GetRotationMatrix(m_rotationMatrix, null, m_lastAccels, m_lastMagFields))
            {
                SensorManager.GetOrientation(m_rotationMatrix, m_orientation);

                float yaw   = (float)(RadianToDegree(m_orientation[0])); /* + Declination (Based on phone's location?) */
                float pitch = (float)RadianToDegree(m_orientation[1]);
                float roll  = (float)RadianToDegree(m_orientation[2]);

                var xMotion = new XMotion
                {
                    Pitch = pitch,
                    Roll  = roll,
                    Yaw   = yaw
                };

                //Console.WriteLine("Pitch: " + xMotion.Pitch);
                //Console.WriteLine("Roll: " + xMotion.Roll);
                //Console.WriteLine("Yaw: " + xMotion.Yaw + " ----");

                //TODO: Low pass filtering? Evens out results. -- http://www.raweng.com/blog/2013/05/28/applying-low-pass-filter-to-android-sensors-readings/
                //var xMotion = new XMotion
                //{
                //    Pitch = lowPass(pitch),
                //    Roll = lowPass(roll),
                //    Yaw = lowPass(yaw)
                //};

                CurrentMotion = xMotion;

                if (MotionUpdated != null)
                {
                    MotionUpdated(this, EventArgs.Empty);
                }
            }
        }