public Task SendDeviceToCloudSensorDataAsync(AccelerationAndGyroModel sensorData) { var telemetryDataPoint = new { messageId = Guid.NewGuid().ToString(), deviceId = deviceId, accelerationX = sensorData.AccelerationX, accelerationY = sensorData.AccelerationY, accelerationZ = sensorData.AccelerationZ, gyroX = sensorData.GyroX, gyroY = sensorData.GyroY, gyroZ = sensorData.GyroZ, }; var messageString = JsonConvert.SerializeObject(telemetryDataPoint); var message = new Message(Encoding.ASCII.GetBytes(messageString)); return(deviceClient.SendEventAsync(message)); }
public void UpdateFromGravity(AccelerationAndGyroModel sensors) { AccelAndGyro = sensors; double gravX = sensors.AccelerationX; double gravY = sensors.AccelerationY; double gravZ = sensors.AccelerationZ; double gyroZ = (sensors.GyroZ * sensors.SamplePeriod) - gyroZNoiseCorrect; double gyroX = (sensors.GyroX * sensors.SamplePeriod) - gyroXNoiseCorrect; double gyroY = (sensors.GyroY * sensors.SamplePeriod) - gyroYNoiseCorrect; //roll happens along the Y axis so the Y gravity doesn't change, so we check X and Z changes for roll if (!IsSignificantGravity(gravX, gravZ)) { Roll += -1 * gyroY; Roll = BoundAngle(Roll); } else { Roll = AngleFromGravity(gravX, gravZ); } //pitch is rotation along the x axis if (!IsSignificantGravity(gravY, gravZ)) { Pitch += gyroX; Pitch = BoundAngle(Pitch); } else { Pitch = BoundAngle(AngleFromGravity(gravY, gravZ)); } Yaw += -1 * gyroZ; Yaw = BoundAngle(Yaw); }