Skip to content
This repository has been archived by the owner on Jun 19, 2024. It is now read-only.

Commit

Permalink
Merge pull request #16 from Tropix126/main
Browse files Browse the repository at this point in the history
feat(devices): V5 Inertial Sensor support
  • Loading branch information
Gavin-Niederman authored Jan 8, 2024
2 parents 4ce49e0 + e61a5e1 commit bb841bb
Show file tree
Hide file tree
Showing 6 changed files with 469 additions and 5 deletions.
2 changes: 1 addition & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ This is the todo list for the eventual 1.0.0 release of pros-rs
* [ ] Sensors
* [X] Distance
* [X] GPS
* [ ] Inertial (IMU)
* [x] Inertial (IMU)
* [ ] Optical
* [X] Rotational
* [X] Vision
Expand Down
8 changes: 4 additions & 4 deletions pros-sys/src/imu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ pub struct quaternion_s_t {

#[repr(C)]
pub struct imu_raw_s {
x: f64,
y: f64,
z: f64,
w: f64,
pub x: f64,
pub y: f64,
pub z: f64,
pub w: f64,
}

pub type imu_gyro_s_t = imu_raw_s;
Expand Down
29 changes: 29 additions & 0 deletions pros/examples/imu.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#![no_std]
#![no_main]

use core::time::Duration;
use pros::prelude::*;

#[derive(Default)]
pub struct Robot;

impl SyncRobot for Robot {
fn opcontrol(&mut self) -> pros::Result {
let imu = InertialSensor::new(1)?;

imu.calibrate()?;

loop {
let euler = imu.euler()?;

println!(
"Pitch: {} Roll: {} Yaw: {}",
euler.pitch, euler.roll, euler.yaw
);

pros::task::delay(Duration::from_secs(1));
}
}
}

sync_robot!(Robot);
1 change: 1 addition & 0 deletions pros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ pub mod prelude {
pub use crate::position::*;
pub use crate::sensors::distance::*;
pub use crate::sensors::gps::*;
pub use crate::sensors::imu::*;
pub use crate::sensors::rotation::*;
pub use crate::sensors::vision::*;
pub use crate::task::{sleep, spawn};
Expand Down
Loading

0 comments on commit bb841bb

Please sign in to comment.