forked from simonliu009/brushless-gimbal-brugi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Trace.ino
159 lines (131 loc) · 3.64 KB
/
Trace.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#include "Trace.h"
#include "MPU6050.h"
void printTrace(traceModeType traceMode)
{
Serial.print(F("traceData"));
switch (traceMode) {
case TRC_RC:
// ******* RC *********
Serial.print(F(" RC"));
for (char id = 0; id < RC_DATA_SIZE; id++)
{
printTrace_int(rcData[id].rx);
}
for (char id = 0; id < RC_DATA_SIZE; id++)
{
printTrace_int(rcData[id].valid);
}
for (char id = 0; id < RC_DATA_SIZE; id++)
{
printTrace_int(rcData[id].rcAuxSwitch1);
printTrace_int(rcData[id].rcAuxSwitch2);
}
break;
case TRC_AUX:
// ******* AUX *********
Serial.print(F(" AUX"));
printTrace_int(fpvModePitch || fpvModeFreezePitch);
printTrace_int(fpvModeRoll || fpvModeFreezeRoll);
printTrace_int(altModeAccTime);
break;
case TRC_MPU:
// ******* Main Status *********
Serial.print(F(" MPU"));
printTrace_int(mpu.readRealTemperature());
printTrace_int(mpu.i2cErrors);
break;
#ifdef TRACE_EXTRA
case TRC_IMU:
// ******* IMU *********
Serial.print(F(" IMU"));
printTrace_float(EstG.V.X);
printTrace_float(EstG.V.Y);
printTrace_float(EstG.V.Z);
printTrace_int(angle[ROLL]);
printTrace_int(angle[PITCH]);
break;
case TRC_GYRO:
// ******* Gyro Sensor *********
Serial.print(F(" GYRO"));
for (char axis = 0; axis < 3; axis++)
{
printTrace_int(gyroADC[axis]);
}
break;
case TRC_ACC:
// ******* ACC Sensor *********
Serial.print(F(" SENSOR_ACC"));
for (char axis = 0; axis < 3; axis++)
{
printTrace_int(accADC[axis]);
}
printTrace_int((int)accMag);
break;
case TRC_PID_PITCH:
// ******* PID Pitch *********
Serial.print(F(" PID_PITCH"));
printTrace_float(pitchAngleSet);
printTrace_int(angle[PITCH]);
printTrace_int(pitchMotorDrive);
printTrace_float((pitchAngleSet*1000-angle[PITCH])*0.001); // PID error
printTrace_int(pitchErrorSum);
break;
case TRC_PID_ROLL:
// ******* PID Roll *********
Serial.print(F(" PID_ROLL"));
printTrace_float(rollAngleSet);
printTrace_int(angle[ROLL]);
printTrace_int(rollMotorDrive);
printTrace_float((rollAngleSet*1000-angle[ROLL])*0.001); // PID error
printTrace_int(rollErrorSum);
break;
#endif
case TRC_OAC:
// ******* OAC mode 2 (replaces oac/acc mode) *********
Serial.print(F(" ACC2"));
printTrace_int(angle[PITCH]);
printTrace_int(angle[ROLL]);
break;
default:
break;
}
Serial.println(F(""));
}
void printTrace_int(int32_t value)
{
Serial.print(F(" "));
Serial.print(value);
}
void printTrace_float(float value)
{
float v = value * 1000;
Serial.print(F(" "));
Serial.print((int32_t)v);
}
void printMessage(msgSeverity_t msgSeverity, const __FlashStringHelper * msg) {
Serial.print(F("message "));
switch (msgSeverity) {
case MSG_INFO:
Serial.print(F("INFO: "));
Serial.println(msg);
break;
case MSG_WARNING:
Serial.print(F("WARNING: "));
Serial.println(msg);
break;
case MSG_ERROR:
Serial.print(F("ERROR: "));
Serial.println(msg);
break;
case MSG_VERSION:
Serial.print(F("VERSION: "));
Serial.print(F("BruGi "));
Serial.print(VERSION);
Serial.print(F(" "));
Serial.print(F(REVISION));
Serial.print(F(" MPU 0x"));
String s = String(MPU6050_DEFAULT_ADDRESS, HEX);
Serial.println(s);
break;
}
}