コード例 #1
0
        /// <summary>
        /// Handle periodic sensor readings from the brick
        /// </summary>
        /// <param name="update"></param>
        private void NotificationHandler(pxbrick.LegoSensorUpdate update)
        {
            I2CResponseMindSensorsAccelerationSensor inputValues = new I2CResponseMindSensorsAccelerationSensor(update.Body.CommandData);

            if (inputValues.Success)
            {
                double x, y, z;
                if (_state.ZeroOffset == null)
                {
                    x = inputValues.X;
                    y = inputValues.Y;
                    z = inputValues.Z;
                }
                else
                {
                    // Adjust Zero Offset
                    x = (inputValues.X + 256.0 - _state.ZeroOffset.X) % 256.0;
                    y = (inputValues.Y + 256.0 - _state.ZeroOffset.Y) % 256.0;
                    z = (inputValues.Z + 256.0 - _state.ZeroOffset.Z) % 256.0;
                }

                _state.Tilt.TimeStamp = inputValues.TimeStamp;
                _state.Tilt.X         = x;
                _state.Tilt.Y         = y;
                _state.Tilt.Z         = z;

                SendNotification <AccelerometerUpdate>(_subMgrPort, _state.Tilt);
            }
        }
コード例 #2
0
        /// <summary>
        /// Handle periodic sensor readings from the brick
        /// </summary>
        /// <param name="update"></param>
        private void NotificationHandler(pxbrick.LegoSensorUpdate update)
        {
            I2CResponseHiTechnicAccelerationSensor inputValues = new I2CResponseHiTechnicAccelerationSensor(update.Body.CommandData);

            if (inputValues.Success)
            {
                _state.Tilt.TimeStamp = inputValues.TimeStamp;

                if (_state.ZeroOffset == null)
                {
                    _state.Tilt.X = inputValues.X;
                    _state.Tilt.Y = inputValues.Y;
                    _state.Tilt.Z = inputValues.Z;
                }
                else
                {
                    // Adjust Zero Offset
                    _state.Tilt.X = (inputValues.X + 512.0 - _state.ZeroOffset.X) % 1024.0 - 512.0;
                    _state.Tilt.Y = (inputValues.Y + 512.0 - _state.ZeroOffset.Y) % 1024.0 - 512.0;
                    _state.Tilt.Z = (inputValues.Z + 512.0 - _state.ZeroOffset.Z) % 1024.0 - 512.0;
                }

                SendNotification <AccelerometerUpdate>(_subMgrPort, _state.Tilt);
            }
        }
コード例 #3
0
        /// <summary>
        /// Handle periodic sensor readings from the pxbrick
        /// </summary>
        /// <param name="update"></param>
        private void NotificationHandler(pxbrick.LegoSensorUpdate update)
        {
            I2CResponseHiTechnicCompassSensor inputValues = new I2CResponseHiTechnicCompassSensor(update.Body.CommandData);

            if (inputValues.Success && inputValues.Heading < 360)
            {
                if (_state.Heading.Degrees != (double)inputValues.Heading || _state.Heading.TimeStamp == DateTime.MinValue)
                {
                    _state.Heading.TimeStamp = inputValues.TimeStamp;
                    _state.Heading.Degrees   = (double)inputValues.Heading;
                    SendNotification <CompassSensorUpdate>(_subMgrPort, _state.Heading);
                    SendNotification <pxanalogsensor.Replace>(_genericSubMgrPort, SyncGenericState());
                }
            }
        }