1
Fork 0
This commit is contained in:
Julian Gaal 2019-04-16 00:58:12 +02:00
parent 865faae9c5
commit 5afe9dfbc1
2 changed files with 17 additions and 21 deletions

View file

@ -1,4 +1,8 @@
//! All constants used in the driver, mostly register addresses
/// Slave address of Mpu6050
pub const SLAVE_ADDR: u8 = 0x68; pub const SLAVE_ADDR: u8 = 0x68;
/// Internal register to check slave addr
pub const WHOAMI: u8 = 0x75; pub const WHOAMI: u8 = 0x75;
/// High Bytle Register Gyro x orientation /// High Bytle Register Gyro x orientation
@ -28,19 +32,11 @@ pub const FS_SEL: (f32, f32, f32, f32) = (131., 65.5, 32.8, 16.4);
/// Calcelerometer Sensitivity /// Calcelerometer Sensitivity
pub const AFS_SEL: (f32, f32, f32, f32) = (16384., 8192., 4096., 2048.); pub const AFS_SEL: (f32, f32, f32, f32) = (16384., 8192., 4096., 2048.);
pub const PI: f32 = 3.14159; /// Accelerometer config register
pub const GRAVITIY_MS2: f32 = 9.80665;
pub const ACCEL_RANGE_2G: u8 = 0x00;
pub const ACCEL_RANGE_4G: u8 = 0x08;
pub const ACCEL_RANGE_8G: u8 = 0x10;
pub const ACCEL_RANGE_16G: u8 = 0x18;
pub const GYRO_RANGE_250DEG: u8 = 0x00;
pub const GYRO_RANGE_500DEG: u8 = 0x08;
pub const GYRO_RANGE_1000DEG: u8 = 0x10;
pub const GYRO_RANGE_2000DEG: u8 = 0x18;
pub const ACCEL_CONFIG: u8 = 0x1c; pub const ACCEL_CONFIG: u8 = 0x1c;
/// gyro config register
pub const GYRO_CONFIG: u8 = 0x1b; pub const GYRO_CONFIG: u8 = 0x1b;
/// pi
pub const PI: f32 = 3.14159;

View file

@ -1,11 +1,11 @@
#![no_std] #![no_std]
pub mod constants;
///! Mpu6050 sensor driver. ///! Mpu6050 sensor driver.
///! Register sheet: https://www.invensense.com/wp-content/uploads/2015/02/MPU-6000-Register-Map1.pdf ///! Register sheet: https://www.invensense.com/wp-content/uploads/2015/02/MPU-6000-Register-Map1.pdf
///! Data sheet: https://www.invensense.com/wp-content/uploads/2015/02/MPU-6500-Datasheet2.pdf ///! Data sheet: https://www.invensense.com/wp-content/uploads/2015/02/MPU-6500-Datasheet2.pdf
pub mod constants;
use crate::constants::*; use crate::constants::*;
use libm::{powf, atan2f, sqrtf}; use libm::{powf, atan2f, sqrtf};
use embedded_hal::{ use embedded_hal::{
@ -45,10 +45,10 @@ impl Bias {
} }
} }
/// Helper struct to convert Sensor measurement range to appropriate values defined in datasheet // Helper struct to convert Sensor measurement range to appropriate values defined in datasheet
struct Sensitivity(f32); struct Sensitivity(f32);
/// Converts accelerometer range to correction/scaling factor, see table p. 29 or register sheet // Converts accelerometer range to correction/scaling factor, see table p. 29 or register sheet
impl From<AccelRange> for Sensitivity { impl From<AccelRange> for Sensitivity {
fn from(range: AccelRange) -> Sensitivity { fn from(range: AccelRange) -> Sensitivity {
match range { match range {
@ -60,7 +60,7 @@ impl From<AccelRange> for Sensitivity {
} }
} }
/// Converts gyro range to correction/scaling factor, see table p. 31 or register sheet // Converts gyro range to correction/scaling factor, see table p. 31 or register sheet
impl From<GyroRange> for Sensitivity { impl From<GyroRange> for Sensitivity {
fn from(range: GyroRange) -> Sensitivity { fn from(range: GyroRange) -> Sensitivity {
match range { match range {
@ -72,7 +72,7 @@ impl From<GyroRange> for Sensitivity {
} }
} }
/// defines accelerometer range/sensivity /// Defines accelerometer range/sensivity
pub enum AccelRange { pub enum AccelRange {
G2, G2,
G4, G4,
@ -80,7 +80,7 @@ pub enum AccelRange {
G16, G16,
} }
/// defines gyro range/sensitivity /// Defines gyro range/sensitivity
pub enum GyroRange { pub enum GyroRange {
DEG250, DEG250,
DEG500, DEG500,