My Project
Sensors
imu.cpp
Go to the documentation of this file.
1
// Copyright (c) 2023 Samuli Nyman
2
// SPDX-License-Identifier: MIT
3
4
#include "
imu.h
"
5
#include "Arduino.h"
6
#include "LSM6.h"
7
8
LSM6
imu
;
9
10
uint8_t
initIMU
()
11
{
12
if
(!
imu
.init(LSM6::device_DS33,LSM6::sa0_low))
13
{
14
Serial.println(
"Failed to detect and initialize IMU!"
);
15
return
1;
16
}
17
imu
.enableDefault();
18
return
0;
19
}
20
21
uint8_t
readAcceleration
(
float
&x,
float
&y,
float
&z){
22
imu
.read();
23
x =
imu
.a.x * 0.061 * 0.001;
24
y =
imu
.a.y * 0.061 * 0.001;
25
z =
imu
.a.z * 0.061 * 0.001;
26
return
0;
27
}
28
29
uint8_t
readGyro
(
float
&x,
float
&y,
float
&z){
30
imu
.read();
31
x =
imu
.g.x * 8.75 * 0.001;
32
y =
imu
.g.y * 8.75 * 0.001;
33
z =
imu
.g.z * 8.75 * 0.001;
34
return
0;
35
}
36
37
float
readAccelX
() {
38
imu
.read();
39
return
imu
.a.x * 0.061 * 0.001;
40
}
41
42
float
readAccelY
() {
43
imu
.read();
44
return
imu
.a.y * 0.061 * 0.001;
45
}
46
47
float
readAccelZ
() {
48
imu
.read();
49
return
imu
.a.z * 0.061 * 0.001;
50
}
51
52
float
readGyroX
() {
53
imu
.read();
54
return
imu
.g.x * 8.75 * 0.001;
55
}
56
57
float
readGyroY
() {
58
imu
.read();
59
return
imu
.g.y * 8.75 * 0.001;
60
}
61
62
float
readGyroZ
() {
63
imu
.read();
64
return
imu
.g.z * 8.75 * 0.001;
65
}
readAccelX
float readAccelX()
Definition:
imu.cpp:37
imu.h
readGyroY
float readGyroY()
Definition:
imu.cpp:57
readAcceleration
uint8_t readAcceleration(float &x, float &y, float &z)
Definition:
imu.cpp:21
imu
LSM6 imu
Definition:
imu.cpp:8
initIMU
uint8_t initIMU()
Definition:
imu.cpp:10
readAccelZ
float readAccelZ()
Definition:
imu.cpp:47
readGyroX
float readGyroX()
Definition:
imu.cpp:52
readGyro
uint8_t readGyro(float &x, float &y, float &z)
Definition:
imu.cpp:29
readAccelY
float readAccelY()
Definition:
imu.cpp:42
readGyroZ
float readGyroZ()
Definition:
imu.cpp:62
Generated by
1.8.17