-
Notifications
You must be signed in to change notification settings - Fork 0
/
gyro_test.cpp
55 lines (42 loc) · 999 Bytes
/
gyro_test.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
#include <stdio.h>
#include <bcm2835.h>
#include "I2Cdev.h"
#include "MPU6050.h"
#include <thread>
#include <time.h>
int main(int argc, char **argv)
{
MPU6050 gyro;
I2Cdev::initialize();
gyro.initialize();
gyro.setRate(0);
gyro.setClockSource(0);
gyro.setWakeFrequency(3);
gyro.setAccelerometerPowerOnDelay(3);
// set sample divider to 7
gyro.setSleepEnabled(false);
gyro.setWakeCycleEnabled(false);
//gyro.setRate(255);
int16_t ax, ay, az;
int16_t x_old = 0, y_old = 0, z_old = 0;
// measure time between two events
uint64_t start = bcm2835_st_read();
printf("start: %llu\n", start);
int i = 0;
int j = 0;
while (bcm2835_st_read() - start < 3000000)
{
gyro.getAcceleration(&ax, &ay, &az);
if (ax != x_old || ay != y_old || az != z_old)
{
//printf("%d: ax: %d, ay: %d, az: %d\n", i, ax, ay, az);
x_old = ax;
y_old = ay;
z_old = az;
i++;
}
j++;
}
printf("%d\n", i);
printf("%d\n", j);
}