generated from Patribots4738/Swerve-Command-Based
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
99 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package frc.robot.subsystems; | ||
|
||
import com.revrobotics.ColorMatchResult; | ||
import com.revrobotics.ColorSensorV3; | ||
import edu.wpi.first.wpilibj.I2C; | ||
import edu.wpi.first.wpilibj.util.Color; | ||
import edu.wpi.first.wpilibj2.command.SubsystemBase; | ||
import edu.wpi.first.wpilibj2.command.button.Trigger; | ||
import frc.robot.util.Constants.ColorSensorConstants; | ||
import monologue.Logged; | ||
import monologue.Annotations.Log; | ||
|
||
public class ColorSensor extends SubsystemBase implements Logged { | ||
|
||
private ColorSensorV3 colorSensor; | ||
|
||
private Trigger hasNoteTrigger; | ||
|
||
@Log | ||
private boolean hasOrange = false; | ||
|
||
private Color detectedColor = new Color(0.0, 0.0, 0.0); | ||
|
||
@Log | ||
private String colorString = ""; | ||
|
||
private ColorMatchResult match = ColorSensorConstants.COLOR_MATCH.matchClosestColor(detectedColor); | ||
|
||
@Log | ||
private String matchString = ""; | ||
|
||
public ColorSensor(I2C.Port i2cPort) { | ||
this.colorSensor = new ColorSensorV3(i2cPort); | ||
} | ||
|
||
@Override | ||
public void periodic() { | ||
this.detectedColor = colorSensor.getColor(); | ||
this.match = ColorSensorConstants.COLOR_MATCH.matchClosestColor(detectedColor); | ||
|
||
colorString = detectedColor.toString(); | ||
if (this.match.color == ColorSensorConstants.NOTE_ORANGE) { | ||
matchString = "Note"; | ||
hasOrange = true; | ||
} else { | ||
matchString = "Surely not a note"; | ||
hasOrange = false; | ||
} | ||
} | ||
|
||
public boolean hasNote() { | ||
return this.hasOrange; | ||
} | ||
|
||
public Trigger hasNoteTrigger() { | ||
if (hasNoteTrigger == null) { | ||
hasNoteTrigger = new Trigger(this::hasNote); | ||
} | ||
return hasNoteTrigger; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters