summaryrefslogtreecommitdiff
path: root/debug/IMU_comp
diff options
context:
space:
mode:
authorAbel Tim <abel@main.home>2024-06-30 17:38:05 +0200
committerAbel Tim <abel@main.home>2024-06-30 17:38:05 +0200
commitb3c098fbb5bc0f64feda8d20e0dafb91f00aa20a (patch)
tree7e51b8b3f711b48df3bd9b667b6803efac610f81 /debug/IMU_comp
parent7ff57db19906283e9edd5a8968a7fc1c8351eeaf (diff)
downloadrobotica-b3c098fbb5bc0f64feda8d20e0dafb91f00aa20a.tar.gz
robotica-b3c098fbb5bc0f64feda8d20e0dafb91f00aa20a.zip
motor drivers
Diffstat (limited to 'debug/IMU_comp')
-rw-r--r--debug/IMU_comp/IMU_comp.ino25
1 files changed, 19 insertions, 6 deletions
diff --git a/debug/IMU_comp/IMU_comp.ino b/debug/IMU_comp/IMU_comp.ino
index 40d99b6..0c3928d 100644
--- a/debug/IMU_comp/IMU_comp.ino
+++ b/debug/IMU_comp/IMU_comp.ino
@@ -1,11 +1,9 @@
-//https://www.pololu.com/product/2862
#include <Wire.h>
#include <LIS3MDL.h>
+#include <math.h>
LIS3MDL mag;
-char report[80];
-
void setup()
{
Serial.begin(9600);
@@ -24,9 +22,24 @@ void loop()
{
mag.read();
- snprintf(report, sizeof(report), "M: %6d %6d %6d",
- mag.m.x, mag.m.y, mag.m.z);
- Serial.println(report);
+ // Calculate heading
+ float heading = atan2(mag.m.y, mag.m.x);
+ if (heading < 0)
+ heading += 2 * PI; // Normalize heading to positive angles
+
+ // Convert from radians to degrees
+ float headingDegrees = heading * 180.0 / PI;
+
+ // Adjust for magnetic declination if needed
+ // headingDegrees += magneticDeclination;
+
+ // Normalize headingDegrees to [0, 360) range
+ if (headingDegrees >= 360.0)
+ headingDegrees -= 360.0;
+
+ // Print heading
+ Serial.print("Heading: ");
+ Serial.println(headingDegrees);
delay(100);
}