-
-
Notifications
You must be signed in to change notification settings - Fork 285
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
75 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#include "imu.h" | ||
#include "pins.h" | ||
#include <LSM6DSOSensor.h> | ||
#include <PioSPI.h> | ||
|
||
PioSPI spiBus(PIN_IMU_MOSI, PIN_IMU_MISO, PIN_IMU_SCK, PIN_IMU_CS, SPI_MODE3, 1000000); | ||
LSM6DSOSensor IMU(&spiBus, PIN_IMU_CS, 1000000); | ||
int32_t accelerometer[3]; | ||
int32_t gyroscope[3]; | ||
|
||
bool init_imu() | ||
{ | ||
spiBus.begin(); | ||
int status = IMU.begin(); | ||
if (status != 0) | ||
return false; | ||
|
||
if (IMU.Enable_G() != 0) | ||
return false; | ||
|
||
if (IMU.Enable_X() != 0) | ||
return false; | ||
return true; | ||
} | ||
|
||
bool imu_read(float *acceleration_mss, float *gyro_rads, float *mag_uT) | ||
{ | ||
bool success = true; | ||
success &= IMU.Get_X_Axes(accelerometer) == 0; | ||
success &= IMU.Get_G_Axes(gyroscope) == 0; | ||
|
||
acceleration_mss[0] = accelerometer[0] * 9.81 / 1000.0; | ||
acceleration_mss[1] = accelerometer[1] * 9.81 / 1000.0; | ||
acceleration_mss[2] = accelerometer[2] * 9.81 / 1000.0; | ||
|
||
gyro_rads[0] = gyroscope[0] * (PI/180.0) / 1000.0; | ||
gyro_rads[1] = gyroscope[1] * (PI/180.0) / 1000.0; | ||
gyro_rads[2] = gyroscope[2] * (PI/180.0) / 1000.0; | ||
|
||
mag_uT[0] = 0; | ||
mag_uT[1] = 0; | ||
mag_uT[2] = 0; | ||
|
||
return success; | ||
} | ||
|
||
void imu_loop() | ||
{ | ||
} |
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