N4 Flight Software
N4
Flight software used for the N4 flight computers
Toggle main menu visibility
Loading...
Searching...
No Matches
mpu.h
1
// MPU6050 class
2
#ifndef MPU_H
3
#define MPU_H
4
5
#include "Arduino.h"
6
#include <Wire.h>
7
#include <math.h>
8
#include "
defs.h
"
9
10
11
// divisor factors based on full scale ranges
12
#define ACCEL_FACTOR_2G 16384
13
#define ACCEL_FACTOR_4G 8192
14
#define ACCEL_FACTOR_8G 4096
15
#define ACCEL_FACTOR_16G 2048
16
#define GYRO_FACTOR_250 131
17
#define GYRO_FACTOR_500 65.5
18
#define GYRO_FACTOR_1000 32.8
19
#define GYRO_FACTOR_2000 16.4
20
21
// MPU6050 addresses definitions
22
#define MPU6050_ADDRESS 0x68
23
#define GYRO_CONFIG 0x1B
24
#define ACCEL_CONFIG 0x1C
25
#define PWR_MNGMT_1 0x6B
26
#define RESET 0x00
27
#define SET_GYRO_FS_250 0x00
28
#define SET_GYRO_FS_500 0x01
29
#define SET_GYRO_FS_1000 0x02
30
#define SET_GYRO_FS_2000 0x18
31
#define SET_ACCEL_FS_2G 0x00
32
#define SET_ACCEL_FS_4G 0x01
33
#define SET_ACCEL_FS_8G 0x02
34
#define SET_ACCEL_FS_16G 0x18
35
#define ACCEL_XOUT_H 0x3B
36
#define ACCEL_XOUT_L 0x3C
37
#define ACCEL_YOUT_H 0x3D
38
#define ACCEL_YOUT_L 0x3E
39
#define ACCEL_ZOUT_H 0x3F
40
#define ACCEL_ZOUT_L 0x40
41
#define GYRO_XOUT_H 0x43
42
#define GYRO_XOUT_L 0x44
43
#define GYRO_YOUT_H 0x45
44
#define GYRO_YOUT_L 0x46
45
#define GYRO_ZOUT_H 0x47
46
#define GYRO_ZOUT_L 0x48
47
#define TEMP_OUT_H 0x41
48
#define TEMP_OUT_L 0x42
49
#define ONE_G 9.80665
50
#define TO_DEG_FACTOR 57.32
51
52
class
MPU6050 {
53
private
:
54
uint8_t _address;
55
uint32_t _accel_fs_range;
56
uint32_t _gyro_fs_range;
57
58
public
:
59
// sensor data
60
int16_t acc_x, acc_y, acc_z;
// raw acceleration values
61
float
acc_x_real, acc_y_real, acc_z_real;
// converted acceleration values
62
int16_t ang_vel_x, ang_vel_y, ang_vel_z;
63
float
ang_vel_x_real, ang_vel_y_real, ang_vel_z_real;
// converted angular velocity values
64
int16_t temp;
65
float
temp_real;
66
67
float
pitch_angle, roll_angle;
68
float
acc_x_ms, acc_y_ms, acc_z_ms;
// acceleration in m/s^2
69
70
71
MPU6050(uint8_t address, uint32_t accel_fs_range, uint32_t gyro_fs_range);
72
uint8_t init();
73
float
readXAcceleration
();
74
float
readYAcceleration
();
75
float
readZAcceleration
();
76
float
readXAngularVelocity();
77
float
readYAngularVelocity();
78
float
readZAngularVelocity();
79
float
readTemperature();
80
void
filterImu
();
81
float
getRoll
();
82
float
getPitch
();
83
};
84
85
#endif
MPU6050::readZAcceleration
float readZAcceleration()
Definition
mpu.cpp:119
MPU6050::readXAcceleration
float readXAcceleration()
Definition
mpu.cpp:67
MPU6050::getPitch
float getPitch()
Definition
mpu.cpp:163
MPU6050::readYAcceleration
float readYAcceleration()
Definition
mpu.cpp:93
MPU6050::getRoll
float getRoll()
Definition
mpu.cpp:147
MPU6050::filterImu
void filterImu()
Definition
mpu.cpp:251
defs.h
necessary miscellaneous defines for various tasks and functions
n4-flight-software
src
mpu.h
Generated by
1.17.0