-
Notifications
You must be signed in to change notification settings - Fork 10
/
Output.ino
132 lines (122 loc) · 3.74 KB
/
Output.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/* This file is part of the Razor AHRS Firmware */
// Output angles: yaw, pitch, roll
void output_angles()
{
//if (output_format == OUTPUT__FORMAT_BINARY)
//{
float ypr[3];
ypr[0] = TO_DEG(yaw);
ypr[1] = TO_DEG(pitch);
ypr[2] = TO_DEG(roll);
Serial.write((byte*) ypr, sizeof(ypr)); // No new-line
//}
//else if (output_format == OUTPUT__FORMAT_TEXT)
//{
// Serial.print("#YPR=");
// Serial.print(TO_DEG(yaw)); Serial.print(",");
// Serial.print(TO_DEG(pitch)); Serial.print(",");
// Serial.print(TO_DEG(roll)); Serial.println();
// }
}
void output_calibration(int calibration_sensor)
{
if (calibration_sensor == 0) // Accelerometer
{
// Output MIN/MAX values
Serial.print("accel x,y,z (min/max) = ");
for (int i = 0; i < 3; i++) {
if (accel[i] < accel_min[i]) accel_min[i] = accel[i];
if (accel[i] > accel_max[i]) accel_max[i] = accel[i];
Serial.print(accel_min[i]);
Serial.print("/");
Serial.print(accel_max[i]);
if (i < 2) Serial.print(" ");
else Serial.println();
}
}
else if (calibration_sensor == 1) // Magnetometer
{
// Output MIN/MAX values
Serial.print("magn x,y,z (min/max) = ");
for (int i = 0; i < 3; i++) {
if (magnetom[i] < magnetom_min[i]) magnetom_min[i] = magnetom[i];
if (magnetom[i] > magnetom_max[i]) magnetom_max[i] = magnetom[i];
Serial.print(magnetom_min[i]);
Serial.print("/");
Serial.print(magnetom_max[i]);
if (i < 2) Serial.print(" ");
else Serial.println();
}
}
else if (calibration_sensor == 2) // Gyroscope
{
// Average gyro values
for (int i = 0; i < 3; i++)
gyro_average[i] += gyro[i];
gyro_num_samples++;
// Output current and averaged gyroscope values
Serial.print("gyro x,y,z (current/average) = ");
for (int i = 0; i < 3; i++) {
Serial.print(gyro[i]);
Serial.print("/");
Serial.print(gyro_average[i] / (float) gyro_num_samples);
if (i < 2) Serial.print(" ");
else Serial.println();
}
}
}
void output_sensors_text(char raw_or_calibrated)
{
Serial.print("#A-"); Serial.print(raw_or_calibrated); Serial.print('=');
Serial.print(accel[0]); Serial.print(",");
Serial.print(accel[1]); Serial.print(",");
Serial.print(accel[2]); Serial.println();
Serial.print("#M-"); Serial.print(raw_or_calibrated); Serial.print('=');
Serial.print(magnetom[0]); Serial.print(",");
Serial.print(magnetom[1]); Serial.print(",");
Serial.print(magnetom[2]); Serial.println();
Serial.print("#G-"); Serial.print(raw_or_calibrated); Serial.print('=');
Serial.print(gyro[0]); Serial.print(",");
Serial.print(gyro[1]); Serial.print(",");
Serial.print(gyro[2]); Serial.println();
}
void output_sensors_binary()
{
Serial.write((byte*) accel, 12);
Serial.write((byte*) magnetom, 12);
Serial.write((byte*) gyro, 12);
}
void output_sensors()
{
if (output_mode == OUTPUT__MODE_SENSORS_RAW)
{
if (output_format == OUTPUT__FORMAT_BINARY)
output_sensors_binary();
else if (output_format == OUTPUT__FORMAT_TEXT)
output_sensors_text('R');
}
else if (output_mode == OUTPUT__MODE_SENSORS_CALIB)
{
// Apply sensor calibration
compensate_sensor_errors();
if (output_format == OUTPUT__FORMAT_BINARY)
output_sensors_binary();
else if (output_format == OUTPUT__FORMAT_TEXT)
output_sensors_text('C');
}
else if (output_mode == OUTPUT__MODE_SENSORS_BOTH)
{
if (output_format == OUTPUT__FORMAT_BINARY)
{
output_sensors_binary();
compensate_sensor_errors();
output_sensors_binary();
}
else if (output_format == OUTPUT__FORMAT_TEXT)
{
output_sensors_text('R');
compensate_sensor_errors();
output_sensors_text('C');
}
}
}