From d181e353a0a2c567ebd08be0590ad0c6d6106874 Mon Sep 17 00:00:00 2001 From: Isaac Turner Date: Sat, 13 Jan 2024 03:00:42 +0800 Subject: [PATCH] [wpilib] ADIS16470: Add no-param GetAngle and GetRate (#6184) This helps with backwards compatibility. --- .../main/native/include/frc/ADIS16470_IMU.h | 10 ++-- .../edu/wpi/first/wpilibj/ADIS16470_IMU.java | 54 +++++++++++++++++++ 2 files changed, 60 insertions(+), 4 deletions(-) diff --git a/wpilibc/src/main/native/include/frc/ADIS16470_IMU.h b/wpilibc/src/main/native/include/frc/ADIS16470_IMU.h index af3a2d64d0..c5ee7e6a6c 100644 --- a/wpilibc/src/main/native/include/frc/ADIS16470_IMU.h +++ b/wpilibc/src/main/native/include/frc/ADIS16470_IMU.h @@ -215,18 +215,20 @@ class ADIS16470_IMU : public wpi::Sendable, /** * Returns the axis angle (CCW positive). * - * @param axis The IMUAxis whose angle to return. + * @param axis The IMUAxis whose angle to return. Defaults to user configured + * Yaw. * @return The axis angle (CCW positive). */ - units::degree_t GetAngle(IMUAxis axis) const; + units::degree_t GetAngle(IMUAxis axis = IMUAxis::kYaw) const; /** * Returns the axis angular rate (CCW positive). * - * @param axis The IMUAxis whose rate to return. + * @param axis The IMUAxis whose rate to return. Defaults to user configured + * Yaw. * @return Axis angular rate (CCW positive). */ - units::degrees_per_second_t GetRate(IMUAxis axis) const; + units::degrees_per_second_t GetRate(IMUAxis axis = IMUAxis::kYaw) const; /** * Returns the acceleration in the X axis. diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/ADIS16470_IMU.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/ADIS16470_IMU.java index b7236a57ee..67a5beca86 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/ADIS16470_IMU.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/ADIS16470_IMU.java @@ -1136,6 +1136,33 @@ public class ADIS16470_IMU implements AutoCloseable, Sendable { return 0.0; } + /** + * Returns the Yaw axis angle in degrees (CCW positive). + * + * @return The Yaw axis angle in degrees (CCW positive). + */ + public synchronized double getAngle() { + switch (m_yaw_axis) { + case kX: + if (m_simGyroAngleX != null) { + return m_simGyroAngleX.get(); + } + return m_integ_angle_x; + case kY: + if (m_simGyroAngleY != null) { + return m_simGyroAngleY.get(); + } + return m_integ_angle_y; + case kZ: + if (m_simGyroAngleZ != null) { + return m_simGyroAngleZ.get(); + } + return m_integ_angle_z; + default: + } + return 0.0; + } + /** * Returns the axis angular rate in degrees per second (CCW positive). * @@ -1177,6 +1204,33 @@ public class ADIS16470_IMU implements AutoCloseable, Sendable { return 0.0; } + /** + * Returns the Yaw axis angular rate in degrees per second (CCW positive). + * + * @return Yaw axis angular rate in degrees per second (CCW positive). + */ + public synchronized double getRate() { + switch (m_yaw_axis) { + case kX: + if (m_simGyroRateX != null) { + return m_simGyroRateX.get(); + } + return m_gyro_rate_x; + case kY: + if (m_simGyroRateY != null) { + return m_simGyroRateY.get(); + } + return m_gyro_rate_y; + case kZ: + if (m_simGyroRateZ != null) { + return m_simGyroRateZ.get(); + } + return m_gyro_rate_z; + default: + } + return 0.0; + } + /** * Returns which axis, kX, kY, or kZ, is set to the yaw axis. *