Skip to content

Commit 210715c

Browse files
MPU to IMU
Deleted references to MPU. TODO: Fix and refactor balancing bot.
1 parent 78bcb16 commit 210715c

File tree

2 files changed

+18
-44
lines changed

2 files changed

+18
-44
lines changed

examples/RoboHeartBalanceBot/RoboHeartBalanceBot.ino

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
* Check out https://roboheart.de/en_gb/ for more information about RoboHeart.
1616
*/
1717

18+
19+
//TODO: Refactor, storeprohibited error fix.
20+
1821
#include <RoboHeart.h>
1922
#include <RoboHeartTimer.h>
2023

@@ -71,7 +74,7 @@ void tick() {
7174
// and later used to indicate stable vertical position
7275
// of the Balancing Bot.
7376
void processPinInterrupt() {
74-
offsetAngleDeg = heart.mpu.getAngleX();
77+
offsetAngleDeg = heart.imu.readFloatGyroX();
7578
targetAngleDeg = offsetAngleDeg;
7679
}
7780

@@ -83,28 +86,10 @@ void setup() {
8386

8487
// Initialize RoboHeart with or without request for IMU automatic
8588
// 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();
10893

10994
// Configure Button which is used to set the
11095
// stable vertical position of the Balancing Bot.
@@ -128,7 +113,7 @@ void loop() {
128113
if (pidControlTick >= PID_CONTROL_PRESCALER) {
129114
unsigned long curTimeIntervalMS = millis();
130115
pidControlTick = 0;
131-
currentAngleDeg = processAngle(heart.mpu.getAngleX());
116+
currentAngleDeg = processAngle(heart.imu.readFloatGyroX());
132117

133118
float error = currentAngleDeg - targetAngleDeg;
134119
errorSum = constrain(errorSum + error, -Kp * 50, Kp * 50);

examples/RoboHeartBalanceBotContol/RoboHeartBalanceBotContol.ino

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
* Check out https://roboheart.de/en_gb/ for more information about RoboHeart.
1919
*/
2020

21+
22+
//TODO: Refactor, storeprohibited error fix.
23+
2124
#include <RoboHeart.h>
2225
#include <RoboHeartBLE.h>
2326
#include <RoboHeartTimer.h>
@@ -192,7 +195,7 @@ void tick() {
192195
// and later used to indicate stable vertical position
193196
// of the Balancing Bot.
194197
void processPinInterrupt() {
195-
offsetAngleDeg = heart.mpu.getAngleX();
198+
offsetAngleDeg = heart.imu.readFloatGyroX();
196199
targetAngleDeg = offsetAngleDeg;
197200
}
198201

@@ -206,24 +209,10 @@ void setup() {
206209

207210
// Initialize RoboHeart with or without request for IMU automatic
208211
// calibration
209-
bool mpuRequestCalibration = true;
210-
heart.begin(mpuRequestCalibration);
211-
212-
// One can set mpuRequestCalibration = false and
213-
// use manual offsets (taken from previous calibrations)
214-
// heart.mpu.setGyroOffsets(-1.76, -0.07, -0.9);
215-
// heart.mpu.setAccOffsets(0.04, -0.00, 0.11);
216-
217-
// print calculated offsets
218-
char offsets_msg[200];
219-
sprintf(offsets_msg, "Offsets Gyro gx: %f, gy: %f gz: %f",
220-
heart.mpu.getGyroXoffset(), heart.mpu.getGyroYoffset(),
221-
heart.mpu.getGyroZoffset());
222-
Serial.println(offsets_msg);
223-
sprintf(offsets_msg, "Offsets Accel ax: %f, ay: %f az: %f",
224-
heart.mpu.getAccXoffset(), heart.mpu.getAccYoffset(),
225-
heart.mpu.getAccZoffset());
226-
Serial.println(offsets_msg);
212+
heart.begin();
213+
214+
//Run IMU calibration and calculation of absolute rotation
215+
heart.setAutomaticRotation();
227216

228217
// BLE configuration
229218

@@ -261,7 +250,7 @@ void loop() {
261250
if (pidControlTick >= PID_CONTROL_PRESCALER) {
262251
unsigned long curTimeIntervalMS = millis();
263252
pidControlTick = 0;
264-
currentAngleDeg = processAngle(heart.mpu.getAngleX());
253+
currentAngleDeg = processAngle(heart.imu.readFloatGyroX());
265254

266255
float error = currentAngleDeg - targetAngleDeg;
267256
errorSum = constrain(errorSum + error, -Kp * 50, Kp * 50);

0 commit comments

Comments
 (0)