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

Commit

Permalink
docs: document Motor::temperature
Browse files Browse the repository at this point in the history
  • Loading branch information
Tropix126 committed Mar 27, 2024
1 parent 3572720 commit 817158a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
11 changes: 7 additions & 4 deletions packages/vex-devices/src/smart/imu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ impl core::future::Future for InertialCalibrateFuture {
cx.waker().wake_by_ref();
Poll::Pending
}
},
}
Self::Waiting(port, timestamp, phase) => {
if timestamp.elapsed() > InertialSensor::CALIBRATION_TIMEOUT {
// Calibration took too long and exceeded timeout.
Expand All @@ -379,19 +379,22 @@ impl core::future::Future for InertialCalibrateFuture {
},
);

if status.contains(InertialStatus::CALIBRATING) && phase == CalibrationPhase::Start {
if status.contains(InertialStatus::CALIBRATING) && phase == CalibrationPhase::Start
{
// Calibration has started, so we'll change to waiting for it to end.
*self = Self::Waiting(port, timestamp, CalibrationPhase::End);
cx.waker().wake_by_ref();
return Poll::Pending;
} else if !status.contains(InertialStatus::CALIBRATING) && phase == CalibrationPhase::End {
} else if !status.contains(InertialStatus::CALIBRATING)
&& phase == CalibrationPhase::End
{
// Calibration has finished.
return Poll::Ready(Ok(()));
}

cx.waker().wake_by_ref();
Poll::Pending
},
}
}
}
}
Expand Down
20 changes: 15 additions & 5 deletions packages/vex-devices/src/smart/motor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,19 @@ use bitflags::bitflags;
use pros_core::error::PortError;
use snafu::Snafu;
use vex_sdk::{
vexDeviceMotorAbsoluteTargetSet, vexDeviceMotorBrakeModeSet, vexDeviceMotorCurrentGet, vexDeviceMotorCurrentLimitGet, vexDeviceMotorCurrentLimitSet, vexDeviceMotorEfficiencyGet, vexDeviceMotorEncoderUnitsSet, vexDeviceMotorFaultsGet, vexDeviceMotorFlagsGet, vexDeviceMotorGearingGet, vexDeviceMotorGearingSet, vexDeviceMotorPositionGet, vexDeviceMotorPositionRawGet, vexDeviceMotorPositionReset, vexDeviceMotorPositionSet, vexDeviceMotorPowerGet, vexDeviceMotorReverseFlagGet, vexDeviceMotorReverseFlagSet, vexDeviceMotorTemperatureGet, vexDeviceMotorTorqueGet, vexDeviceMotorVelocityGet, vexDeviceMotorVelocitySet, vexDeviceMotorVelocityUpdate, vexDeviceMotorVoltageGet, vexDeviceMotorVoltageLimitGet, vexDeviceMotorVoltageLimitSet, vexDeviceMotorVoltageSet, V5MotorBrakeMode, V5MotorGearset
vexDeviceMotorAbsoluteTargetSet, vexDeviceMotorBrakeModeSet, vexDeviceMotorCurrentGet,
vexDeviceMotorCurrentLimitGet, vexDeviceMotorCurrentLimitSet, vexDeviceMotorEfficiencyGet,
vexDeviceMotorEncoderUnitsSet, vexDeviceMotorFaultsGet, vexDeviceMotorFlagsGet,
vexDeviceMotorGearingGet, vexDeviceMotorGearingSet, vexDeviceMotorPositionGet,
vexDeviceMotorPositionRawGet, vexDeviceMotorPositionReset, vexDeviceMotorPositionSet,
vexDeviceMotorPowerGet, vexDeviceMotorReverseFlagGet, vexDeviceMotorReverseFlagSet,
vexDeviceMotorTemperatureGet, vexDeviceMotorTorqueGet, vexDeviceMotorVelocityGet,
vexDeviceMotorVelocitySet, vexDeviceMotorVelocityUpdate, vexDeviceMotorVoltageGet,
vexDeviceMotorVoltageLimitGet, vexDeviceMotorVoltageLimitSet, vexDeviceMotorVoltageSet,
V5MotorBrakeMode, V5MotorGearset,
};

#[cfg(feature = "dangerous_motor_tuning")]
use vex_sdk::{
vexDeviceMotorPositionPidSet, vexDeviceMotorVelocityPidSet, V5_DeviceMotorPid
};
use vex_sdk::{vexDeviceMotorPositionPidSet, vexDeviceMotorVelocityPidSet, V5_DeviceMotorPid};

use super::{SmartDevice, SmartDeviceInternal, SmartDeviceTimestamp, SmartDeviceType, SmartPort};
use crate::Position;
Expand Down Expand Up @@ -112,6 +118,7 @@ impl Motor {
match target {
MotorControl::Brake(mode) => unsafe {
vexDeviceMotorBrakeModeSet(self.device_handle(), mode.into());
// Force motor into braking by putting it into velocity control with a 0rpm setpoint.
vexDeviceMotorVelocitySet(self.device_handle(), 0);
},
MotorControl::Velocity(rpm) => unsafe {
Expand Down Expand Up @@ -323,6 +330,7 @@ impl Motor {
Ok(unsafe { vexDeviceMotorVoltageLimitGet(self.device_handle()) } as f64 / 1000.0)
}

/// Returns the internal teperature recorded by the motor in increments of 5°C.
pub fn temperature(&self) -> Result<f64, MotorError> {
self.validate_port()?;
Ok(unsafe { vexDeviceMotorTemperatureGet(self.device_handle()) })
Expand All @@ -334,6 +342,8 @@ impl Motor {

let bits = unsafe { vexDeviceMotorFlagsGet(self.device_handle()) };

// This is technically just a flag, but it indicates that an error occurred when trying
// to get the flags, so we return early here.
if (bits & pros_sys::E_MOTOR_FLAGS_BUSY) != 0 {
return Err(MotorError::Busy);
}
Expand Down

0 comments on commit 817158a

Please sign in to comment.