-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path06_getIMUGyro_LSM9DS1.cpp
60 lines (52 loc) · 1.52 KB
/
06_getIMUGyro_LSM9DS1.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/* File: 06_getIMUGyro_LSM9DS1.cpp
* Author: Philippe Latu
* Source: https://github.com/platu/libsensehat-cpp
*
* This example program collects orientation measures from the LSM9DS1 IMU
* sensor.
*
* Function prototypes:
*
* void senseSetIMUConfig(bool compass_enabled, bool gyro_enabled, bool
* accel_enabled);
*
* bool senseGetOrientationRadians(double &picth, double &roll, double &yaw);
*
* bool senseGetOrientationDegrees(double &pitch, double &roll, double &yaw);
*
* The program simply calls one of the two functions
*/
#include <iostream>
#include <iomanip>
#include <chrono>
#include <thread>
#include <console_io.h>
#include <sensehat.h>
using namespace std;
using namespace std::this_thread; // sleep_for, sleep_until
using namespace std::chrono; // nanoseconds, system_clock, seconds
int main() {
unsigned int time = 0;
double x, y, z;
if (senseInit()) {
cout << "-------------------------------" << endl
<< "Sense Hat initialization Ok." << endl;
senseClear();
for (time = 0; time < 60; time++) {
// wait for 500ms
sleep_for(milliseconds(500));
cout << "Gyrometer in radians/s." << endl;
if (senseGetGyroRadians(x, y, z)) {
cout << fixed << setprecision(6) << "Roll = " << x
<< " Pitch = " << y << " Yaw = " << z << endl;
} else
cout << "Error. No measures." << endl;
}
cout << endl << "Waiting for keypress." << endl;
getch();
senseShutdown();
cout << "-------------------------------" << endl
<< "Sense Hat shut down." << endl;
}
return EXIT_SUCCESS;
}