-
Notifications
You must be signed in to change notification settings - Fork 145
/
Copy pathRTIMULibDrive.cpp
79 lines (59 loc) · 2.05 KB
/
RTIMULibDrive.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
//
// Copyright (c) 2014 richards-tech
//
// This file is part of RTIMULib
//
// RTIMULib is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// RTIMULib is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with RTIMULib. If not, see <http://www.gnu.org/licenses/>.
//
#include "RTIMULib.h"
int main()
{
int sampleCount = 0;
int sampleRate = 0;
uint64_t rateTimer;
uint64_t displayTimer;
uint64_t now;
// using RTIMULib here allows it to use the .ini file generated by RTIMULibDemo.
RTIMUSettings *settings = new RTIMUSettings("RTIMULib");
RTIMU *imu = RTIMU::createIMU(settings);
if (imu == NULL) {
printf("No IMU found\n");
exit(1);
}
// set up IMU
imu->IMUInit();
// set up for rate timer
rateTimer = displayTimer = RTMath::currentUSecsSinceEpoch();
// now just process data
while (1) {
// poll at the rate recommended by the IMU
usleep(imu->IMUGetPollInterval() * 1000);
while (imu->IMURead()) {
RTIMU_DATA imuData = imu->getIMUData();
sampleCount++;
now = RTMath::currentUSecsSinceEpoch();
// display 10 times per second
if ((now - displayTimer) > 10000) {
printf("Sample rate %d: %s\r", sampleRate, RTMath::displayDegrees("", imuData.fusionPose));
displayTimer = now;
}
// update rate every second
if ((now - rateTimer) > 1000000) {
sampleRate = sampleCount;
sampleCount = 0;
rateTimer = now;
}
}
}
}