-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from ASU-ASCEND/LSM9DS1-Calibration
Added LSM9DS1 sensor calibration code.
- Loading branch information
Showing
2 changed files
with
54 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
//LSM9DS1 Calibration Code | ||
|
||
#include <SparkFunLSM9DS1.h> | ||
|
||
LSM9DS1 IMU(SPI_MODE, 10); // Adjust CS pin accordingly | ||
|
||
void setup() { | ||
Serial.begin(115200); | ||
if (!IMU.begin()) { | ||
Serial.println("Failed to communicate with LSM9DS1."); | ||
while (1); | ||
} | ||
|
||
// Calibrate sensors | ||
calibrateGyro(); | ||
calibrateAccel(); | ||
} | ||
|
||
void loop() { | ||
// Read and output calibrated data | ||
} | ||
|
||
void calibrateGyro() { | ||
// Implement gyroscope calibration as shown earlier | ||
// Example | ||
float gx, gy, gz; | ||
int samples = 1000; | ||
float gx_offset = 0, gy_offset = 0, gz_offset = 0; | ||
|
||
for (int i = 0; i < samples; i++) { | ||
IMU.readGyroscope(gx, gy, gz); | ||
gx_offset += gx; | ||
gy_offset += gy; | ||
gz_offset += gz; | ||
delay(2); | ||
} | ||
|
||
gx_offset /= samples; | ||
gy_offset /= samples; | ||
gz_offset /= samples; | ||
|
||
// Store offsets for later use | ||
} | ||
|
||
void calibrateAccel() { | ||
// Implement accelerometer calibration | ||
} |
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