diff --git a/wpilibcExamples/CMakeLists.txt b/wpilibcExamples/CMakeLists.txt index 1853876ee4..f46d1c246d 100644 --- a/wpilibcExamples/CMakeLists.txt +++ b/wpilibcExamples/CMakeLists.txt @@ -12,7 +12,7 @@ foreach(example ${EXAMPLES}) add_executable(${example} ${sources}) wpilib_target_warnings(${example}) target_include_directories(${example} PUBLIC src/main/cpp/examples/${example}/include) - target_link_libraries(${example} apriltag wpilibc wpilibNewCommands) + target_link_libraries(${example} apriltag wpilibc wpilibNewCommands romiVendordep xrpVendordep) if (WITH_TESTS AND EXISTS ${CMAKE_SOURCE_DIR}/wpilibcExamples/src/test/cpp/examples/${example}) wpilib_add_test(${example} src/test/cpp/examples/${example}/cpp) @@ -21,7 +21,7 @@ foreach(example ${EXAMPLES}) src/main/cpp/examples/${example}/include src/test/cpp/examples/${example}/include) target_compile_definitions(${example}_test PUBLIC RUNNING_FRC_TESTS) - target_link_libraries(${example}_test apriltag wpilibc wpilibNewCommands gmock_main) + target_link_libraries(${example}_test apriltag wpilibc wpilibNewCommands romiVendordep xrpVendordep gmock_main) endif() endforeach() @@ -31,5 +31,5 @@ foreach(template ${TEMPLATES}) add_executable(${template} ${sources}) wpilib_target_warnings(${template}) target_include_directories(${template} PUBLIC src/main/cpp/templates/${template}/include) - target_link_libraries(${template} wpilibc wpilibNewCommands) + target_link_libraries(${template} wpilibc wpilibNewCommands romiVendordep xrpVendordep) endforeach() diff --git a/wpilibcExamples/build.gradle b/wpilibcExamples/build.gradle index 2ca603866d..eb1aca5251 100644 --- a/wpilibcExamples/build.gradle +++ b/wpilibcExamples/build.gradle @@ -60,6 +60,8 @@ model { return } lib project: ':wpilibNewCommands', library: 'wpilibNewCommands', linkage: 'shared' + lib project: ':romiVendordep', library: 'romiVendordep', linkage: 'shared' + lib project: ':xrpVendordep', library: 'xrpVendordep', linkage: 'shared' lib project: ':apriltag', library: 'apriltag', linkage: 'shared' lib project: ':wpilibc', library: 'wpilibc', linkage: 'shared' lib project: ':wpimath', library: 'wpimath', linkage: 'shared' @@ -89,6 +91,8 @@ model { targetBuildTypes 'debug' binaries.all { binary -> lib project: ':wpilibNewCommands', library: 'wpilibNewCommands', linkage: 'shared' + lib project: ':romiVendordep', library: 'romiVendordep', linkage: 'shared' + lib project: ':xrpVendordep', library: 'xrpVendordep', linkage: 'shared' lib project: ':wpilibc', library: 'wpilibc', linkage: 'shared' lib project: ':apriltag', library: 'apriltag', linkage: 'shared' lib project: ':wpimath', library: 'wpimath', linkage: 'shared' @@ -138,6 +142,8 @@ model { targetBuildTypes 'debug' binaries.all { binary -> lib project: ':wpilibNewCommands', library: 'wpilibNewCommands', linkage: 'shared' + lib project: ':romiVendordep', library: 'romiVendordep', linkage: 'shared' + lib project: ':xrpVendordep', library: 'xrpVendordep', linkage: 'shared' lib project: ':wpilibc', library: 'wpilibc', linkage: 'shared' lib project: ':apriltag', library: 'apriltag', linkage: 'shared' lib project: ':wpimath', library: 'wpimath', linkage: 'shared' @@ -204,6 +210,8 @@ model { binaries { withType(GoogleTestTestSuiteBinarySpec) { lib project: ':wpilibNewCommands', library: 'wpilibNewCommands', linkage: 'shared' + lib project: ':romiVendordep', library: 'romiVendordep', linkage: 'shared' + lib project: ':xrpVendordep', library: 'xrpVendordep', linkage: 'shared' lib project: ':wpilibc', library: 'wpilibc', linkage: 'shared' lib project: ':apriltag', library: 'apriltag', linkage: 'shared' lib project: ':wpimath', library: 'wpimath', linkage: 'shared' diff --git a/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/sensors/RomiGyro.cpp b/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/sensors/RomiGyro.cpp deleted file mode 100644 index 08a537bca3..0000000000 --- a/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/sensors/RomiGyro.cpp +++ /dev/null @@ -1,79 +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. - -#include "sensors/RomiGyro.h" - -RomiGyro::RomiGyro() : m_simDevice("Gyro:RomiGyro") { - if (m_simDevice) { - m_simDevice.CreateBoolean("init", hal::SimDevice::kOutput, true); - m_simRateX = - m_simDevice.CreateDouble("rate_x", hal::SimDevice::kInput, 0.0); - m_simRateY = - m_simDevice.CreateDouble("rate_y", hal::SimDevice::kInput, 0.0); - m_simRateZ = - m_simDevice.CreateDouble("rate_z", hal::SimDevice::kInput, 0.0); - m_simAngleX = - m_simDevice.CreateDouble("angle_x", hal::SimDevice::kInput, 0.0); - m_simAngleY = - m_simDevice.CreateDouble("angle_y", hal::SimDevice::kInput, 0.0); - m_simAngleZ = - m_simDevice.CreateDouble("angle_z", hal::SimDevice::kInput, 0.0); - } -} - -double RomiGyro::GetRateX() { - if (m_simRateX) { - return m_simRateX.Get(); - } - - return 0.0; -} - -double RomiGyro::GetRateY() { - if (m_simRateY) { - return m_simRateY.Get(); - } - - return 0.0; -} - -double RomiGyro::GetRateZ() { - if (m_simRateZ) { - return m_simRateZ.Get(); - } - - return 0.0; -} - -double RomiGyro::GetAngleX() { - if (m_simAngleX) { - return m_simAngleX.Get() - m_angleXOffset; - } - - return 0.0; -} - -double RomiGyro::GetAngleY() { - if (m_simAngleY) { - return m_simAngleY.Get() - m_angleYOffset; - } - - return 0.0; -} - -double RomiGyro::GetAngleZ() { - if (m_simAngleZ) { - return m_simAngleZ.Get() - m_angleZOffset; - } - - return 0.0; -} - -void RomiGyro::Reset() { - if (m_simAngleX) { - m_angleXOffset = m_simAngleX.Get(); - m_angleYOffset = m_simAngleY.Get(); - m_angleZOffset = m_simAngleZ.Get(); - } -} diff --git a/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/subsystems/OnBoardIO.cpp b/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/subsystems/OnBoardIO.cpp deleted file mode 100644 index 1b76c74ec1..0000000000 --- a/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/subsystems/OnBoardIO.cpp +++ /dev/null @@ -1,81 +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. - -#include "subsystems/OnBoardIO.h" - -#include -#include -#include -#include - -OnBoardIO::OnBoardIO(OnBoardIO::ChannelMode dio1, OnBoardIO::ChannelMode dio2) { - if (dio1 == ChannelMode::INPUT) { - m_buttonB = std::make_unique(1); - } else { - m_greenLed = std::make_unique(1); - } - if (dio2 == ChannelMode::INPUT) { - m_buttonC = std::make_unique(2); - } else { - m_redLed = std::make_unique(2); - } -} - -bool OnBoardIO::GetButtonAPressed() { - return m_buttonA.Get(); -} - -bool OnBoardIO::GetButtonBPressed() { - if (m_buttonB) { - return m_buttonB->Get(); - } - - auto currentTime = frc::Timer::GetFPGATimestamp(); - if (currentTime > m_nextMessageTime) { - FRC_ReportError(frc::err::Error, "Button {} was not configured", "B"); - m_nextMessageTime = currentTime + kMessageInterval; - } - return false; -} - -bool OnBoardIO::GetButtonCPressed() { - if (m_buttonC) { - return m_buttonC->Get(); - } - - auto currentTime = frc::Timer::GetFPGATimestamp(); - if (currentTime > m_nextMessageTime) { - FRC_ReportError(frc::err::Error, "Button {} was not configured", "C"); - m_nextMessageTime = currentTime + kMessageInterval; - } - return false; -} - -void OnBoardIO::SetGreenLed(bool value) { - if (m_greenLed) { - m_greenLed->Set(value); - } else { - auto currentTime = frc::Timer::GetFPGATimestamp(); - if (currentTime > m_nextMessageTime) { - FRC_ReportError(frc::err::Error, "{} LED was not configured", "Green"); - m_nextMessageTime = currentTime + kMessageInterval; - } - } -} - -void OnBoardIO::SetRedLed(bool value) { - if (m_redLed) { - m_redLed->Set(value); - } else { - auto currentTime = frc::Timer::GetFPGATimestamp(); - if (currentTime > m_nextMessageTime) { - FRC_ReportError(frc::err::Error, "{} LED was not configured", "Red"); - m_nextMessageTime = currentTime + kMessageInterval; - } - } -} - -void OnBoardIO::SetYellowLed(bool value) { - m_yellowLed.Set(value); -} diff --git a/wpilibcExamples/src/main/cpp/examples/RomiReference/include/RobotContainer.h b/wpilibcExamples/src/main/cpp/examples/RomiReference/include/RobotContainer.h index 6f36537dfd..0a7761410b 100644 --- a/wpilibcExamples/src/main/cpp/examples/RomiReference/include/RobotContainer.h +++ b/wpilibcExamples/src/main/cpp/examples/RomiReference/include/RobotContainer.h @@ -5,6 +5,7 @@ #pragma once #include +#include #include #include #include @@ -14,7 +15,6 @@ #include "commands/AutonomousDistance.h" #include "commands/AutonomousTime.h" #include "subsystems/Drivetrain.h" -#include "subsystems/OnBoardIO.h" /** * This class is where the bulk of the robot should be declared. Since @@ -47,8 +47,8 @@ class RobotContainer { // The robot's subsystems Drivetrain m_drive; - OnBoardIO m_onboardIO{OnBoardIO::ChannelMode::INPUT, - OnBoardIO::ChannelMode::INPUT}; + frc::OnBoardIO m_onboardIO{frc::OnBoardIO::ChannelMode::INPUT, + frc::OnBoardIO::ChannelMode::INPUT}; // Example button frc2::Trigger m_onboardButtonA{ diff --git a/wpilibcExamples/src/main/cpp/examples/RomiReference/include/sensors/RomiGyro.h b/wpilibcExamples/src/main/cpp/examples/RomiReference/include/sensors/RomiGyro.h deleted file mode 100644 index 0e93d488ed..0000000000 --- a/wpilibcExamples/src/main/cpp/examples/RomiReference/include/sensors/RomiGyro.h +++ /dev/null @@ -1,60 +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 - -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 98ae9574b0..ace7d33bc7 100644 --- a/wpilibcExamples/src/main/cpp/examples/RomiReference/include/subsystems/Drivetrain.h +++ b/wpilibcExamples/src/main/cpp/examples/RomiReference/include/subsystems/Drivetrain.h @@ -8,11 +8,10 @@ #include #include #include +#include #include #include -#include "sensors/RomiGyro.h" - class Drivetrain : public frc2::SubsystemBase { public: static constexpr double kCountsPerRevolution = 1440.0; @@ -117,6 +116,6 @@ class Drivetrain : public frc2::SubsystemBase { frc::DifferentialDrive m_drive{m_leftMotor, m_rightMotor}; - RomiGyro m_gyro; + frc::RomiGyro m_gyro; frc::BuiltInAccelerometer m_accelerometer; }; diff --git a/wpilibcExamples/src/main/cpp/examples/RomiReference/include/subsystems/OnBoardIO.h b/wpilibcExamples/src/main/cpp/examples/RomiReference/include/subsystems/OnBoardIO.h deleted file mode 100644 index 0bb5225bc9..0000000000 --- a/wpilibcExamples/src/main/cpp/examples/RomiReference/include/subsystems/OnBoardIO.h +++ /dev/null @@ -1,72 +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 -#include -#include - -/** - * This class represents the onboard IO of the Romi - * reference robot. This includes the pushbuttons and - * LEDs. - * - *

DIO 0 - Button A (input only) - * DIO 1 - Button B (input) or Green LED (output) - * DIO 2 - Button C (input) or Red LED (output) - * DIO 3 - Yellow LED (output only) - */ -class OnBoardIO : public frc2::SubsystemBase { - public: - enum ChannelMode { INPUT, OUTPUT }; - OnBoardIO(OnBoardIO::ChannelMode dio1, OnBoardIO::ChannelMode dio2); - - static constexpr auto kMessageInterval = 1_s; - units::second_t m_nextMessageTime = 0_s; - - /** - * Gets if the A button is pressed. - */ - bool GetButtonAPressed(); - - /** - * Gets if the B button is pressed. - */ - bool GetButtonBPressed(); - - /** - * Gets if the C button is pressed. - */ - bool GetButtonCPressed(); - - /** - * Sets the green LED. - */ - void SetGreenLed(bool value); - - /** - * Sets the red LED. - */ - void SetRedLed(bool value); - - /** - * Sets the yellow LED. - */ - void SetYellowLed(bool value); - - private: - frc::DigitalInput m_buttonA{0}; - frc::DigitalOutput m_yellowLed{3}; - - // DIO 1 - std::unique_ptr m_buttonB; - std::unique_ptr m_greenLed; - - // DIO 2 - std::unique_ptr m_buttonC; - std::unique_ptr m_redLed; -}; diff --git a/wpilibcExamples/src/main/cpp/examples/examples.json b/wpilibcExamples/src/main/cpp/examples/examples.json index 2cc151958e..f6828692a2 100644 --- a/wpilibcExamples/src/main/cpp/examples/examples.json +++ b/wpilibcExamples/src/main/cpp/examples/examples.json @@ -686,7 +686,10 @@ ], "foldername": "RomiReference", "gradlebase": "cppromi", - "commandversion": 2 + "commandversion": 2, + "extravendordeps": [ + "romi" + ] }, { "name": "StateSpaceFlywheel", diff --git a/wpilibcExamples/src/main/cpp/templates/templates.json b/wpilibcExamples/src/main/cpp/templates/templates.json index 13e197b271..ae74993ace 100644 --- a/wpilibcExamples/src/main/cpp/templates/templates.json +++ b/wpilibcExamples/src/main/cpp/templates/templates.json @@ -82,7 +82,10 @@ ], "foldername": "commandbased", "gradlebase": "cppromi", - "commandversion": 2 + "commandversion": 2, + "extravendordeps": [ + "romi" + ] }, { "name": "Romi - Timed Robot", @@ -93,6 +96,9 @@ ], "foldername": "timed", "gradlebase": "cppromi", - "commandversion": 2 + "commandversion": 2, + "extravendordeps": [ + "romi" + ] } ] diff --git a/wpilibjExamples/build.gradle b/wpilibjExamples/build.gradle index d58923ca33..b850a50c54 100644 --- a/wpilibjExamples/build.gradle +++ b/wpilibjExamples/build.gradle @@ -22,6 +22,8 @@ dependencies { implementation project(':cscore') implementation project(':cameraserver') implementation project(':wpilibNewCommands') + implementation project(':romiVendordep') + implementation project(':xrpVendordep') testImplementation 'org.junit.jupiter:junit-jupiter-api:5.10.0' testImplementation 'org.junit.jupiter:junit-jupiter-params:5.10.0' @@ -94,6 +96,8 @@ model { } binaries.all { binary -> lib project: ':wpilibNewCommands', library: 'wpilibNewCommands', linkage: 'shared' + lib project: ':romiVendordep', library: 'romiVendordep', linkage: 'shared' + lib project: ':xrpVendordep', library: 'xrpVendordep', linkage: 'shared' lib project: ':apriltag', library: 'apriltag', linkage: 'shared' lib project: ':wpilibc', library: 'wpilibc', linkage: 'shared' lib project: ':wpimath', library: 'wpimath', linkage: 'shared' diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/examples.json b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/examples.json index 139b6130d7..99e20270f3 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/examples.json +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/examples.json @@ -891,7 +891,10 @@ "foldername": "romireference", "gradlebase": "javaromi", "mainclass": "Main", - "commandversion": 2 + "commandversion": 2, + "extravendordeps": [ + "romi" + ] }, { "name": "XRP Reference", @@ -906,7 +909,10 @@ "foldername": "xrpreference", "gradlebase": "javaxrp", "mainclass": "Main", - "commandversion": 2 + "commandversion": 2, + "extravendordeps": [ + "xrp" + ] }, { "name": "Digital Communication Sample", diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/romireference/RobotContainer.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/romireference/RobotContainer.java index 158255537d..39c1a36afd 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/romireference/RobotContainer.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/romireference/RobotContainer.java @@ -11,8 +11,8 @@ import edu.wpi.first.wpilibj.examples.romireference.commands.ArcadeDrive; import edu.wpi.first.wpilibj.examples.romireference.commands.AutonomousDistance; import edu.wpi.first.wpilibj.examples.romireference.commands.AutonomousTime; import edu.wpi.first.wpilibj.examples.romireference.subsystems.Drivetrain; -import edu.wpi.first.wpilibj.examples.romireference.subsystems.OnBoardIO; -import edu.wpi.first.wpilibj.examples.romireference.subsystems.OnBoardIO.ChannelMode; +import edu.wpi.first.wpilibj.romi.OnBoardIO; +import edu.wpi.first.wpilibj.romi.OnBoardIO.ChannelMode; import edu.wpi.first.wpilibj.smartdashboard.SendableChooser; import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; import edu.wpi.first.wpilibj2.command.Command; diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/romireference/sensors/RomiGyro.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/romireference/sensors/RomiGyro.java deleted file mode 100644 index a0ee53d542..0000000000 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/romireference/sensors/RomiGyro.java +++ /dev/null @@ -1,132 +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. - -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; - -public class RomiGyro { - private final SimDouble m_simRateX; - private final SimDouble m_simRateY; - private final SimDouble m_simRateZ; - private final SimDouble m_simAngleX; - private final SimDouble m_simAngleY; - private final SimDouble m_simAngleZ; - - private double m_angleXOffset; - private double m_angleYOffset; - private double m_angleZOffset; - - /** Create a new RomiGyro. */ - public RomiGyro() { - 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 = 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); - } else { - m_simRateX = null; - m_simRateY = null; - m_simRateZ = null; - - m_simAngleX = null; - m_simAngleY = null; - m_simAngleZ = null; - } - } - - /** - * Get the rate of turn in degrees-per-second around the X-axis. - * - * @return rate of turn in degrees-per-second - */ - public double getRateX() { - if (m_simRateX != null) { - return m_simRateX.get(); - } - - return 0.0; - } - - /** - * Get the rate of turn in degrees-per-second around the Y-axis. - * - * @return rate of turn in degrees-per-second - */ - public double getRateY() { - if (m_simRateY != null) { - return m_simRateY.get(); - } - - return 0.0; - } - - /** - * Get the rate of turn in degrees-per-second around the Z-axis. - * - * @return rate of turn in degrees-per-second - */ - public double getRateZ() { - if (m_simRateZ != null) { - return m_simRateZ.get(); - } - - return 0.0; - } - - /** - * Get the currently reported angle around the X-axis. - * - * @return current angle around X-axis in degrees - */ - public double getAngleX() { - if (m_simAngleX != null) { - return m_simAngleX.get() - m_angleXOffset; - } - - return 0.0; - } - - /** - * Get the currently reported angle around the X-axis. - * - * @return current angle around Y-axis in degrees - */ - public double getAngleY() { - if (m_simAngleY != null) { - return m_simAngleY.get() - m_angleYOffset; - } - - return 0.0; - } - - /** - * Get the currently reported angle around the Z-axis. - * - * @return current angle around Z-axis in degrees - */ - public double getAngleZ() { - if (m_simAngleZ != null) { - return m_simAngleZ.get() - m_angleZOffset; - } - - return 0.0; - } - - /** Reset the gyro angles to 0. */ - public void reset() { - if (m_simAngleX != null) { - m_angleXOffset = m_simAngleX.get(); - m_angleYOffset = m_simAngleY.get(); - m_angleZOffset = m_simAngleZ.get(); - } - } -} 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 a7c84320a6..d805590c06 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 @@ -7,8 +7,8 @@ package edu.wpi.first.wpilibj.examples.romireference.subsystems; import edu.wpi.first.wpilibj.BuiltInAccelerometer; import edu.wpi.first.wpilibj.Encoder; import edu.wpi.first.wpilibj.drive.DifferentialDrive; -import edu.wpi.first.wpilibj.examples.romireference.sensors.RomiGyro; import edu.wpi.first.wpilibj.motorcontrol.Spark; +import edu.wpi.first.wpilibj.romi.RomiGyro; import edu.wpi.first.wpilibj2.command.SubsystemBase; public class Drivetrain extends SubsystemBase { diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/romireference/subsystems/OnBoardIO.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/romireference/subsystems/OnBoardIO.java deleted file mode 100644 index 0199f6a8ba..0000000000 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/romireference/subsystems/OnBoardIO.java +++ /dev/null @@ -1,132 +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. - -package edu.wpi.first.wpilibj.examples.romireference.subsystems; - -import edu.wpi.first.wpilibj.DigitalInput; -import edu.wpi.first.wpilibj.DigitalOutput; -import edu.wpi.first.wpilibj.DriverStation; -import edu.wpi.first.wpilibj.Timer; -import edu.wpi.first.wpilibj2.command.SubsystemBase; - -/** - * This class represents the onboard IO of the Romi reference robot. This includes the pushbuttons - * and LEDs. - * - *

DIO 0 - Button A (input only) DIO 1 - Button B (input) or Green LED (output) DIO 2 - Button C - * (input) or Red LED (output) DIO 3 - Yellow LED (output only) - */ -public class OnBoardIO extends SubsystemBase { - private final DigitalInput m_buttonA = new DigitalInput(0); - private final DigitalOutput m_yellowLed = new DigitalOutput(3); - - // DIO 1 - private final DigitalInput m_buttonB; - private final DigitalOutput m_greenLed; - - // DIO 2 - private final DigitalInput m_buttonC; - private final DigitalOutput m_redLed; - - private static final double MESSAGE_INTERVAL = 1.0; - private double m_nextMessageTime; - - public enum ChannelMode { - INPUT, - OUTPUT - } - - /** - * Constructor. - * - * @param dio1 Mode for DIO 1 (input = Button B, output = green LED) - * @param dio2 Mode for DIO 2 (input = Button C, output = red LED) - */ - public OnBoardIO(ChannelMode dio1, ChannelMode dio2) { - if (dio1 == ChannelMode.INPUT) { - m_buttonB = new DigitalInput(1); - m_greenLed = null; - } else { - m_buttonB = null; - m_greenLed = new DigitalOutput(1); - } - - if (dio2 == ChannelMode.INPUT) { - m_buttonC = new DigitalInput(2); - m_redLed = null; - } else { - m_buttonC = null; - m_redLed = new DigitalOutput(2); - } - } - - /** Gets if the A button is pressed. */ - public boolean getButtonAPressed() { - return m_buttonA.get(); - } - - /** Gets if the B button is pressed. */ - public boolean getButtonBPressed() { - if (m_buttonB != null) { - return m_buttonB.get(); - } - - double currentTime = Timer.getFPGATimestamp(); - if (currentTime > m_nextMessageTime) { - DriverStation.reportError("Button B was not configured", true); - m_nextMessageTime = currentTime + MESSAGE_INTERVAL; - } - return false; - } - - /** Gets if the C button is pressed. */ - public boolean getButtonCPressed() { - if (m_buttonC != null) { - return m_buttonC.get(); - } - - double currentTime = Timer.getFPGATimestamp(); - if (currentTime > m_nextMessageTime) { - DriverStation.reportError("Button C was not configured", true); - m_nextMessageTime = currentTime + MESSAGE_INTERVAL; - } - return false; - } - - /** Sets the green LED. */ - public void setGreenLed(boolean value) { - if (m_greenLed != null) { - m_greenLed.set(value); - } else { - double currentTime = Timer.getFPGATimestamp(); - if (currentTime > m_nextMessageTime) { - DriverStation.reportError("Green LED was not configured", true); - m_nextMessageTime = currentTime + MESSAGE_INTERVAL; - } - } - } - - /** Sets the red LED. */ - public void setRedLed(boolean value) { - if (m_redLed != null) { - m_redLed.set(value); - } else { - double currentTime = Timer.getFPGATimestamp(); - if (currentTime > m_nextMessageTime) { - DriverStation.reportError("Red LED was not configured", true); - m_nextMessageTime = currentTime + MESSAGE_INTERVAL; - } - } - } - - /** Sets the yellow LED. */ - public void setYellowLed(boolean value) { - m_yellowLed.set(value); - } - - @Override - public void periodic() { - // This method will be called once per scheduler run - } -} diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/xrpreference/RobotContainer.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/xrpreference/RobotContainer.java index 593e5a77dc..8c2746bf59 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/xrpreference/RobotContainer.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/xrpreference/RobotContainer.java @@ -12,9 +12,9 @@ import edu.wpi.first.wpilibj.examples.xrpreference.commands.AutonomousDistance; import edu.wpi.first.wpilibj.examples.xrpreference.commands.AutonomousTime; import edu.wpi.first.wpilibj.examples.xrpreference.subsystems.Arm; import edu.wpi.first.wpilibj.examples.xrpreference.subsystems.Drivetrain; -import edu.wpi.first.wpilibj.examples.xrpreference.subsystems.XRPOnBoardIO; import edu.wpi.first.wpilibj.smartdashboard.SendableChooser; import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; +import edu.wpi.first.wpilibj.xrp.XRPOnBoardIO; import edu.wpi.first.wpilibj2.command.Command; import edu.wpi.first.wpilibj2.command.InstantCommand; import edu.wpi.first.wpilibj2.command.PrintCommand; diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/xrpreference/devices/XRPMotor.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/xrpreference/devices/XRPMotor.java deleted file mode 100644 index be84e6b5ea..0000000000 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/xrpreference/devices/XRPMotor.java +++ /dev/null @@ -1,109 +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. - -package edu.wpi.first.wpilibj.examples.xrpreference.devices; - -import edu.wpi.first.hal.SimBoolean; -import edu.wpi.first.hal.SimDevice; -import edu.wpi.first.hal.SimDevice.Direction; -import edu.wpi.first.hal.SimDouble; -import edu.wpi.first.wpilibj.motorcontrol.MotorController; -import java.util.HashMap; -import java.util.HashSet; - -/** - * XRPMotor. - * - *

A SimDevice based motor controller representing the motors on an XRP robot - */ -public class XRPMotor implements MotorController { - private static HashMap s_simDeviceNameMap = new HashMap<>(); - private static HashSet s_registeredDevices = new HashSet<>(); - - private static void checkDeviceAllocation(int deviceNum) { - if (!s_simDeviceNameMap.containsKey(deviceNum)) { - throw new IllegalArgumentException("Invalid XRPMotor device number. Should be 0-3"); - } - - if (s_registeredDevices.contains(deviceNum)) { - throw new IllegalArgumentException("XRPMotor " + deviceNum + " already allocated"); - } - - s_registeredDevices.add(deviceNum); - } - - static { - s_simDeviceNameMap.put(0, "motorL"); - s_simDeviceNameMap.put(1, "motorR"); - s_simDeviceNameMap.put(2, "motor3"); - s_simDeviceNameMap.put(3, "motor4"); - } - - private final SimDouble m_simSpeed; - private final SimBoolean m_simInverted; - - /** XRPMotor. */ - public XRPMotor(int deviceNum) { - checkDeviceAllocation(deviceNum); - - // We want this to appear on the WS messages as type: "XRPMotor", device: - String simDeviceName = "XRPMotor:" + s_simDeviceNameMap.get(deviceNum); - SimDevice xrpMotorSimDevice = SimDevice.create(simDeviceName); - - if (xrpMotorSimDevice != null) { - xrpMotorSimDevice.createBoolean("init", Direction.kOutput, true); - m_simInverted = xrpMotorSimDevice.createBoolean("inverted", Direction.kInput, false); - m_simSpeed = xrpMotorSimDevice.createDouble("speed", Direction.kOutput, 0.0); - } else { - m_simInverted = null; - m_simSpeed = null; - } - } - - @Override - public void set(double speed) { - if (m_simSpeed != null) { - boolean invert = false; - if (m_simInverted != null) { - invert = m_simInverted.get(); - } - - m_simSpeed.set(invert ? -speed : speed); - } - } - - @Override - public double get() { - if (m_simSpeed != null) { - return m_simSpeed.get(); - } - - return 0.0; - } - - @Override - public void setInverted(boolean isInverted) { - if (m_simInverted != null) { - m_simInverted.set(isInverted); - } - } - - @Override - public boolean getInverted() { - if (m_simInverted != null) { - return m_simInverted.get(); - } - return false; - } - - @Override - public void disable() { - set(0.0); - } - - @Override - public void stopMotor() { - set(0.0); - } -} diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/xrpreference/devices/XRPServo.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/xrpreference/devices/XRPServo.java deleted file mode 100644 index 064e20911a..0000000000 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/xrpreference/devices/XRPServo.java +++ /dev/null @@ -1,123 +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. - -package edu.wpi.first.wpilibj.examples.xrpreference.devices; - -import edu.wpi.first.hal.SimDevice; -import edu.wpi.first.hal.SimDevice.Direction; -import edu.wpi.first.hal.SimDouble; -import java.util.HashMap; -import java.util.HashSet; - -/** - * XRPServo. - * - *

A SimDevice based servo - */ -public class XRPServo { - private static HashMap s_simDeviceNameMap = new HashMap<>(); - private static HashSet s_registeredDevices = new HashSet<>(); - - private static void checkDeviceAllocation(int deviceNum) { - if (!s_simDeviceNameMap.containsKey(deviceNum)) { - throw new IllegalArgumentException("Invalid XRPServo device number. Should be 4-5"); - } - - if (s_registeredDevices.contains(deviceNum)) { - throw new IllegalArgumentException("XRPServo " + deviceNum + " already allocated"); - } - - s_registeredDevices.add(deviceNum); - } - - static { - s_simDeviceNameMap.put(4, "servo1"); - s_simDeviceNameMap.put(5, "servo2"); - } - - private final SimDouble m_simPosition; - - /** XRPServo. */ - public XRPServo(int deviceNum) { - checkDeviceAllocation(deviceNum); - - // We want this to appear on WS as type: "XRPServo", device: - String simDeviceName = "XRPServo:" + s_simDeviceNameMap.get(deviceNum); - SimDevice xrpServoSimDevice = SimDevice.create(simDeviceName); - - if (xrpServoSimDevice != null) { - xrpServoSimDevice.createBoolean("init", Direction.kOutput, true); - // This should mimic PWM position [0.0, 1.0] - m_simPosition = xrpServoSimDevice.createDouble("position", Direction.kOutput, 0.5); - } else { - m_simPosition = null; - } - } - - /** - * Set the servo angle. - * - * @param angle Desired angle in degrees - */ - public void setAngle(double angle) { - if (angle < 0.0) { - angle = 0.0; - } - - if (angle > 180.0) { - angle = 180.0; - } - - double pos = angle / 180.0; - - if (m_simPosition != null) { - m_simPosition.set(pos); - } - } - - /** - * Get the servo angle. - * - * @return Current servo angle - */ - public double getAngle() { - if (m_simPosition != null) { - return m_simPosition.get() * 180.0; - } - - return 90.0; - } - - /** - * Set the servo position. - * - * @param pos Desired position (Between 0.0 and 1.0) - */ - public void setPosition(double pos) { - if (pos < 0.0) { - pos = 0.0; - } - - if (pos > 1.0) { - pos = 1.0; - } - - if (m_simPosition != null) { - m_simPosition.set(pos); - } - } - - /** - * Get the servo position. - * - * @return Current servo position - */ - public double getPosition() { - if (m_simPosition != null) { - return m_simPosition.get(); - } - - return 0.5; - } -} diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/xrpreference/sensors/XRPGyro.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/xrpreference/sensors/XRPGyro.java deleted file mode 100644 index 101006f57b..0000000000 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/xrpreference/sensors/XRPGyro.java +++ /dev/null @@ -1,132 +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. - -package edu.wpi.first.wpilibj.examples.xrpreference.sensors; - -import edu.wpi.first.hal.SimDevice; -import edu.wpi.first.hal.SimDevice.Direction; -import edu.wpi.first.hal.SimDouble; - -public class XRPGyro { - private final SimDouble m_simRateX; - private final SimDouble m_simRateY; - private final SimDouble m_simRateZ; - private final SimDouble m_simAngleX; - private final SimDouble m_simAngleY; - private final SimDouble m_simAngleZ; - - private double m_angleXOffset; - private double m_angleYOffset; - private double m_angleZOffset; - - /** Create a new XRPGyro. */ - public XRPGyro() { - SimDevice gyroSimDevice = SimDevice.create("Gyro:XRPGyro"); - 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 = 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); - } else { - m_simRateX = null; - m_simRateY = null; - m_simRateZ = null; - - m_simAngleX = null; - m_simAngleY = null; - m_simAngleZ = null; - } - } - - /** - * Get the rate of turn in degrees-per-second around the X-axis. - * - * @return rate of turn in degrees-per-second - */ - public double getRateX() { - if (m_simRateX != null) { - return m_simRateX.get(); - } - - return 0.0; - } - - /** - * Get the rate of turn in degrees-per-second around the Y-axis. - * - * @return rate of turn in degrees-per-second - */ - public double getRateY() { - if (m_simRateY != null) { - return m_simRateY.get(); - } - - return 0.0; - } - - /** - * Get the rate of turn in degrees-per-second around the Z-axis. - * - * @return rate of turn in degrees-per-second - */ - public double getRateZ() { - if (m_simRateZ != null) { - return m_simRateZ.get(); - } - - return 0.0; - } - - /** - * Get the currently reported angle around the X-axis. - * - * @return current angle around X-axis in degrees - */ - public double getAngleX() { - if (m_simAngleX != null) { - return m_simAngleX.get() - m_angleXOffset; - } - - return 0.0; - } - - /** - * Get the currently reported angle around the X-axis. - * - * @return current angle around Y-axis in degrees - */ - public double getAngleY() { - if (m_simAngleY != null) { - return m_simAngleY.get() - m_angleYOffset; - } - - return 0.0; - } - - /** - * Get the currently reported angle around the Z-axis. - * - * @return current angle around Z-axis in degrees - */ - public double getAngleZ() { - if (m_simAngleZ != null) { - return m_simAngleZ.get() - m_angleZOffset; - } - - return 0.0; - } - - /** Reset the gyro angles to 0. */ - public void reset() { - if (m_simAngleX != null) { - m_angleXOffset = m_simAngleX.get(); - m_angleYOffset = m_simAngleY.get(); - m_angleZOffset = m_simAngleZ.get(); - } - } -} diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/xrpreference/subsystems/Arm.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/xrpreference/subsystems/Arm.java index 61b1d5b226..ecf88b0884 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/xrpreference/subsystems/Arm.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/xrpreference/subsystems/Arm.java @@ -4,7 +4,7 @@ package edu.wpi.first.wpilibj.examples.xrpreference.subsystems; -import edu.wpi.first.wpilibj.examples.xrpreference.devices.XRPServo; +import edu.wpi.first.wpilibj.xrp.XRPServo; import edu.wpi.first.wpilibj2.command.SubsystemBase; public class Arm extends SubsystemBase { diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/xrpreference/subsystems/Drivetrain.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/xrpreference/subsystems/Drivetrain.java index e15ea6cf4f..f618add665 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/xrpreference/subsystems/Drivetrain.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/xrpreference/subsystems/Drivetrain.java @@ -7,8 +7,8 @@ package edu.wpi.first.wpilibj.examples.xrpreference.subsystems; import edu.wpi.first.wpilibj.BuiltInAccelerometer; import edu.wpi.first.wpilibj.Encoder; import edu.wpi.first.wpilibj.drive.DifferentialDrive; -import edu.wpi.first.wpilibj.examples.xrpreference.devices.XRPMotor; -import edu.wpi.first.wpilibj.examples.xrpreference.sensors.XRPGyro; +import edu.wpi.first.wpilibj.xrp.XRPGyro; +import edu.wpi.first.wpilibj.xrp.XRPMotor; import edu.wpi.first.wpilibj2.command.SubsystemBase; public class Drivetrain extends SubsystemBase { diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/xrpreference/subsystems/XRPOnBoardIO.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/xrpreference/subsystems/XRPOnBoardIO.java deleted file mode 100644 index c52ebc08fa..0000000000 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/xrpreference/subsystems/XRPOnBoardIO.java +++ /dev/null @@ -1,47 +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. - -package edu.wpi.first.wpilibj.examples.xrpreference.subsystems; - -import edu.wpi.first.wpilibj.DigitalInput; -import edu.wpi.first.wpilibj.DigitalOutput; -import edu.wpi.first.wpilibj2.command.SubsystemBase; - -/** - * This class represents the onboard IO of the XRP Reference Robot. This includes the USER - * pushbutton and LED - */ -public class XRPOnBoardIO extends SubsystemBase { - private final DigitalInput m_button = new DigitalInput(0); - private final DigitalOutput m_led = new DigitalOutput(1); - - /** Constructor. */ - public XRPOnBoardIO() { - // No need to do anything else. Unlike the Romi, there are no other configurable - // I/O ports - } - - /** - * Gets if the USER button is pressed. - * - * @return True if the USER button is currently pressed. - */ - public boolean getUserButtonPressed() { - return m_button.get(); - } - - /** - * Sets the onboard LED. - * - * @param value True to activate LED, false otherwise. - */ - public void setLed(boolean value) { - m_led.set(value); - } - - @Override - public void periodic() { - // This method will be called once per scheduler run - } -} diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/templates.json b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/templates.json index cfc985ad6e..b4524f025b 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/templates.json +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/templates.json @@ -90,7 +90,10 @@ "foldername": "romicommandbased", "gradlebase": "javaromi", "mainclass": "Main", - "commandversion": 2 + "commandversion": 2, + "extravendordeps": [ + "romi" + ] }, { "name": "Romi - Timed Robot", @@ -102,7 +105,10 @@ "foldername": "romitimed", "gradlebase": "javaromi", "mainclass": "Main", - "commandversion": 2 + "commandversion": 2, + "extravendordeps": [ + "romi" + ] }, { "name": "XRP - Command Robot", @@ -114,7 +120,10 @@ "foldername": "xrpcommandbased", "gradlebase": "javaxrp", "mainclass": "Main", - "commandversion": 2 + "commandversion": 2, + "extravendordeps": [ + "xrp" + ] }, { "name": "XRP - Timed Robot", @@ -126,7 +135,10 @@ "foldername": "xrptimed", "gradlebase": "javaxrp", "mainclass": "Main", - "commandversion": 2 + "commandversion": 2, + "extravendordeps": [ + "xrp" + ] }, { "name": "Educational Robot", @@ -149,7 +161,10 @@ "foldername": "romieducational", "gradlebase": "javaromi", "mainclass": "Main", - "commandversion": 2 + "commandversion": 2, + "extravendordeps": [ + "romi" + ] }, { "name": "XRP - Educational Robot", @@ -161,6 +176,9 @@ "foldername": "xrpeducational", "gradlebase": "javaxrp", "mainclass": "Main", - "commandversion": 2 + "commandversion": 2, + "extravendordeps": [ + "xrp" + ] } ] diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/xrpcommandbased/devices/XRPMotor.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/xrpcommandbased/devices/XRPMotor.java deleted file mode 100644 index a5c71465cd..0000000000 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/xrpcommandbased/devices/XRPMotor.java +++ /dev/null @@ -1,109 +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. - -package edu.wpi.first.wpilibj.templates.xrpcommandbased.devices; - -import edu.wpi.first.hal.SimBoolean; -import edu.wpi.first.hal.SimDevice; -import edu.wpi.first.hal.SimDevice.Direction; -import edu.wpi.first.hal.SimDouble; -import edu.wpi.first.wpilibj.motorcontrol.MotorController; -import java.util.HashMap; -import java.util.HashSet; - -/** - * XRPMotor. - * - *

A SimDevice based motor controller representing the motors on an XRP robot - */ -public class XRPMotor implements MotorController { - private static HashMap s_simDeviceNameMap = new HashMap<>(); - private static HashSet s_registeredDevices = new HashSet<>(); - - private static void checkDeviceAllocation(int deviceNum) { - if (!s_simDeviceNameMap.containsKey(deviceNum)) { - throw new IllegalArgumentException("Invalid XRPMotor device number. Should be 0-3"); - } - - if (s_registeredDevices.contains(deviceNum)) { - throw new IllegalArgumentException("XRPMotor " + deviceNum + " already allocated"); - } - - s_registeredDevices.add(deviceNum); - } - - static { - s_simDeviceNameMap.put(0, "motorL"); - s_simDeviceNameMap.put(1, "motorR"); - s_simDeviceNameMap.put(2, "motor3"); - s_simDeviceNameMap.put(3, "motor4"); - } - - private final SimDouble m_simSpeed; - private final SimBoolean m_simInverted; - - /** XRPMotor. */ - public XRPMotor(int deviceNum) { - checkDeviceAllocation(deviceNum); - - // We want this to appear on the WS messages as type: "XRPMotor", device: - String simDeviceName = "XRPMotor:" + s_simDeviceNameMap.get(deviceNum); - SimDevice xrpMotorSimDevice = SimDevice.create(simDeviceName); - - if (xrpMotorSimDevice != null) { - xrpMotorSimDevice.createBoolean("init", Direction.kOutput, true); - m_simInverted = xrpMotorSimDevice.createBoolean("inverted", Direction.kInput, false); - m_simSpeed = xrpMotorSimDevice.createDouble("speed", Direction.kOutput, 0.0); - } else { - m_simInverted = null; - m_simSpeed = null; - } - } - - @Override - public void set(double speed) { - if (m_simSpeed != null) { - boolean invert = false; - if (m_simInverted != null) { - invert = m_simInverted.get(); - } - - m_simSpeed.set(invert ? -speed : speed); - } - } - - @Override - public double get() { - if (m_simSpeed != null) { - return m_simSpeed.get(); - } - - return 0.0; - } - - @Override - public void setInverted(boolean isInverted) { - if (m_simInverted != null) { - m_simInverted.set(isInverted); - } - } - - @Override - public boolean getInverted() { - if (m_simInverted != null) { - return m_simInverted.get(); - } - return false; - } - - @Override - public void disable() { - set(0.0); - } - - @Override - public void stopMotor() { - set(0.0); - } -} diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/xrpcommandbased/devices/XRPServo.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/xrpcommandbased/devices/XRPServo.java deleted file mode 100644 index b88fa50c5b..0000000000 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/xrpcommandbased/devices/XRPServo.java +++ /dev/null @@ -1,123 +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. - -package edu.wpi.first.wpilibj.templates.xrpcommandbased.devices; - -import edu.wpi.first.hal.SimDevice; -import edu.wpi.first.hal.SimDevice.Direction; -import edu.wpi.first.hal.SimDouble; -import java.util.HashMap; -import java.util.HashSet; - -/** - * XRPServo. - * - *

A SimDevice based servo - */ -public class XRPServo { - private static HashMap s_simDeviceNameMap = new HashMap<>(); - private static HashSet s_registeredDevices = new HashSet<>(); - - private static void checkDeviceAllocation(int deviceNum) { - if (!s_simDeviceNameMap.containsKey(deviceNum)) { - throw new IllegalArgumentException("Invalid XRPServo device number. Should be 4-5"); - } - - if (s_registeredDevices.contains(deviceNum)) { - throw new IllegalArgumentException("XRPServo " + deviceNum + " already allocated"); - } - - s_registeredDevices.add(deviceNum); - } - - static { - s_simDeviceNameMap.put(4, "servo1"); - s_simDeviceNameMap.put(5, "servo2"); - } - - private final SimDouble m_simPosition; - - /** XRPServo. */ - public XRPServo(int deviceNum) { - checkDeviceAllocation(deviceNum); - - // We want this to appear on WS as type: "XRPServo", device: - String simDeviceName = "XRPServo:" + s_simDeviceNameMap.get(deviceNum); - SimDevice xrpServoSimDevice = SimDevice.create(simDeviceName); - - if (xrpServoSimDevice != null) { - xrpServoSimDevice.createBoolean("init", Direction.kOutput, true); - // This should mimic PWM position [0.0, 1.0] - m_simPosition = xrpServoSimDevice.createDouble("position", Direction.kOutput, 0.5); - } else { - m_simPosition = null; - } - } - - /** - * Set the servo angle. - * - * @param angle Desired angle in degrees - */ - public void setAngle(double angle) { - if (angle < 0.0) { - angle = 0.0; - } - - if (angle > 180.0) { - angle = 180.0; - } - - double pos = angle / 180.0; - - if (m_simPosition != null) { - m_simPosition.set(pos); - } - } - - /** - * Get the servo angle. - * - * @return Current servo angle - */ - public double getAngle() { - if (m_simPosition != null) { - return m_simPosition.get() * 180.0; - } - - return 90.0; - } - - /** - * Set the servo position. - * - * @param pos Desired position (Between 0.0 and 1.0) - */ - public void setPosition(double pos) { - if (pos < 0.0) { - pos = 0.0; - } - - if (pos > 1.0) { - pos = 1.0; - } - - if (m_simPosition != null) { - m_simPosition.set(pos); - } - } - - /** - * Get the servo position. - * - * @return Current servo position - */ - public double getPosition() { - if (m_simPosition != null) { - return m_simPosition.get(); - } - - return 0.5; - } -} diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/xrpcommandbased/subsystems/XRPDrivetrain.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/xrpcommandbased/subsystems/XRPDrivetrain.java index e8e6eb63f4..a3a1063a21 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/xrpcommandbased/subsystems/XRPDrivetrain.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/xrpcommandbased/subsystems/XRPDrivetrain.java @@ -6,7 +6,7 @@ package edu.wpi.first.wpilibj.templates.xrpcommandbased.subsystems; import edu.wpi.first.wpilibj.Encoder; import edu.wpi.first.wpilibj.drive.DifferentialDrive; -import edu.wpi.first.wpilibj.templates.xrpcommandbased.devices.XRPMotor; +import edu.wpi.first.wpilibj.xrp.XRPMotor; import edu.wpi.first.wpilibj2.command.SubsystemBase; public class XRPDrivetrain extends SubsystemBase { diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/xrpeducational/XRPDrivetrain.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/xrpeducational/XRPDrivetrain.java index 54fff39523..8f73baec50 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/xrpeducational/XRPDrivetrain.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/xrpeducational/XRPDrivetrain.java @@ -6,7 +6,7 @@ package edu.wpi.first.wpilibj.templates.xrpeducational; import edu.wpi.first.wpilibj.Encoder; import edu.wpi.first.wpilibj.drive.DifferentialDrive; -import edu.wpi.first.wpilibj.templates.xrpeducational.devices.XRPMotor; +import edu.wpi.first.wpilibj.xrp.XRPMotor; public class XRPDrivetrain { private static final double kGearRatio = diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/xrpeducational/devices/XRPMotor.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/xrpeducational/devices/XRPMotor.java deleted file mode 100644 index c11f08153c..0000000000 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/xrpeducational/devices/XRPMotor.java +++ /dev/null @@ -1,109 +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. - -package edu.wpi.first.wpilibj.templates.xrpeducational.devices; - -import edu.wpi.first.hal.SimBoolean; -import edu.wpi.first.hal.SimDevice; -import edu.wpi.first.hal.SimDevice.Direction; -import edu.wpi.first.hal.SimDouble; -import edu.wpi.first.wpilibj.motorcontrol.MotorController; -import java.util.HashMap; -import java.util.HashSet; - -/** - * XRPMotor. - * - *

A SimDevice based motor controller representing the motors on an XRP robot - */ -public class XRPMotor implements MotorController { - private static HashMap s_simDeviceNameMap = new HashMap<>(); - private static HashSet s_registeredDevices = new HashSet<>(); - - private static void checkDeviceAllocation(int deviceNum) { - if (!s_simDeviceNameMap.containsKey(deviceNum)) { - throw new IllegalArgumentException("Invalid XRPMotor device number. Should be 0-3"); - } - - if (s_registeredDevices.contains(deviceNum)) { - throw new IllegalArgumentException("XRPMotor " + deviceNum + " already allocated"); - } - - s_registeredDevices.add(deviceNum); - } - - static { - s_simDeviceNameMap.put(0, "motorL"); - s_simDeviceNameMap.put(1, "motorR"); - s_simDeviceNameMap.put(2, "motor3"); - s_simDeviceNameMap.put(3, "motor4"); - } - - private final SimDouble m_simSpeed; - private final SimBoolean m_simInverted; - - /** XRPMotor. */ - public XRPMotor(int deviceNum) { - checkDeviceAllocation(deviceNum); - - // We want this to appear on the WS messages as type: "XRPMotor", device: - String simDeviceName = "XRPMotor:" + s_simDeviceNameMap.get(deviceNum); - SimDevice xrpMotorSimDevice = SimDevice.create(simDeviceName); - - if (xrpMotorSimDevice != null) { - xrpMotorSimDevice.createBoolean("init", Direction.kOutput, true); - m_simInverted = xrpMotorSimDevice.createBoolean("inverted", Direction.kInput, false); - m_simSpeed = xrpMotorSimDevice.createDouble("speed", Direction.kOutput, 0.0); - } else { - m_simInverted = null; - m_simSpeed = null; - } - } - - @Override - public void set(double speed) { - if (m_simSpeed != null) { - boolean invert = false; - if (m_simInverted != null) { - invert = m_simInverted.get(); - } - - m_simSpeed.set(invert ? -speed : speed); - } - } - - @Override - public double get() { - if (m_simSpeed != null) { - return m_simSpeed.get(); - } - - return 0.0; - } - - @Override - public void setInverted(boolean isInverted) { - if (m_simInverted != null) { - m_simInverted.set(isInverted); - } - } - - @Override - public boolean getInverted() { - if (m_simInverted != null) { - return m_simInverted.get(); - } - return false; - } - - @Override - public void disable() { - set(0.0); - } - - @Override - public void stopMotor() { - set(0.0); - } -} diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/xrpeducational/devices/XRPServo.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/xrpeducational/devices/XRPServo.java deleted file mode 100644 index 9f727797b0..0000000000 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/xrpeducational/devices/XRPServo.java +++ /dev/null @@ -1,123 +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. - -package edu.wpi.first.wpilibj.templates.xrpeducational.devices; - -import edu.wpi.first.hal.SimDevice; -import edu.wpi.first.hal.SimDevice.Direction; -import edu.wpi.first.hal.SimDouble; -import java.util.HashMap; -import java.util.HashSet; - -/** - * XRPServo. - * - *

A SimDevice based servo - */ -public class XRPServo { - private static HashMap s_simDeviceNameMap = new HashMap<>(); - private static HashSet s_registeredDevices = new HashSet<>(); - - private static void checkDeviceAllocation(int deviceNum) { - if (!s_simDeviceNameMap.containsKey(deviceNum)) { - throw new IllegalArgumentException("Invalid XRPServo device number. Should be 4-5"); - } - - if (s_registeredDevices.contains(deviceNum)) { - throw new IllegalArgumentException("XRPServo " + deviceNum + " already allocated"); - } - - s_registeredDevices.add(deviceNum); - } - - static { - s_simDeviceNameMap.put(4, "servo1"); - s_simDeviceNameMap.put(5, "servo2"); - } - - private final SimDouble m_simPosition; - - /** XRPServo. */ - public XRPServo(int deviceNum) { - checkDeviceAllocation(deviceNum); - - // We want this to appear on WS as type: "XRPServo", device: - String simDeviceName = "XRPServo:" + s_simDeviceNameMap.get(deviceNum); - SimDevice xrpServoSimDevice = SimDevice.create(simDeviceName); - - if (xrpServoSimDevice != null) { - xrpServoSimDevice.createBoolean("init", Direction.kOutput, true); - // This should mimic PWM position [0.0, 1.0] - m_simPosition = xrpServoSimDevice.createDouble("position", Direction.kOutput, 0.5); - } else { - m_simPosition = null; - } - } - - /** - * Set the servo angle. - * - * @param angle Desired angle in degrees - */ - public void setAngle(double angle) { - if (angle < 0.0) { - angle = 0.0; - } - - if (angle > 180.0) { - angle = 180.0; - } - - double pos = angle / 180.0; - - if (m_simPosition != null) { - m_simPosition.set(pos); - } - } - - /** - * Get the servo angle. - * - * @return Current servo angle - */ - public double getAngle() { - if (m_simPosition != null) { - return m_simPosition.get() * 180.0; - } - - return 90.0; - } - - /** - * Set the servo position. - * - * @param pos Desired position (Between 0.0 and 1.0) - */ - public void setPosition(double pos) { - if (pos < 0.0) { - pos = 0.0; - } - - if (pos > 1.0) { - pos = 1.0; - } - - if (m_simPosition != null) { - m_simPosition.set(pos); - } - } - - /** - * Get the servo position. - * - * @return Current servo position - */ - public double getPosition() { - if (m_simPosition != null) { - return m_simPosition.get(); - } - - return 0.5; - } -} diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/xrptimed/XRPDrivetrain.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/xrptimed/XRPDrivetrain.java index 3d8721b8fc..e66d750d09 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/xrptimed/XRPDrivetrain.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/xrptimed/XRPDrivetrain.java @@ -6,7 +6,7 @@ package edu.wpi.first.wpilibj.templates.xrptimed; import edu.wpi.first.wpilibj.Encoder; import edu.wpi.first.wpilibj.drive.DifferentialDrive; -import edu.wpi.first.wpilibj.templates.xrptimed.devices.XRPMotor; +import edu.wpi.first.wpilibj.xrp.XRPMotor; public class XRPDrivetrain { private static final double kGearRatio = diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/xrptimed/devices/XRPMotor.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/xrptimed/devices/XRPMotor.java deleted file mode 100644 index 8dab7022b9..0000000000 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/xrptimed/devices/XRPMotor.java +++ /dev/null @@ -1,109 +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. - -package edu.wpi.first.wpilibj.templates.xrptimed.devices; - -import edu.wpi.first.hal.SimBoolean; -import edu.wpi.first.hal.SimDevice; -import edu.wpi.first.hal.SimDevice.Direction; -import edu.wpi.first.hal.SimDouble; -import edu.wpi.first.wpilibj.motorcontrol.MotorController; -import java.util.HashMap; -import java.util.HashSet; - -/** - * XRPMotor. - * - *

A SimDevice based motor controller representing the motors on an XRP robot - */ -public class XRPMotor implements MotorController { - private static HashMap s_simDeviceNameMap = new HashMap<>(); - private static HashSet s_registeredDevices = new HashSet<>(); - - private static void checkDeviceAllocation(int deviceNum) { - if (!s_simDeviceNameMap.containsKey(deviceNum)) { - throw new IllegalArgumentException("Invalid XRPMotor device number. Should be 0-3"); - } - - if (s_registeredDevices.contains(deviceNum)) { - throw new IllegalArgumentException("XRPMotor " + deviceNum + " already allocated"); - } - - s_registeredDevices.add(deviceNum); - } - - static { - s_simDeviceNameMap.put(0, "motorL"); - s_simDeviceNameMap.put(1, "motorR"); - s_simDeviceNameMap.put(2, "motor3"); - s_simDeviceNameMap.put(3, "motor4"); - } - - private final SimDouble m_simSpeed; - private final SimBoolean m_simInverted; - - /** XRPMotor. */ - public XRPMotor(int deviceNum) { - checkDeviceAllocation(deviceNum); - - // We want this to appear on the WS messages as type: "XRPMotor", device: - String simDeviceName = "XRPMotor:" + s_simDeviceNameMap.get(deviceNum); - SimDevice xrpMotorSimDevice = SimDevice.create(simDeviceName); - - if (xrpMotorSimDevice != null) { - xrpMotorSimDevice.createBoolean("init", Direction.kOutput, true); - m_simInverted = xrpMotorSimDevice.createBoolean("inverted", Direction.kInput, false); - m_simSpeed = xrpMotorSimDevice.createDouble("speed", Direction.kOutput, 0.0); - } else { - m_simInverted = null; - m_simSpeed = null; - } - } - - @Override - public void set(double speed) { - if (m_simSpeed != null) { - boolean invert = false; - if (m_simInverted != null) { - invert = m_simInverted.get(); - } - - m_simSpeed.set(invert ? -speed : speed); - } - } - - @Override - public double get() { - if (m_simSpeed != null) { - return m_simSpeed.get(); - } - - return 0.0; - } - - @Override - public void setInverted(boolean isInverted) { - if (m_simInverted != null) { - m_simInverted.set(isInverted); - } - } - - @Override - public boolean getInverted() { - if (m_simInverted != null) { - return m_simInverted.get(); - } - return false; - } - - @Override - public void disable() { - set(0.0); - } - - @Override - public void stopMotor() { - set(0.0); - } -} diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/xrptimed/devices/XRPServo.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/xrptimed/devices/XRPServo.java deleted file mode 100644 index b3c4e637ef..0000000000 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/xrptimed/devices/XRPServo.java +++ /dev/null @@ -1,123 +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. - -package edu.wpi.first.wpilibj.templates.xrptimed.devices; - -import edu.wpi.first.hal.SimDevice; -import edu.wpi.first.hal.SimDevice.Direction; -import edu.wpi.first.hal.SimDouble; -import java.util.HashMap; -import java.util.HashSet; - -/** - * XRPServo. - * - *

A SimDevice based servo - */ -public class XRPServo { - private static HashMap s_simDeviceNameMap = new HashMap<>(); - private static HashSet s_registeredDevices = new HashSet<>(); - - private static void checkDeviceAllocation(int deviceNum) { - if (!s_simDeviceNameMap.containsKey(deviceNum)) { - throw new IllegalArgumentException("Invalid XRPServo device number. Should be 4-5"); - } - - if (s_registeredDevices.contains(deviceNum)) { - throw new IllegalArgumentException("XRPServo " + deviceNum + " already allocated"); - } - - s_registeredDevices.add(deviceNum); - } - - static { - s_simDeviceNameMap.put(4, "servo1"); - s_simDeviceNameMap.put(5, "servo2"); - } - - private final SimDouble m_simPosition; - - /** XRPServo. */ - public XRPServo(int deviceNum) { - checkDeviceAllocation(deviceNum); - - // We want this to appear on WS as type: "XRPServo", device: - String simDeviceName = "XRPServo:" + s_simDeviceNameMap.get(deviceNum); - SimDevice xrpServoSimDevice = SimDevice.create(simDeviceName); - - if (xrpServoSimDevice != null) { - xrpServoSimDevice.createBoolean("init", Direction.kOutput, true); - // This should mimic PWM position [0.0, 1.0] - m_simPosition = xrpServoSimDevice.createDouble("position", Direction.kOutput, 0.5); - } else { - m_simPosition = null; - } - } - - /** - * Set the servo angle. - * - * @param angle Desired angle in degrees - */ - public void setAngle(double angle) { - if (angle < 0.0) { - angle = 0.0; - } - - if (angle > 180.0) { - angle = 180.0; - } - - double pos = angle / 180.0; - - if (m_simPosition != null) { - m_simPosition.set(pos); - } - } - - /** - * Get the servo angle. - * - * @return Current servo angle - */ - public double getAngle() { - if (m_simPosition != null) { - return m_simPosition.get() * 180.0; - } - - return 90.0; - } - - /** - * Set the servo position. - * - * @param pos Desired position (Between 0.0 and 1.0) - */ - public void setPosition(double pos) { - if (pos < 0.0) { - pos = 0.0; - } - - if (pos > 1.0) { - pos = 1.0; - } - - if (m_simPosition != null) { - m_simPosition.set(pos); - } - } - - /** - * Get the servo position. - * - * @return Current servo position - */ - public double getPosition() { - if (m_simPosition != null) { - return m_simPosition.get(); - } - - return 0.5; - } -}