Skip to content

Commit 928cf17

Browse files
heyisulaonelicodes
andcommitted
Refactor MPU6050 integration and remove obstacle avoidance
Replaced the 'MPU6050_tockn' library with 'electroniccats/MPU6050' and refactored the MotionTracker class for improved initialization, calibration, and data processing. Deleted the obstacle avoidance mode implementation (obstacle_avoidance.cpp/h). Updated main.cpp to demonstrate real-time MPU6050 data output. These changes streamline sensor handling and remove unused obstacle avoidance code. Co-Authored-By: Oneli Wijesuriya <247418039+onelicodes@users.noreply.github.com>
1 parent fd9ae80 commit 928cf17

7 files changed

Lines changed: 170 additions & 209 deletions

File tree

ESP32-S3-Main/platformio.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ lib_deps =
1919
sparkfun/SparkFun MAX3010x Pulse and Proximity Sensor Library@^1.1.2
2020
adafruit/Adafruit Unified Sensor@^1.1.15
2121
hasenradball/AM2302-Sensor@^1.4.0
22-
tockn/MPU6050_tockn@^1.5.2
2322
ericksimoes/Ultrasonic@^3.0.0
2423
panjkrc/tcs3200@^1.3.1
2524
codingabi/KY040@^1.0.3
2625
powerbroker2/SerialTransfer@^3.1.5
2726
mobizt/Firebase ESP32 Client@^4.4.17
27+
electroniccats/MPU6050@^1.4.4
2828
build_flags =
2929
-DARDUINO_USB_MODE=0
3030
-DARDUINO_USB_CDC_ON_BOOT=0

ESP32-S3-Main/src/config/constants.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
#ifndef CONSTANTS_H
32
#define CONSTANTS_H
43

ESP32-S3-Main/src/main.cpp

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,51 @@
11
#include <Arduino.h>
2+
#include "sensors/mpu6050.h"
23

4+
MotionTracker motionTracker;
5+
unsigned long lastPrintTime = 0;
36

47
void setup() {
8+
Serial.begin(115200);
9+
while (!Serial && millis() < 3000);
510

11+
Serial.println("\n=== MPU6050 Motion Tracker ===");
12+
Serial.println("Initializing...\n");
13+
14+
if (!motionTracker.begin()) {
15+
Serial.println("ERROR: MPU6050 initialization failed!");
16+
while (1) delay(1000);
17+
}
18+
19+
Serial.println("MPU6050 initialized successfully!");
20+
21+
motionTracker.autoCalibrate();
22+
23+
Serial.println("--- Starting measurements ---\n");
24+
Serial.println("Time(s) | Roll(°) | Pitch(°) | Fwd(g) | Side(g) | Mag(g) | RawX | RawY | RawZ");
25+
Serial.println("--------|---------|----------|--------|---------|--------|------|------|------");
26+
27+
lastPrintTime = millis();
628
}
729

830
void loop() {
31+
motionTracker.update();
932

10-
11-
}
33+
if (millis() - lastPrintTime >= 100) {
34+
lastPrintTime = millis();
35+
36+
float roll = motionTracker.getRoll();
37+
float pitch = motionTracker.getPitch();
38+
float fwd = motionTracker.getForwardAcceleration();
39+
float side = motionTracker.getSideAcceleration();
40+
float mag = motionTracker.getAccelMagnitude();
41+
float rawX = motionTracker.getAccelX();
42+
float rawY = motionTracker.getAccelY();
43+
float rawZ = motionTracker.getAccelZ();
44+
45+
char buf[150];
46+
snprintf(buf, sizeof(buf),
47+
"%7.2f | %7.2f | %8.2f | %6.3f | %7.3f | %6.3f | %4.2f | %4.2f | %4.2f",
48+
millis()/1000.0, roll, pitch, fwd, side, mag, rawX, rawY, rawZ);
49+
Serial.println(buf);
50+
}
51+
}

ESP32-S3-Main/src/modes/obstacle_avoidance.cpp

Lines changed: 0 additions & 108 deletions
This file was deleted.

ESP32-S3-Main/src/modes/obstacle_avoidance.h

Lines changed: 0 additions & 42 deletions
This file was deleted.

0 commit comments

Comments
 (0)