From 68dae153910bf50650aa626ab2501015cb326ac4 Mon Sep 17 00:00:00 2001 From: "Ian N." <163360899+IanNpdx5@users.noreply.github.com> Date: Tue, 27 Oct 2026 20:59:07 -0700 Subject: [PATCH 1/2] added color sensor subsystem --- .wpilib/wpilib_preferences.json | 8 +- src/main/java/first/robot/RobotContainer.java | 11 ++ .../subsystems/colorsensor/ColorSensor.java | 26 ++++ .../subsystems/colorsensor/ColorSensorIO.java | 24 ++++ .../colorsensor/ColorSensorIORev.java | 34 +++++ vendordeps/REVLib.json | 126 ++++++++++++++++++ 6 files changed, 225 insertions(+), 4 deletions(-) create mode 100644 src/main/java/first/robot/subsystems/colorsensor/ColorSensor.java create mode 100644 src/main/java/first/robot/subsystems/colorsensor/ColorSensorIO.java create mode 100644 src/main/java/first/robot/subsystems/colorsensor/ColorSensorIORev.java create mode 100644 vendordeps/REVLib.json diff --git a/.wpilib/wpilib_preferences.json b/.wpilib/wpilib_preferences.json index 10cbd13..9442ed0 100644 --- a/.wpilib/wpilib_preferences.json +++ b/.wpilib/wpilib_preferences.json @@ -1,6 +1,6 @@ { - "enableCppIntellisense": false, - "currentLanguage": "java", - "projectYear": "2027_alpha7", - "teamNumber": 6328 + "enableCppIntellisense": false, + "currentLanguage": "java", + "projectYear": "2027_alpha7", + "teamNumber": 1425 } \ No newline at end of file diff --git a/src/main/java/first/robot/RobotContainer.java b/src/main/java/first/robot/RobotContainer.java index 941c15b..461ba0c 100644 --- a/src/main/java/first/robot/RobotContainer.java +++ b/src/main/java/first/robot/RobotContainer.java @@ -16,6 +16,9 @@ import first.generated.CompTunerConstants; import first.robot.Constants.DriveConstants; import first.robot.commands.drive.DriveCommands; +import first.robot.subsystems.colorsensor.ColorSensor; +import first.robot.subsystems.colorsensor.ColorSensorIO; +import first.robot.subsystems.colorsensor.ColorSensorIORev; import first.robot.subsystems.drive.Drive; import first.robot.subsystems.drive.GyroIO; import first.robot.subsystems.drive.GyroIOPigeon2; @@ -31,12 +34,14 @@ import org.wpilib.command2.Commands; import org.wpilib.command2.button.CommandXboxController; import org.wpilib.hardware.bus.CANPort; +import org.wpilib.hardware.bus.I2C; public class RobotContainer { private Drive drive; private AprilTagVision vision; private Motor motor; + private ColorSensor colorSensor; private final CommandXboxController gamepad = new CommandXboxController(0); @@ -57,6 +62,8 @@ public RobotContainer() { motor = new Motor(new MotorIOHardware(4, new CANBus(CANPort.CAN_S4))); + colorSensor = new ColorSensor(new ColorSensorIORev(I2C.Port.PORT_1)); + vision = new AprilTagVision( drive::addVisionMeasurement, @@ -93,6 +100,10 @@ public RobotContainer() { motor = new Motor(new MotorIO() {}); } + if (colorSensor == null) { + colorSensor = new ColorSensor(new ColorSensorIO() {}); + } + if (vision == null) { vision = new AprilTagVision(drive::addVisionMeasurement, new CameraIO() {}); } diff --git a/src/main/java/first/robot/subsystems/colorsensor/ColorSensor.java b/src/main/java/first/robot/subsystems/colorsensor/ColorSensor.java new file mode 100644 index 0000000..5c87b0e --- /dev/null +++ b/src/main/java/first/robot/subsystems/colorsensor/ColorSensor.java @@ -0,0 +1,26 @@ +// Copyright (c) 2026 FRC 1425 Error Code Xero +// http://github.com/errorcodexero +// +// Use of this source code is governed by an MIT-style +// license that can be found in the LICENSE file at +// the root directory of this project. + +package first.robot.subsystems.colorsensor; + +import org.littletonrobotics.junction.Logger; +import org.wpilib.command2.SubsystemBase; + +public class ColorSensor extends SubsystemBase { + private final ColorSensorIO io; + private final ColorSensorInputsAutoLogged inputs = new ColorSensorInputsAutoLogged(); + + public ColorSensor(ColorSensorIO io) { + this.io = io; + } + + @Override + public void periodic() { + io.updateInputs(inputs); + Logger.processInputs("ColorSensor", inputs); + } +} diff --git a/src/main/java/first/robot/subsystems/colorsensor/ColorSensorIO.java b/src/main/java/first/robot/subsystems/colorsensor/ColorSensorIO.java new file mode 100644 index 0000000..8fcd3e4 --- /dev/null +++ b/src/main/java/first/robot/subsystems/colorsensor/ColorSensorIO.java @@ -0,0 +1,24 @@ +// Copyright (c) 2026 FRC 1425 Error Code Xero +// http://github.com/errorcodexero +// +// Use of this source code is governed by an MIT-style +// license that can be found in the LICENSE file at +// the root directory of this project. + +package first.robot.subsystems.colorsensor; + +import org.littletonrobotics.junction.AutoLog; +import org.wpilib.util.Color; + +public interface ColorSensorIO { + @AutoLog + public static class ColorSensorInputs { + public boolean connected = false; + + public int[] rawColor = {0, 0, 0, 0}; // red, green, blue, ir + public Color color = Color.BLACK; + public int proximity = 0; + } + + public default void updateInputs(ColorSensorInputs inputs) {} +} diff --git a/src/main/java/first/robot/subsystems/colorsensor/ColorSensorIORev.java b/src/main/java/first/robot/subsystems/colorsensor/ColorSensorIORev.java new file mode 100644 index 0000000..579f2ff --- /dev/null +++ b/src/main/java/first/robot/subsystems/colorsensor/ColorSensorIORev.java @@ -0,0 +1,34 @@ +// Copyright (c) 2026 FRC 1425 Error Code Xero +// http://github.com/errorcodexero +// +// Use of this source code is governed by an MIT-style +// license that can be found in the LICENSE file at +// the root directory of this project. + +package first.robot.subsystems.colorsensor; + +import com.revrobotics.ColorSensorV3; +import com.revrobotics.ColorSensorV3.RawColor; +import org.wpilib.hardware.bus.I2C.Port; + +public class ColorSensorIORev implements ColorSensorIO { + private final ColorSensorV3 sensor; + + public ColorSensorIORev(Port i2CPort) { + sensor = new ColorSensorV3(i2CPort); + } + + @Override + public void updateInputs(ColorSensorInputs inputs) { + inputs.connected = sensor.isConnected(); + + RawColor rawColor = sensor.getRawColor(); + + inputs.rawColor[0] = rawColor.red; + inputs.rawColor[1] = rawColor.green; + inputs.rawColor[2] = rawColor.blue; + inputs.rawColor[3] = rawColor.ir; + inputs.color = sensor.getColor(); + inputs.proximity = sensor.getProximity(); + } +} diff --git a/vendordeps/REVLib.json b/vendordeps/REVLib.json new file mode 100644 index 0000000..8e9d07b --- /dev/null +++ b/vendordeps/REVLib.json @@ -0,0 +1,126 @@ +{ + "fileName": "REVLib.json", + "name": "REVLib", + "version": "2027.0.0-alpha-8", + "wpilibYear": "2027_alpha7", + "uuid": "3f48eb8c-50fe-43a6-9cb7-44c86353c4cb", + "mavenUrls": [ + "https://maven.revrobotics.com/" + ], + "jsonUrl": "https://software-metadata.revrobotics.com/REVLib-2027.json", + "javaDependencies": [ + { + "groupId": "com.revrobotics.frc", + "artifactId": "REVLib-java", + "version": "2027.0.0-alpha-8" + } + ], + "jniDependencies": [ + { + "groupId": "com.revrobotics.frc", + "artifactId": "REVLib-driver", + "version": "2027.0.0-alpha-8", + "skipInvalidPlatforms": true, + "isJar": false, + "validPlatforms": [ + "windowsx86-64", + "linuxarm64", + "linuxx86-64", + "linuxsystemcore", + "osxuniversal" + ] + }, + { + "groupId": "com.revrobotics.frc", + "artifactId": "RevLibBackendDriver", + "version": "2027.0.0-alpha-8", + "skipInvalidPlatforms": true, + "isJar": false, + "validPlatforms": [ + "windowsx86-64", + "linuxarm64", + "linuxx86-64", + "linuxsystemcore", + "osxuniversal" + ] + }, + { + "groupId": "com.revrobotics.frc", + "artifactId": "RevLibWpiBackendDriver", + "version": "2027.0.0-alpha-8", + "skipInvalidPlatforms": true, + "isJar": false, + "validPlatforms": [ + "windowsx86-64", + "linuxarm64", + "linuxx86-64", + "linuxsystemcore", + "osxuniversal" + ] + } + ], + "cppDependencies": [ + { + "groupId": "com.revrobotics.frc", + "artifactId": "REVLib-cpp", + "version": "2027.0.0-alpha-8", + "libName": "REVLib", + "headerClassifier": "headers", + "sharedLibrary": false, + "skipInvalidPlatforms": true, + "binaryPlatforms": [ + "windowsx86-64", + "linuxarm64", + "linuxx86-64", + "linuxsystemcore", + "osxuniversal" + ] + }, + { + "groupId": "com.revrobotics.frc", + "artifactId": "REVLib-driver", + "version": "2027.0.0-alpha-8", + "libName": "REVLibDriver", + "headerClassifier": "headers", + "sharedLibrary": false, + "skipInvalidPlatforms": true, + "binaryPlatforms": [ + "windowsx86-64", + "linuxarm64", + "linuxx86-64", + "linuxsystemcore", + "osxuniversal" + ] + }, + { + "groupId": "com.revrobotics.frc", + "artifactId": "RevLibBackendDriver", + "version": "2027.0.0-alpha-8", + "libName": "BackendDriver", + "sharedLibrary": true, + "skipInvalidPlatforms": true, + "binaryPlatforms": [ + "windowsx86-64", + "linuxarm64", + "linuxx86-64", + "linuxsystemcore", + "osxuniversal" + ] + }, + { + "groupId": "com.revrobotics.frc", + "artifactId": "RevLibWpiBackendDriver", + "version": "2027.0.0-alpha-8", + "libName": "REVLibWpi", + "sharedLibrary": true, + "skipInvalidPlatforms": true, + "binaryPlatforms": [ + "windowsx86-64", + "linuxarm64", + "linuxx86-64", + "linuxsystemcore", + "osxuniversal" + ] + } + ] +} From 80d434da11982cffe0844cf2c67fc3051667f5f0 Mon Sep 17 00:00:00 2001 From: "Ian N." <163360899+IanNpdx5@users.noreply.github.com> Date: Sat, 31 Oct 2026 11:00:25 -0700 Subject: [PATCH 2/2] Update REVLib.json --- vendordeps/REVLib.json | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/vendordeps/REVLib.json b/vendordeps/REVLib.json index 8e9d07b..e092b9a 100644 --- a/vendordeps/REVLib.json +++ b/vendordeps/REVLib.json @@ -1,7 +1,7 @@ { "fileName": "REVLib.json", "name": "REVLib", - "version": "2027.0.0-alpha-8", + "version": "2027.0.0-alpha-9", "wpilibYear": "2027_alpha7", "uuid": "3f48eb8c-50fe-43a6-9cb7-44c86353c4cb", "mavenUrls": [ @@ -12,14 +12,14 @@ { "groupId": "com.revrobotics.frc", "artifactId": "REVLib-java", - "version": "2027.0.0-alpha-8" + "version": "2027.0.0-alpha-9" } ], "jniDependencies": [ { "groupId": "com.revrobotics.frc", "artifactId": "REVLib-driver", - "version": "2027.0.0-alpha-8", + "version": "2027.0.0-alpha-9", "skipInvalidPlatforms": true, "isJar": false, "validPlatforms": [ @@ -33,7 +33,7 @@ { "groupId": "com.revrobotics.frc", "artifactId": "RevLibBackendDriver", - "version": "2027.0.0-alpha-8", + "version": "2027.0.0-alpha-9", "skipInvalidPlatforms": true, "isJar": false, "validPlatforms": [ @@ -47,7 +47,7 @@ { "groupId": "com.revrobotics.frc", "artifactId": "RevLibWpiBackendDriver", - "version": "2027.0.0-alpha-8", + "version": "2027.0.0-alpha-9", "skipInvalidPlatforms": true, "isJar": false, "validPlatforms": [ @@ -63,7 +63,7 @@ { "groupId": "com.revrobotics.frc", "artifactId": "REVLib-cpp", - "version": "2027.0.0-alpha-8", + "version": "2027.0.0-alpha-9", "libName": "REVLib", "headerClassifier": "headers", "sharedLibrary": false, @@ -79,7 +79,7 @@ { "groupId": "com.revrobotics.frc", "artifactId": "REVLib-driver", - "version": "2027.0.0-alpha-8", + "version": "2027.0.0-alpha-9", "libName": "REVLibDriver", "headerClassifier": "headers", "sharedLibrary": false, @@ -95,7 +95,7 @@ { "groupId": "com.revrobotics.frc", "artifactId": "RevLibBackendDriver", - "version": "2027.0.0-alpha-8", + "version": "2027.0.0-alpha-9", "libName": "BackendDriver", "sharedLibrary": true, "skipInvalidPlatforms": true, @@ -110,7 +110,7 @@ { "groupId": "com.revrobotics.frc", "artifactId": "RevLibWpiBackendDriver", - "version": "2027.0.0-alpha-8", + "version": "2027.0.0-alpha-9", "libName": "REVLibWpi", "sharedLibrary": true, "skipInvalidPlatforms": true,