comments
This commit is contained in:
parent
865faae9c5
commit
5afe9dfbc1
2 changed files with 17 additions and 21 deletions
|
@ -1,4 +1,8 @@
|
|||
//! All constants used in the driver, mostly register addresses
|
||||
|
||||
/// Slave address of Mpu6050
|
||||
pub const SLAVE_ADDR: u8 = 0x68;
|
||||
/// Internal register to check slave addr
|
||||
pub const WHOAMI: u8 = 0x75;
|
||||
|
||||
/// 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
|
||||
pub const AFS_SEL: (f32, f32, f32, f32) = (16384., 8192., 4096., 2048.);
|
||||
|
||||
pub const PI: f32 = 3.14159;
|
||||
|
||||
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;
|
||||
|
||||
/// Accelerometer config register
|
||||
pub const ACCEL_CONFIG: u8 = 0x1c;
|
||||
|
||||
/// gyro config register
|
||||
pub const GYRO_CONFIG: u8 = 0x1b;
|
||||
|
||||
/// pi
|
||||
pub const PI: f32 = 3.14159;
|
||||
|
|
14
src/lib.rs
14
src/lib.rs
|
@ -1,11 +1,11 @@
|
|||
#![no_std]
|
||||
|
||||
pub mod constants;
|
||||
|
||||
///! Mpu6050 sensor driver.
|
||||
///! 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
|
||||
|
||||
pub mod constants;
|
||||
|
||||
use crate::constants::*;
|
||||
use libm::{powf, atan2f, sqrtf};
|
||||
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);
|
||||
|
||||
/// 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 {
|
||||
fn from(range: AccelRange) -> Sensitivity {
|
||||
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 {
|
||||
fn from(range: GyroRange) -> Sensitivity {
|
||||
match range {
|
||||
|
@ -72,7 +72,7 @@ impl From<GyroRange> for Sensitivity {
|
|||
}
|
||||
}
|
||||
|
||||
/// defines accelerometer range/sensivity
|
||||
/// Defines accelerometer range/sensivity
|
||||
pub enum AccelRange {
|
||||
G2,
|
||||
G4,
|
||||
|
@ -80,7 +80,7 @@ pub enum AccelRange {
|
|||
G16,
|
||||
}
|
||||
|
||||
/// defines gyro range/sensitivity
|
||||
/// Defines gyro range/sensitivity
|
||||
pub enum GyroRange {
|
||||
DEG250,
|
||||
DEG500,
|
||||
|
|
Loading…
Reference in a new issue