From a096cb7c96673dde02c5bd1486fc0ad6e8402071 Mon Sep 17 00:00:00 2001 From: 09lkei <09lkei@brightoncollege.net> Date: Wed, 6 Mar 2024 16:41:40 +0000 Subject: [PATCH] added color sensour code --- .vscode/launch.json | 12 ++- .../commands/colorSensorDriveUntilTape.java | 51 +++++++++++++ vendordeps/REVLib.json | 74 +++++++++++++++++++ 3 files changed, 134 insertions(+), 3 deletions(-) create mode 100644 src/main/java/frc/robot/commands/colorSensorDriveUntilTape.java create mode 100644 vendordeps/REVLib.json diff --git a/.vscode/launch.json b/.vscode/launch.json index c9c9713..629d4b1 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -4,18 +4,24 @@ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ - + { + "type": "java", + "name": "Launch Main", + "request": "launch", + "mainClass": "frc.robot.Main", + "projectName": "2024" + }, { "type": "wpilib", "name": "WPILib Desktop Debug", "request": "launch", - "desktop": true, + "desktop": true }, { "type": "wpilib", "name": "WPILib roboRIO Debug", "request": "launch", - "desktop": false, + "desktop": false } ] } diff --git a/src/main/java/frc/robot/commands/colorSensorDriveUntilTape.java b/src/main/java/frc/robot/commands/colorSensorDriveUntilTape.java new file mode 100644 index 0000000..2509d84 --- /dev/null +++ b/src/main/java/frc/robot/commands/colorSensorDriveUntilTape.java @@ -0,0 +1,51 @@ +// 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 frc.robot.commands; + +import edu.wpi.first.wpilibj2.command.Command; +import edu.wpi.first.wpilibj.I2C; +import com.revrobotics.ColorSensorV3; +import com.revrobotics.ColorMatchResult; +import com.revrobotics.ColorMatch; +import edu.wpi.first.wpilibj.util.Color; + +public class colorSensorDriveUntilTape extends Command { + private final I2C.Port i2cPort = I2C.Port.kOnboard; + private final ColorSensorV3 m_colorSensor = new ColorSensorV3(i2cPort); + private final ColorMatch m_colorMatcher = new ColorMatch(); + private Color tileColor; + + public colorSensorDriveUntilTape(Color colorsToDetect[], Color tileColor) { + m_colorMatcher.addColorMatch(tileColor); + this.tileColor = tileColor; + for (Color colorToDetect : colorsToDetect) { + m_colorMatcher.addColorMatch(colorToDetect); + } + } + + + @Override + public void initialize() {} + + @Override + public void execute() { + Color detectedColor = m_colorSensor.getColor(); + int proximity = m_colorSensor.getProximity(); + ColorMatchResult match = m_colorMatcher.matchClosestColor(detectedColor); + if (match.color == tileColor) { + // put start code code here + } else { + // put stop code here + } + } + + @Override + public void end(boolean interrupted) {} + + @Override + public boolean isFinished() { + return false; + } +} diff --git a/vendordeps/REVLib.json b/vendordeps/REVLib.json new file mode 100644 index 0000000..60eacf8 --- /dev/null +++ b/vendordeps/REVLib.json @@ -0,0 +1,74 @@ +{ + "fileName": "REVLib.json", + "name": "REVLib", + "version": "2024.2.3", + "frcYear": "2024", + "uuid": "3f48eb8c-50fe-43a6-9cb7-44c86353c4cb", + "mavenUrls": [ + "https://maven.revrobotics.com/" + ], + "jsonUrl": "https://software-metadata.revrobotics.com/REVLib-2024.json", + "javaDependencies": [ + { + "groupId": "com.revrobotics.frc", + "artifactId": "REVLib-java", + "version": "2024.2.3" + } + ], + "jniDependencies": [ + { + "groupId": "com.revrobotics.frc", + "artifactId": "REVLib-driver", + "version": "2024.2.3", + "skipInvalidPlatforms": true, + "isJar": false, + "validPlatforms": [ + "windowsx86-64", + "windowsx86", + "linuxarm64", + "linuxx86-64", + "linuxathena", + "linuxarm32", + "osxuniversal" + ] + } + ], + "cppDependencies": [ + { + "groupId": "com.revrobotics.frc", + "artifactId": "REVLib-cpp", + "version": "2024.2.3", + "libName": "REVLib", + "headerClassifier": "headers", + "sharedLibrary": false, + "skipInvalidPlatforms": true, + "binaryPlatforms": [ + "windowsx86-64", + "windowsx86", + "linuxarm64", + "linuxx86-64", + "linuxathena", + "linuxarm32", + "osxuniversal" + ] + }, + { + "groupId": "com.revrobotics.frc", + "artifactId": "REVLib-driver", + "version": "2024.2.3", + "libName": "REVLibDriver", + "headerClassifier": "headers", + "sharedLibrary": false, + "skipInvalidPlatforms": true, + "binaryPlatforms": [ + "windowsx86-64", + "windowsx86", + "linuxarm64", + "linuxx86-64", + "linuxathena", + "linuxarm32", + "osxuniversal" + ] + } + ] +} \ No newline at end of file