From 01d0e12603bd2617ce0efaadd5a247be9cd8ca2d Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Sat, 10 Apr 2021 10:27:44 -0700 Subject: [PATCH] [wpilib] Revert move of RomiGyro into main wpilibc/j (#3296) This reverts commit 69e8d0b65d53a7b78d4cc4e4078fbcc4add5d723 (#3143). We haven't released a version with this yet, and plan to make a vendor library instead. --- .../main/native/include/frc/romi/RomiGyro.h | 101 ------------------ .../RomiReference/cpp/sensors}/RomiGyro.cpp | 24 ++--- .../RomiReference/include/sensors/RomiGyro.h | 60 +++++++++++ .../include/subsystems/Drivetrain.h | 5 +- .../romireference/sensors}/RomiGyro.java | 47 ++------ .../romireference/subsystems/Drivetrain.java | 2 +- 6 files changed, 82 insertions(+), 157 deletions(-) delete mode 100644 wpilibc/src/main/native/include/frc/romi/RomiGyro.h rename {wpilibc/src/main/native/cpp/romi => wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/sensors}/RomiGyro.cpp (79%) create mode 100644 wpilibcExamples/src/main/cpp/examples/RomiReference/include/sensors/RomiGyro.h rename {wpilibj/src/main/java/edu/wpi/first/wpilibj/romi => wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/romireference/sensors}/RomiGyro.java (69%) diff --git a/wpilibc/src/main/native/include/frc/romi/RomiGyro.h b/wpilibc/src/main/native/include/frc/romi/RomiGyro.h deleted file mode 100644 index 391e26b700..0000000000 --- a/wpilibc/src/main/native/include/frc/romi/RomiGyro.h +++ /dev/null @@ -1,101 +0,0 @@ -// Copyright (c) FIRST and other WPILib contributors. -// Open Source Software; you can modify and/or share it under the terms of -// the WPILib BSD license file in the root directory of this project. - -#pragma once - -#include - -#include "frc/GyroBase.h" - -namespace frc { - -/** - * Use a rate gyro to return the robots heading relative to a starting position. - * - * This class is for the Romi onboard gyro, and will only work in - * simulation/Romi mode. Only one instance of a RomiGyro is supported. - */ -class RomiGyro : public GyroBase { - public: - RomiGyro(); - - /** - * Return the actual angle in degrees that the robot is currently facing. - * - * The angle is based on integration of the returned rate form the gyro. - * The angle is continuous, that is, it will continue from 360->361 degrees. - * This allows algorithms that wouldn't want to see a discontinuity in the - * gyro output as it sweeps from 360 to 0 on the second time around. - * - * @return the current heading of the robot in degrees. - */ - double GetAngle() const override; - - /** - * Return the rate of rotation of the gyro - * - * The rate is based on the most recent reading of the gyro. - * - * @return the current rate in degrees per second - */ - double GetRate() const override; - - /** - * Initialize the gyro. - * - * NOTE: This function is a no-op. The Romi gyro should be calibrated via - * the web UI. - */ - void Calibrate() final {} - - /** - * Gets the rate of turn in degrees-per-second around the X-axis - */ - double GetRateX() const; - - /** - * Gets the rate of turn in degrees-per-second around the Y-axis - */ - double GetRateY() const; - - /** - * Gets the rate of turn in degrees-per-second around the Z-axis - */ - double GetRateZ() const; - - /** - * Gets the currently reported angle around the X-axis - */ - double GetAngleX() const; - - /** - * Gets the currently reported angle around the X-axis - */ - double GetAngleY() const; - - /** - * Gets the currently reported angle around the X-axis - */ - double GetAngleZ() const; - - /** - * Resets the gyro - */ - void Reset() override; - - private: - hal::SimDevice m_simDevice; - hal::SimDouble m_simRateX; - hal::SimDouble m_simRateY; - hal::SimDouble m_simRateZ; - hal::SimDouble m_simAngleX; - hal::SimDouble m_simAngleY; - hal::SimDouble m_simAngleZ; - - double m_angleXOffset = 0; - double m_angleYOffset = 0; - double m_angleZOffset = 0; -}; - -} // namespace frc diff --git a/wpilibc/src/main/native/cpp/romi/RomiGyro.cpp b/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/sensors/RomiGyro.cpp similarity index 79% rename from wpilibc/src/main/native/cpp/romi/RomiGyro.cpp rename to wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/sensors/RomiGyro.cpp index 50260f9d37..08a537bca3 100644 --- a/wpilibc/src/main/native/cpp/romi/RomiGyro.cpp +++ b/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/sensors/RomiGyro.cpp @@ -2,9 +2,7 @@ // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. -#include "frc/romi/RomiGyro.h" - -using namespace frc; +#include "sensors/RomiGyro.h" RomiGyro::RomiGyro() : m_simDevice("Gyro:RomiGyro") { if (m_simDevice) { @@ -24,15 +22,7 @@ RomiGyro::RomiGyro() : m_simDevice("Gyro:RomiGyro") { } } -double RomiGyro::GetAngle() const { - return GetAngleZ(); -} - -double RomiGyro::GetRate() const { - return GetRateZ(); -} - -double RomiGyro::GetRateX() const { +double RomiGyro::GetRateX() { if (m_simRateX) { return m_simRateX.Get(); } @@ -40,7 +30,7 @@ double RomiGyro::GetRateX() const { return 0.0; } -double RomiGyro::GetRateY() const { +double RomiGyro::GetRateY() { if (m_simRateY) { return m_simRateY.Get(); } @@ -48,7 +38,7 @@ double RomiGyro::GetRateY() const { return 0.0; } -double RomiGyro::GetRateZ() const { +double RomiGyro::GetRateZ() { if (m_simRateZ) { return m_simRateZ.Get(); } @@ -56,7 +46,7 @@ double RomiGyro::GetRateZ() const { return 0.0; } -double RomiGyro::GetAngleX() const { +double RomiGyro::GetAngleX() { if (m_simAngleX) { return m_simAngleX.Get() - m_angleXOffset; } @@ -64,7 +54,7 @@ double RomiGyro::GetAngleX() const { return 0.0; } -double RomiGyro::GetAngleY() const { +double RomiGyro::GetAngleY() { if (m_simAngleY) { return m_simAngleY.Get() - m_angleYOffset; } @@ -72,7 +62,7 @@ double RomiGyro::GetAngleY() const { return 0.0; } -double RomiGyro::GetAngleZ() const { +double RomiGyro::GetAngleZ() { if (m_simAngleZ) { return m_simAngleZ.Get() - m_angleZOffset; } diff --git a/wpilibcExamples/src/main/cpp/examples/RomiReference/include/sensors/RomiGyro.h b/wpilibcExamples/src/main/cpp/examples/RomiReference/include/sensors/RomiGyro.h new file mode 100644 index 0000000000..0e93d488ed --- /dev/null +++ b/wpilibcExamples/src/main/cpp/examples/RomiReference/include/sensors/RomiGyro.h @@ -0,0 +1,60 @@ +// Copyright (c) FIRST and other WPILib contributors. +// Open Source Software; you can modify and/or share it under the terms of +// the WPILib BSD license file in the root directory of this project. + +#pragma once + +#include + +class RomiGyro { + public: + RomiGyro(); + + /** + * Gets the rate of turn in degrees-per-second around the X-axis + */ + double GetRateX(); + + /** + * Gets the rate of turn in degrees-per-second around the Y-axis + */ + double GetRateY(); + + /** + * Gets the rate of turn in degrees-per-second around the Z-axis + */ + double GetRateZ(); + + /** + * Gets the currently reported angle around the X-axis + */ + double GetAngleX(); + + /** + * Gets the currently reported angle around the X-axis + */ + double GetAngleY(); + + /** + * Gets the currently reported angle around the X-axis + */ + double GetAngleZ(); + + /** + * Resets the gyro + */ + void Reset(); + + private: + hal::SimDevice m_simDevice; + hal::SimDouble m_simRateX; + hal::SimDouble m_simRateY; + hal::SimDouble m_simRateZ; + hal::SimDouble m_simAngleX; + hal::SimDouble m_simAngleY; + hal::SimDouble m_simAngleZ; + + double m_angleXOffset = 0; + double m_angleYOffset = 0; + double m_angleZOffset = 0; +}; diff --git a/wpilibcExamples/src/main/cpp/examples/RomiReference/include/subsystems/Drivetrain.h b/wpilibcExamples/src/main/cpp/examples/RomiReference/include/subsystems/Drivetrain.h index 0f96ff4f4d..7bedcdee4b 100644 --- a/wpilibcExamples/src/main/cpp/examples/RomiReference/include/subsystems/Drivetrain.h +++ b/wpilibcExamples/src/main/cpp/examples/RomiReference/include/subsystems/Drivetrain.h @@ -8,10 +8,11 @@ #include #include #include -#include #include #include +#include "sensors/RomiGyro.h" + class Drivetrain : public frc2::SubsystemBase { public: static constexpr double kCountsPerRevolution = 1440.0; @@ -116,6 +117,6 @@ class Drivetrain : public frc2::SubsystemBase { frc::DifferentialDrive m_drive{m_leftMotor, m_rightMotor}; - frc::RomiGyro m_gyro; + RomiGyro m_gyro; frc::BuiltInAccelerometer m_accelerometer; }; diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/romi/RomiGyro.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/romireference/sensors/RomiGyro.java similarity index 69% rename from wpilibj/src/main/java/edu/wpi/first/wpilibj/romi/RomiGyro.java rename to wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/romireference/sensors/RomiGyro.java index ea61795c4e..c21f62317e 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/romi/RomiGyro.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/romireference/sensors/RomiGyro.java @@ -2,15 +2,13 @@ // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. -package edu.wpi.first.wpilibj.romi; +package edu.wpi.first.wpilibj.examples.romireference.sensors; import edu.wpi.first.hal.SimDevice; import edu.wpi.first.hal.SimDevice.Direction; import edu.wpi.first.hal.SimDouble; -import edu.wpi.first.wpilibj.GyroBase; -public class RomiGyro extends GyroBase { - private final SimDevice m_simDevice; +public class RomiGyro { private SimDouble m_simRateX; private SimDouble m_simRateY; private SimDouble m_simRateZ; @@ -24,16 +22,16 @@ public class RomiGyro extends GyroBase { /** Create a new RomiGyro. */ public RomiGyro() { - m_simDevice = SimDevice.create("Gyro:RomiGyro"); - if (m_simDevice != null) { - m_simDevice.createBoolean("init", Direction.kOutput, true); - m_simRateX = m_simDevice.createDouble("rate_x", Direction.kInput, 0.0); - m_simRateY = m_simDevice.createDouble("rate_y", Direction.kInput, 0.0); - m_simRateZ = m_simDevice.createDouble("rate_z", Direction.kInput, 0.0); + SimDevice gyroSimDevice = SimDevice.create("Gyro:RomiGyro"); + if (gyroSimDevice != null) { + gyroSimDevice.createBoolean("init", Direction.kOutput, true); + m_simRateX = gyroSimDevice.createDouble("rate_x", Direction.kInput, 0.0); + m_simRateY = gyroSimDevice.createDouble("rate_y", Direction.kInput, 0.0); + m_simRateZ = gyroSimDevice.createDouble("rate_z", Direction.kInput, 0.0); - m_simAngleX = m_simDevice.createDouble("angle_x", Direction.kInput, 0.0); - m_simAngleY = m_simDevice.createDouble("angle_y", Direction.kInput, 0.0); - m_simAngleZ = m_simDevice.createDouble("angle_z", Direction.kInput, 0.0); + m_simAngleX = gyroSimDevice.createDouble("angle_x", Direction.kInput, 0.0); + m_simAngleY = gyroSimDevice.createDouble("angle_y", Direction.kInput, 0.0); + m_simAngleZ = gyroSimDevice.createDouble("angle_z", Direction.kInput, 0.0); } } @@ -116,7 +114,6 @@ public class RomiGyro extends GyroBase { } /** Reset the gyro angles to 0. */ - @Override public void reset() { if (m_simAngleX != null) { m_angleXOffset = m_simAngleX.get(); @@ -124,26 +121,4 @@ public class RomiGyro extends GyroBase { m_angleZOffset = m_simAngleZ.get(); } } - - @Override - public void calibrate() { - // no-op - Romi Gyro calibration is done via web UI - } - - @Override - public double getAngle() { - return getAngleZ(); - } - - @Override - public double getRate() { - return getRateZ(); - } - - @Override - public void close() throws Exception { - if (m_simDevice != null) { - m_simDevice.close(); - } - } } diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/romireference/subsystems/Drivetrain.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/romireference/subsystems/Drivetrain.java index eb3ca22a1e..40d2d2feb1 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/romireference/subsystems/Drivetrain.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/romireference/subsystems/Drivetrain.java @@ -8,7 +8,7 @@ import edu.wpi.first.wpilibj.BuiltInAccelerometer; import edu.wpi.first.wpilibj.Encoder; import edu.wpi.first.wpilibj.Spark; import edu.wpi.first.wpilibj.drive.DifferentialDrive; -import edu.wpi.first.wpilibj.romi.RomiGyro; +import edu.wpi.first.wpilibj.examples.romireference.sensors.RomiGyro; import edu.wpi.first.wpilibj2.command.SubsystemBase; public class Drivetrain extends SubsystemBase {