11#pragma once
2+
3+ #include < freertos/FreeRTOS.h>
4+
25#include " rbcx.pb.h"
36namespace rb {
47
@@ -57,83 +60,95 @@ class Mpu {
5760 */
5861 void sendStop ();
5962
63+ /* *
64+ * @brief Records current Gyro and Accelerometer data as "start" position
65+ * and subtracts it from future readings
66+ */
67+ void setCalibrationData ();
68+
69+ /* *
70+ * @brief Clears the data recorded by setCalibrationData
71+ */
72+ void clearCalibrationData ();
73+
6074 /* *
6175 * @brief Get the Mpu acceleration data.
62- * @return The Mpu acceleration data.
76+ * @return The Mpu acceleration data in Gs .
6377 */
6478 MpuVector getAcc ();
6579
6680 /* *
6781 * @brief Get the Mpu acceleration data on the X axis.
68- * @return The Mpu acceleration data on the X axis.
82+ * @return The Mpu acceleration data on the X axis in Gs .
6983 */
7084 float getAccX ();
7185
7286 /* *
7387 * @brief Get the Mpu acceleration data on the Y axis.
74- * @return The Mpu acceleration data on the Y axis.
88+ * @return The Mpu acceleration data on the Y axis in Gs .
7589 */
7690 float getAccY ();
7791
7892 /* *
7993 * @brief Get the Mpu acceleration data on the Z axis.
80- * @return The Mpu acceleration data on the Z axis.
94+ * @return The Mpu acceleration data on the Z axis in Gs .
8195 */
8296 float getAccZ ();
8397
8498 /* *
8599 * @brief Get the Mpu gyroscope data.
86- * @return The Mpu gyroscope data.
100+ * @return The Mpu gyroscope data in degrees per second .
87101 */
88102 MpuVector getGyro ();
89103
90104 /* *
91105 * @brief Get the Mpu gyroscope data on the X axis.
92- * @return The Mpu gyroscope data on the X axis.
106+ * @return The Mpu gyroscope data on the X axis in degrees per second .
93107 */
94108 float getGyroX ();
95109
96110 /* *
97111 * @brief Get the Mpu gyroscope data on the Y axis.
98- * @return The Mpu gyroscope data on the Y axis.
112+ * @return The Mpu gyroscope data on the Y axis in degrees per second .
99113 */
100114 float getGyroY ();
101115
102116 /* *
103117 * @brief Get the Mpu gyroscope data on the Z axis.
104- * @return The Mpu gyroscope data on the Z axis.
118+ * @return The Mpu gyroscope data on the Z axis in degrees per second .
105119 */
106120 float getGyroZ ();
107121
108122 /* *
109123 * @brief Get the Mpu angle data.
110- * @return The Mpu angle data.
124+ * @return The Mpu angle data in degrees .
111125 */
112126 MpuVector getAngle ();
113127
114128 /* *
115129 * @brief Get the Mpu angle data on the X axis.
116- * @return The Mpu angle data on the X axis.
130+ * @return The Mpu angle data on the X axis in degrees .
117131 */
118132 float getAngleX ();
119133
120134 /* *
121135 * @brief Get the Mpu angle data on the Y axis.
122- * @return The Mpu angle data on the Y axis.
136+ * @return The Mpu angle data on the Y axis in degrees .
123137 */
124138 float getAngleY ();
125139
126140 /* *
127141 * @brief Get the Mpu angle data on the Z axis.
128- * @return The Mpu angle data on the Z axis.
142+ *
143+ * The Z angle is relative to the original heading of the robot at the start of the program,
144+ * or after latest resetAngleZ() call, NOT to geographic north.
145+ *
146+ * @return The Mpu angle data on the Z axis in degrees.
129147 */
130148 float getAngleZ ();
131149
132- /* *
133- * @brief Get the Mpu sending interval.
134- * @return The Mpu sending interval
135- */
136- long getInterval ();
150+ // Reset heading back to 0
151+ void resetAngleZ ();
137152
138153 /* *
139154 * @brief Set the Mpu compression coefficient (10 - 20).
@@ -152,10 +167,9 @@ class Mpu {
152167 MpuMotion9 m_mpuMotion;
153168 MpuMotion6 m_mpuMotionOffset;
154169
155- long m_preInterval;
156- int32_t m_interval;
157- bool m_firstRead = true ;
158- uint8_t m_compressCoef = 4 ;
170+ TickType_t m_lastTicks;
171+
172+ uint8_t m_compressCoef;
159173
160174 Mpu ();
161175 Mpu (const Mpu&) = delete ;
@@ -166,7 +180,6 @@ class Mpu {
166180 void calculateGyro (const CoprocStat_MpuVector& gyro);
167181 void calculateAngle ();
168182
169- void calcOffsets ();
170183 float wrap (float angle, float limit);
171184
172185 void sendMpuReq (CoprocReq_MpuReq mpuReq);
0 commit comments