15
15
* Check out https://roboheart.de/en_gb/ for more information about RoboHeart.
16
16
*/
17
17
18
+
19
+ // TODO: Refactor, storeprohibited error fix.
20
+
18
21
#include < RoboHeart.h>
19
22
#include < RoboHeartTimer.h>
20
23
@@ -71,7 +74,7 @@ void tick() {
71
74
// and later used to indicate stable vertical position
72
75
// of the Balancing Bot.
73
76
void processPinInterrupt () {
74
- offsetAngleDeg = heart.mpu . getAngleX ();
77
+ offsetAngleDeg = heart.imu . readFloatGyroX ();
75
78
targetAngleDeg = offsetAngleDeg;
76
79
}
77
80
@@ -83,28 +86,10 @@ void setup() {
83
86
84
87
// Initialize RoboHeart with or without request for IMU automatic
85
88
// calibration
86
- bool mpuRequestCalibration = true ;
87
- heart.begin (mpuRequestCalibration);
88
-
89
- // One can set mpuRequestCalibration = false and
90
- // use manual offsets (taken from previous calibrations)
91
- // heart.mpu.setGyroOffsets(-1.76, -0.07, -0.9);
92
- // heart.mpu.setAccOffsets(0.04, -0.00, 0.11);
93
-
94
- // use manual offsets (taken from previous calibrations)
95
- heart.mpu .setGyroOffsets (-1.76 , -0.07 , -0.9 );
96
- heart.mpu .setAccOffsets (0.04 , -0.00 , 0.11 );
97
-
98
- // print calculated offsets
99
- char offsets_msg[200 ];
100
- sprintf (offsets_msg, " Offsets Gyro gx: %f, gy: %f gz: %f" ,
101
- heart.mpu .getGyroXoffset (), heart.mpu .getGyroYoffset (),
102
- heart.mpu .getGyroZoffset ());
103
- Serial.println (offsets_msg);
104
- sprintf (offsets_msg, " Offsets Accel ax: %f, ay: %f az: %f" ,
105
- heart.mpu .getAccXoffset (), heart.mpu .getAccYoffset (),
106
- heart.mpu .getAccZoffset ());
107
- Serial.println (offsets_msg);
89
+ heart.begin ();
90
+
91
+ // Run IMU calibration and calculation of absolute rotation
92
+ heart.setAutomaticRotation ();
108
93
109
94
// Configure Button which is used to set the
110
95
// stable vertical position of the Balancing Bot.
@@ -128,7 +113,7 @@ void loop() {
128
113
if (pidControlTick >= PID_CONTROL_PRESCALER) {
129
114
unsigned long curTimeIntervalMS = millis ();
130
115
pidControlTick = 0 ;
131
- currentAngleDeg = processAngle (heart.mpu . getAngleX ());
116
+ currentAngleDeg = processAngle (heart.imu . readFloatGyroX ());
132
117
133
118
float error = currentAngleDeg - targetAngleDeg;
134
119
errorSum = constrain (errorSum + error, -Kp * 50 , Kp * 50 );
0 commit comments