Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file modified SwerveCode/gradlew
100644 → 100755
Empty file.
36 changes: 17 additions & 19 deletions SwerveCode/src/main/java/frc/robot/ColorSensor.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,44 +12,42 @@
public class ColorSensor{
private final I2C.Port i2cPort = I2C.Port.kOnboard;
private final ColorSensorV3 m_colorSensor = new ColorSensorV3(i2cPort);


private ALLIANCE_COLOR alliance;
private ALLIANCE_COLOR currentBallColor;


public ColorSensor(){
alliance = updateCurrentBallColor();
alliance = updateCurrentBallColor();
currentBallColor = alliance;
}

public void getColors(){
public ALLIANCE_COLOR updateCurrentBallColor(){
Color detectedColor = m_colorSensor.getColor();
int proximity = m_colorSensor.getProximity();

SmartDashboard.putNumber("Red", detectedColor.red); //output the seen overall red value to the smartdashboard
SmartDashboard.putNumber("Blue", detectedColor.blue); //output the seen overall blue value to the smartdashboard
SmartDashboard.putNumber("Proximity", proximity); //distance from colorsensor to the nearest object (2047 to 0) output to the smartdashboard
SmartDashboard.putNumber("Proximity", m_colorSensor.getProximity()); //distance from colorsensor to the nearest object (2047 to 0) output to the smartdashboard
SmartDashboard.putString("alliance", this.toString()); //current alliance value output the the smartdashboard
//System.out.println(detectedColor.red);
}

public ALLIANCE_COLOR updateCurrentBallColor(){
Color detectedColor = m_colorSensor.getColor();
if(m_colorSensor.getProximity() >= 1500){
if(detectedColor.blue > detectedColor.red){
return ALLIANCE_COLOR.BLUE;
}else if(detectedColor.red > detectedColor.blue){
return ALLIANCE_COLOR.RED;
}
else{
return ALLIANCE_COLOR.NONE;
}
}else{
return ALLIANCE_COLOR.NONE;}
return ALLIANCE_COLOR.NONE;
}
}

public boolean compareBallToAlliance(){
if(currentBallColor == alliance){
return true;
}else if(currentBallColor != alliance){
return false;
}else{return false;}
boolean aColor = true;
if (this.alliance != ALLIANCE_COLOR.NONE){
ALLIANCE_COLOR color = updateCurrentBallColor();
aColor = (color != ALLIANCE_COLOR.NONE && color != this.alliance);
}
return aColor;
}

public int getProximity(){
Expand Down Expand Up @@ -78,4 +76,4 @@ public String toString(){
}
return s;
}
}
}
16 changes: 9 additions & 7 deletions SwerveCode/src/main/java/frc/robot/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class Robot extends TimedRobot {
public Locality locality;
public Shooter shooter;
public Collector collector;
public ColorSensor color;
public ColorSensor cSensor;


/**
Expand All @@ -59,7 +59,7 @@ public void robotInit() {
visionBall = new Vision(Constants.LIMELIGHT_BALL, Constants.BALL_LOCK_ERROR, Constants.BALL_CAMERA_HEIGHT, Constants.BALL_CAMERA_ANGLE, Constants.BALL_TARGET_HEIGHT, Constants.BALL_ROTATE_KP);
locality = new Locality(0, 0);
shooter = new Shooter();
color = new ColorSensor();
cSensor = new ColorSensor();
//ball.setLimelightAllianceColor(ALLIANCE_COLOR.RED);
NetworkTableInstance.getDefault().getTable("limelight-ball").getEntry("pipeline").setNumber(1);
}
Expand Down Expand Up @@ -96,7 +96,7 @@ public void robotPeriodic() {
*/
@Override
public void autonomousInit() {

cSensor = new ColorSensor();
m_autoSelected = m_chooser.getSelected();
// m_autoSelected = SmartDashboard.getString("Auto Selector", kDefaultAuto);
System.out.println("Auto selected: " + m_autoSelected);
Expand All @@ -108,6 +108,9 @@ public void autonomousInit() {
/** This function is called once when teleop is enabled. */
@Override
public void teleopInit() {
if (cSensor == null){
cSensor = new ColorSensor();
}
drive.zeroGyroscope();
//Create the primary controller object
}
Expand Down Expand Up @@ -160,12 +163,11 @@ else if(driverController.getLeftBumper() == true) {
}

SmartDashboard.putNumber("Rotate", rotate);
color.getColors();
if(color.getProximity() > 200){
color.updateCurrentBallColor();
cSensor.updateCurrentBallColor();
if(cSensor.getProximity() > 200){
cSensor.updateCurrentBallColor();
}


}
/** This function is called once when the robot is disabled. */
@Override
Expand Down
5 changes: 3 additions & 2 deletions SwerveCode/src/main/java/frc/robot/Shooter.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class Shooter{
public WPI_TalonFX flyWheelLeft;
public WPI_TalonFX flyWheelRight;
public WPI_TalonFX staging;

public ColorSensor cSensor;
//motor groups
MotorControllerGroup flyWheel;

Expand Down Expand Up @@ -61,7 +61,8 @@ public void testshooter(XboxController shooterController) {
staging.set(shooterController.getLeftTriggerAxis());

flyWheel.set(flyWheelSpeed);
}
}

}