diff --git a/packages/pros-devices/src/smart/distance.rs b/packages/pros-devices/src/smart/distance.rs index 607991ca..53fa0849 100644 --- a/packages/pros-devices/src/smart/distance.rs +++ b/packages/pros-devices/src/smart/distance.rs @@ -29,33 +29,40 @@ impl DistanceSensor { }) as u32) } - /// returns the velocity of the object the sensor detects in m/s - pub fn object_velocity(&self) -> Result { - // all VEX Distance Sensor functions return PROS_ERR on failure even though + /// Returns the velocity of the object the sensor detects in m/s + pub fn velocity(&self) -> Result { + // All VEX Distance Sensor functions return PROS_ERR on failure even though // some return floating point values (not PROS_ERR_F) Ok(bail_on!(PROS_ERR as c_double, unsafe { pros_sys::distance_get_object_velocity(self.port.index()) })) } - /// Get the current guess at relative object size. + /// Get the current guess at relative "object size". /// - /// This is a value that has a range of 0 to 400. - /// A 18" x 30" grey card will return a value of approximately 75 - /// in typical room lighting. - pub fn object_size(&self) -> Result { + /// This is a value that has a range of 0 to 400. A 18" x 30" grey card will return + /// a value of approximately 75 in typical room lighting. + /// + /// This sensor reading is unusual, as it is entirely unitless with the seemingly arbitrary + /// range of 0-400 existing due to VEXCode's [`vex::sizeType`] enum having four variants. It's + /// unknown what the sensor is *actually* measuring here either, so use this data with a grain + /// of salt. + /// + /// [`vex::sizeType`]: https://api.vexcode.cloud/v5/search/sizeType/sizeType/enum + pub fn relative_size(&self) -> Result { Ok(bail_on!(PROS_ERR, unsafe { pros_sys::distance_get_object_size(self.port.index()) }) as u32) } - /// Returns the confidence in the distance measurement from 0% to 100%. - pub fn distance_confidence(&self) -> Result { + /// Returns the confidence in the distance measurement from 0.0 to 1.0. + pub fn distance_confidence(&self) -> Result { // 0 -> 63 let confidence = bail_on!(PROS_ERR, unsafe { pros_sys::distance_get_confidence(self.port.index()) - }) as f32; - Ok(confidence * 100.0 / 63.0) + }) as f64; + + Ok(confidence / 63.0) } }