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..e092b9a --- /dev/null +++ b/vendordeps/REVLib.json @@ -0,0 +1,126 @@ +{ + "fileName": "REVLib.json", + "name": "REVLib", + "version": "2027.0.0-alpha-9", + "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-9" + } + ], + "jniDependencies": [ + { + "groupId": "com.revrobotics.frc", + "artifactId": "REVLib-driver", + "version": "2027.0.0-alpha-9", + "skipInvalidPlatforms": true, + "isJar": false, + "validPlatforms": [ + "windowsx86-64", + "linuxarm64", + "linuxx86-64", + "linuxsystemcore", + "osxuniversal" + ] + }, + { + "groupId": "com.revrobotics.frc", + "artifactId": "RevLibBackendDriver", + "version": "2027.0.0-alpha-9", + "skipInvalidPlatforms": true, + "isJar": false, + "validPlatforms": [ + "windowsx86-64", + "linuxarm64", + "linuxx86-64", + "linuxsystemcore", + "osxuniversal" + ] + }, + { + "groupId": "com.revrobotics.frc", + "artifactId": "RevLibWpiBackendDriver", + "version": "2027.0.0-alpha-9", + "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-9", + "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-9", + "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-9", + "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-9", + "libName": "REVLibWpi", + "sharedLibrary": true, + "skipInvalidPlatforms": true, + "binaryPlatforms": [ + "windowsx86-64", + "linuxarm64", + "linuxx86-64", + "linuxsystemcore", + "osxuniversal" + ] + } + ] +}