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

Commit

Permalink
refactor: raw_position timestamp outvalue
Browse files Browse the repository at this point in the history
  • Loading branch information
Tropix126 committed Mar 8, 2024
1 parent 127f7e2 commit 460c982
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions packages/pros-devices/src/smart/motor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use core::time::Duration;

use bitflags::bitflags;
use pros_core::{bail_on, error::PortError, map_errno};
use pros_core::{bail_on, error::PortError, map_errno, time::Instant};

Check warning on line 6 in packages/pros-devices/src/smart/motor.rs

View workflow job for this annotation

GitHub Actions / Check

unused import: `time::Instant`
use pros_sys::{PROS_ERR, PROS_ERR_F};
use snafu::Snafu;

Expand Down Expand Up @@ -249,14 +249,24 @@ impl Motor {
})))
}

/// Returns the raw position tick data recorded by the motor at a given timestamp.
pub fn raw_position(&self, timestamp: Duration) -> Result<i32, MotorError> {
Ok(bail_on!(PROS_ERR, unsafe {
/// Returns the most recently recorded raw encoder tick data from the motor's IME
/// along with a timestamp of the internal clock of the motor indicating when the
/// data was recorded.
pub fn raw_position(&self) -> Result<(i32, Duration), MotorError> {
let timestamp = 0 as *mut u32;

// PROS docs claim that this function gets the position *at* a recorded timestamp,
// but in reality the "timestamp" paramater is a mutable outvalue. The function
// outputs the most recent recorded posision AND the timestamp it was measured at,
// rather than a position at a requested timestamp.
let ticks = bail_on!(PROS_ERR, unsafe {
pros_sys::motor_get_raw_position(
self.port.index() as i8,
timestamp.as_millis() as *const u32,
timestamp,
)
}))
});

Ok((ticks, Duration::from_millis(unsafe { *timestamp } as u64)))
}

/// Returns the electrical current draw of the motor in amps.
Expand Down

0 comments on commit 460c982

Please sign in to comment.