-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resolved issues with the gyroscope code
- Loading branch information
1 parent
15ed6a9
commit 2cdf0ec
Showing
3 changed files
with
59 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,27 @@ | ||
use mpu6050::Mpu6050; | ||
use rppal::i2c::I2c; | ||
|
||
pub struct Mpu6050Sensor { | ||
mpu6050: Mpu6050<I2c>, | ||
pub struct Gyroscope { | ||
mpu6050: Mpu6050<I2c>, | ||
} | ||
|
||
impl Mpu6050Sensor { | ||
pub fn new() -> Self { | ||
let i2c = I2c::new().unwrap(); | ||
let mpu6050 = Mpu6050::new(i2c); | ||
Mpu6050Sensor { mpu6050 } | ||
} | ||
pub struct Orientation { | ||
pub pitch: f32, | ||
pub roll: f32, | ||
} | ||
|
||
impl Gyroscope { | ||
pub fn new() -> Self { | ||
let i2c = I2c::new().unwrap(); | ||
let mpu6050 = Mpu6050::new(i2c); | ||
Gyroscope { mpu6050 } | ||
} | ||
|
||
pub fn read_accel_gyro(&mut self) -> (f32, f32) { | ||
let acc = self.mpu6050.get_acc_angles().unwrap(); | ||
(acc[0], acc[1]) | ||
} | ||
pub fn read_orientation(&mut self) -> Orientation { | ||
let acc = self.mpu6050.get_acc_angles().unwrap(); | ||
Orientation { | ||
pitch: acc[0], | ||
roll: acc[1], | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters