Skip to content

Commit aa3c301

Browse files
committed
Keep trying to calibrate gyro until it is standing still
1 parent c05a1b8 commit aa3c301

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

Firmware/Balanduino/Balanduino.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ void testMotorSpeed(double *leftSpeed, double *rightSpeed, double leftScaler, do
228228
void calibrateAcc();
229229
void printValues();
230230
void setValues(char *input);
231-
void calibrateGyro();
231+
bool calibrateGyro();
232232
bool checkMinMax(int16_t *array, uint8_t length, int16_t maxDifference);
233233

234234
#endif

Firmware/Balanduino/Balanduino.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,8 @@ void setup() {
235235
pitch = accAngle;
236236
gyroAngle = accAngle;
237237

238-
/* Find gyro zero value */
239-
calibrateGyro();
238+
/* Calibrate gyro zero value */
239+
while (calibrateGyro()); // Run again if the robot is moved while calibrating
240240

241241
LED::SetDirWrite();
242242

Firmware/Balanduino/Tools.ino

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ void setValues(char *input) {
408408
}
409409
#endif // ENABLE_TOOLS or ENABLE_SPP
410410

411-
void calibrateGyro() {
411+
bool calibrateGyro() {
412412
int16_t gyroXbuffer[25];
413413
for (uint8_t i = 0; i < 25; i++) {
414414
while (i2cRead(0x43, i2cBuffer, 2));
@@ -418,11 +418,12 @@ void calibrateGyro() {
418418
if (!checkMinMax(gyroXbuffer, 25, 2000)) {
419419
Serial.print(F("Gyro calibration error"));
420420
buzzer::Set();
421-
while (1); // Halt
421+
return 1;
422422
}
423423
for (uint8_t i = 0; i < 25; i++)
424424
gyroXzero += gyroXbuffer[i];
425425
gyroXzero /= 25;
426+
return 0;
426427
}
427428

428429
bool checkMinMax(int16_t *array, uint8_t length, int16_t maxDifference) { // Used to check that the robot is laying still while calibrating

0 commit comments

Comments
 (0)