Skip to content

Commit d1c14d2

Browse files
Examples
Timer fixed, BalanceBot, rotation
1 parent 84672a2 commit d1c14d2

File tree

4 files changed

+9
-15
lines changed

4 files changed

+9
-15
lines changed

RoboHeartTimer.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@
1313

1414
PeriodicTimer::PeriodicTimer(void (*callback)(void),
1515
uint64_t timerPeriodMicroSec)
16-
: timer(timerBegin(3)) {
16+
: timer(timerBegin(1000000)) {
1717
timerAttachInterrupt(timer, callback);
1818
setTimePeriod(timerPeriodMicroSec);
1919
stop();
2020
}
2121

2222
PeriodicTimer::PeriodicTimer(void (*callback)(void),
2323
uint64_t timerPeriodMicroSec, Stream& debug)
24-
: timer(timerBegin(3)), _debug(&debug) {
24+
: timer(timerBegin(1000000)), _debug(&debug) {
2525
timerAttachInterrupt(timer, callback);
2626
setTimePeriod(timerPeriodMicroSec);
2727
stop();
@@ -30,7 +30,7 @@ PeriodicTimer::PeriodicTimer(void (*callback)(void),
3030
void PeriodicTimer::setTimePeriod(uint64_t timerPeriodMicroSec) {
3131

3232
timerStop(timer);
33-
timerWrite(timer, timerPeriodMicroSec);
33+
timerAlarm(timer, timerPeriodMicroSec, true, 0);
3434
timerRestart(timer);
3535
timerStart(timer);
3636
}

examples/RoboHeartBalanceBot/RoboHeartBalanceBot.ino

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

18-
19-
//TODO: Refactor, storeprohibited error fix.
20-
2118
#include <RoboHeart.h>
2219
#include <RoboHeartTimer.h>
2320

@@ -74,7 +71,7 @@ void tick() {
7471
// and later used to indicate stable vertical position
7572
// of the Balancing Bot.
7673
void processPinInterrupt() {
77-
offsetAngleDeg = heart.imu.readFloatGyroX();
74+
offsetAngleDeg = heart.getRotationX();
7875
targetAngleDeg = offsetAngleDeg;
7976
}
8077

@@ -113,7 +110,7 @@ void loop() {
113110
if (pidControlTick >= PID_CONTROL_PRESCALER) {
114111
unsigned long curTimeIntervalMS = millis();
115112
pidControlTick = 0;
116-
currentAngleDeg = processAngle(heart.imu.readFloatGyroX());
113+
currentAngleDeg = processAngle(heart.getRotationX());
117114

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

examples/RoboHeartBalanceBotContol/RoboHeartBalanceBotContol.ino

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

21-
22-
//TODO: Refactor, storeprohibited error fix.
23-
2421
#include <RoboHeart.h>
2522
#include <RoboHeartBLE.h>
2623
#include <RoboHeartTimer.h>
@@ -195,7 +192,7 @@ void tick() {
195192
// and later used to indicate stable vertical position
196193
// of the Balancing Bot.
197194
void processPinInterrupt() {
198-
offsetAngleDeg = heart.imu.readFloatGyroX();
195+
offsetAngleDeg = heart.getRotationX();
199196
targetAngleDeg = offsetAngleDeg;
200197
}
201198

@@ -250,7 +247,7 @@ void loop() {
250247
if (pidControlTick >= PID_CONTROL_PRESCALER) {
251248
unsigned long curTimeIntervalMS = millis();
252249
pidControlTick = 0;
253-
currentAngleDeg = processAngle(heart.imu.readFloatGyroX());
250+
currentAngleDeg = processAngle(heart.heart.getRotationX());
254251

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

examples/RoboHeartRotation/RoboHeartRotation.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ void setup() {
5252

5353
Serial.println("RoboHeart LSM6DS3 rotation demo");
5454

55-
calculateDiff();
55+
calculateDrifts();
5656
int counter = 0;
5757
Serial.println("RoboHeart calibrating...");
5858
while (isCalibrated() == 0) {
5959
counter++;
6060
if(counter > 3){
61-
calculateDiff();
61+
calculateDrifts();
6262
counter = 0;
6363
Serial.println("Calibration failed, trying again...");
6464
}

0 commit comments

Comments
 (0)