-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revamped Service Light, much IMU headway.
- Loading branch information
1 parent
ec2c92e
commit 09feaeb
Showing
12 changed files
with
247 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
examples/sensor_fusion/sensor_calibration_CALfredo/sensor_calibration_CALfredo.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#include <Alfredo_NoU3.h> | ||
|
||
void setup() { | ||
Serial.begin(115200); | ||
NoU3.begin(); | ||
} | ||
|
||
long lastPrintMs = 0; // Stores the last time the function was called | ||
|
||
void loop() { | ||
|
||
NoU3.updateIMUs(); | ||
|
||
if (millis() - lastPrintMs >= 20) { | ||
lastPrintMs = millis(); // Update the last time the function was called | ||
formatPrint(NoU3.acceleration_x); | ||
Serial.print(", "); | ||
formatPrint(NoU3.acceleration_y); | ||
Serial.print(", "); | ||
formatPrint(NoU3.acceleration_z); | ||
Serial.print(", "); | ||
formatPrint(NoU3.gyroscope_x); | ||
Serial.print(", "); | ||
formatPrint(NoU3.gyroscope_y); | ||
Serial.print(", "); | ||
formatPrint(NoU3.gyroscope_z); | ||
Serial.print(", "); | ||
formatPrint(NoU3.magnetometer_x); | ||
Serial.print(", "); | ||
formatPrint(NoU3.magnetometer_y); | ||
Serial.print(", "); | ||
formatPrint(NoU3.magnetometer_z); | ||
Serial.println(""); | ||
} | ||
} | ||
|
||
void formatPrint(float num) { | ||
char buffer[11]; | ||
snprintf(buffer, sizeof(buffer), "%.3f ", num); | ||
Serial.print(buffer); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
76 changes: 76 additions & 0 deletions
76
examples/sensor_fusion/sensor_fusion_compass/sensor_fusion_compass.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#include <Alfredo_NoU3.h> | ||
|
||
float yaw_gyro_deg = 0; | ||
float yaw_mag_deg = 0; | ||
float wrapped_yaw_mag_deg = 0; | ||
float yaw = 0; | ||
|
||
const float alpha = 0.98; // Complementary filter weighting | ||
unsigned long lastTime = 0; | ||
|
||
float gyro_z_offset_degrees = 0.444; | ||
|
||
void setup() { | ||
Serial.begin(115200); | ||
NoU3.begin(); | ||
|
||
} | ||
|
||
void loop() { | ||
|
||
if (NoU3.updateIMUs()) { | ||
|
||
unsigned long currentTime = millis(); | ||
float dt = (currentTime - lastTime) / 1000.0; | ||
lastTime = currentTime; | ||
|
||
// Gyroscope yaw update | ||
yaw_gyro_deg += (NoU3.gyroscope_z - gyro_z_offset_degrees) * dt; | ||
|
||
// Magnetometer yaw | ||
yaw_mag_deg = -1 * degrees(atan2(NoU3.magnetometer_y, NoU3.magnetometer_x)); | ||
|
||
// Wrap Magnetometer yaw | ||
wrapped_yaw_mag_deg = wrapYaw(yaw_mag_deg); | ||
|
||
// Apply complementary filter with drift compensation | ||
yaw = alpha * (yaw_gyro_deg) + (1 - alpha) * wrapped_yaw_mag_deg; | ||
|
||
// Print results | ||
Serial.print("yaw_gyro_deg: "); | ||
Serial.print(yaw_gyro_deg); | ||
Serial.print(" wrapped_yaw_mag_deg: "); | ||
Serial.print(wrapped_yaw_mag_deg); | ||
Serial.print(" Yaw: "); | ||
Serial.print(yaw); | ||
|
||
Serial.println(" "); | ||
|
||
} | ||
} | ||
|
||
// Function to process yaw and keep track of rotations | ||
float wrapYaw(float currentYaw) { | ||
static bool isInitialized = false; | ||
static int rotations = 0; | ||
static float previousYaw = 0; | ||
|
||
if(isInitialized == false){ | ||
previousYaw = currentYaw; | ||
isInitialized = true; | ||
} | ||
|
||
// Check for wrapping | ||
if (currentYaw - previousYaw > 180.0) { | ||
rotations--; // Wrapped from -180 to 180 | ||
} else if (currentYaw - previousYaw < -180.0) { | ||
rotations++; // Wrapped from 180 to -180 | ||
} | ||
|
||
// Wrap the yaw angle between -180 and 180 | ||
float wrappedYaw = currentYaw + rotations * 360.0; | ||
|
||
previousYaw = currentYaw; | ||
|
||
return wrappedYaw; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
name=Alfredo-NoU3 | ||
version=1.0.5 | ||
version=1.0.6 | ||
author=Alfredo Systems | ||
maintainer=Jacob Williams ([email protected]) | ||
sentence=Library for the Alfredo NoU3 robot control board. | ||
|
Oops, something went wrong.