in sensors/Tools/SensorExplorer/Scenario0_Testing.xaml.cs [925:1004]
private void CalculateOffsetTest()
{
string str = string.Empty;
int type = SensorType[pivotSensor.SelectedIndex];
if (type == Sensor.ACCELEROMETER)
{
string connectionType = Constants.SensorConnectionTypes[int.Parse(currentAccInfo.Properties[Constants.Properties["Sensor_ConnectionType"]].ToString())];
double[] errorSum = new double[3]; // x, y, z
if (connectionType == "Integrated")
{
foreach (double[] array in dataList)
{
errorSum[0] += Math.Abs(array[0] - Constants.OffsetTestExpectedValue[type][0]);
errorSum[1] += Math.Abs(array[1] - Constants.OffsetTestExpectedValue[type][1]);
errorSum[2] += Math.Abs(array[2] - Constants.OffsetTestExpectedValue[type][2]);
}
}
else
{
foreach (double[] array in dataList)
{
errorSum[0] += Math.Abs(array[0] - Constants.OffsetTestExpectedValue[type][0]);
errorSum[1] += Math.Abs(array[1] - Constants.OffsetTestExpectedValue[type][1]);
errorSum[2] += Math.Abs(array[2] + Constants.OffsetTestExpectedValue[type][2]);
}
}
double avgErrorX = errorSum[0] / dataList.Count;
double avgErrorY = errorSum[1] / dataList.Count;
double avgErrorZ = errorSum[2] / dataList.Count;
double result = Math.Sqrt(avgErrorX * avgErrorX + avgErrorY * avgErrorY + avgErrorZ * avgErrorZ);
str = Constants.SensorName[type] + " " + testType + " Test Result: " + result + " G\n";
}
else if (type == Sensor.GYROMETER)
{
double[] errorSum = new double[3]; // x, y, z
foreach (double[] array in dataList)
{
errorSum[0] += Math.Abs(array[0] - Constants.OffsetTestExpectedValue[type][0]);
errorSum[1] += Math.Abs(array[1] - Constants.OffsetTestExpectedValue[type][1]);
errorSum[2] += Math.Abs(array[2] - Constants.OffsetTestExpectedValue[type][2]);
}
double avgErrorX = errorSum[0] / dataList.Count;
double avgErrorY = errorSum[1] / dataList.Count;
double avgErrorZ = errorSum[2] / dataList.Count;
double result = Math.Sqrt(avgErrorX * avgErrorX + avgErrorY * avgErrorY + avgErrorZ * avgErrorZ);
str = Constants.SensorName[type] + " " + testType + " Test Result: " + result + " Degrees/s\n";
}
else if (type == Sensor.LIGHTSENSOR)
{
double errorSum = 0;
foreach (double[] array in dataList)
{
errorSum += Math.Abs(array[0] - Constants.OffsetTestExpectedValue[type][0]);
}
double result = errorSum / dataList.Count;
str = Constants.SensorName[type] + " " + testType + " Test Result: " + (errorSum / dataList.Count) + " Lux\n";
}
else if (type == Sensor.ORIENTATIONSENSOR || type == Sensor.ORIENTATIONGEOMAGNETIC || type == Sensor.ORIENTATIONRELATIVE)
{
double[] errorSum = new double[4]; // w, x, y, z
foreach (double[] array in dataList)
{
errorSum[0] += Math.Abs(array[0] - Constants.OffsetTestExpectedValue[type][0]);
errorSum[1] += Math.Abs(array[1] - Constants.OffsetTestExpectedValue[type][1]);
errorSum[2] += Math.Abs(array[2] - Constants.OffsetTestExpectedValue[type][2]);
errorSum[3] += Math.Abs(array[3] - Constants.OffsetTestExpectedValue[type][3]);
}
double avgErrorW = errorSum[0] / dataList.Count;
double avgErrorX = errorSum[1] / dataList.Count;
double avgErrorY = errorSum[2] / dataList.Count;
double avgErrorZ = errorSum[3] / dataList.Count;
double result = Math.Sqrt(avgErrorW * avgErrorW + avgErrorX * avgErrorX + avgErrorY * avgErrorY + avgErrorZ * avgErrorZ);
str = Constants.SensorName[type] + " " + testType + " Test Result: " + result + " Degrees\n\n";
}
rootPage.LoggingChannelView.LogMessage(str);
hyperlink.NavigateUri = new Uri("https://aka.ms/sensorexplorerblog");
run.Text = "https://aka.ms/sensorexplorerblog";
instruction.Text = str + "For more information, please visit:";
}