2020-02-25 20:01:24 -07:00
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
|
|
|
|
|
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
|
|
|
|
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
|
|
|
|
/* the project. */
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
package frc4388.robot.subsystems;
|
|
|
|
|
|
|
|
|
|
import edu.wpi.first.networktables.NetworkTableInstance;
|
2021-04-03 11:09:19 -06:00
|
|
|
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
|
2020-02-25 20:01:24 -07:00
|
|
|
import edu.wpi.first.wpilibj2.command.SubsystemBase;
|
2021-04-03 11:09:19 -06:00
|
|
|
import frc4388.robot.Constants.VisionConstants;
|
2020-02-25 20:01:24 -07:00
|
|
|
|
|
|
|
|
public class LimeLight extends SubsystemBase {
|
|
|
|
|
/**
|
|
|
|
|
* Creates a new LimeLight.
|
|
|
|
|
*/
|
2021-03-19 01:34:57 -06:00
|
|
|
public String galacticSearchPath;
|
|
|
|
|
|
2020-02-25 20:01:24 -07:00
|
|
|
public LimeLight() {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-28 20:05:56 -07:00
|
|
|
public void limeOff(){
|
2021-03-21 17:29:31 -06:00
|
|
|
NetworkTableInstance.getDefault().getTable("limelight").getEntry("camMode").setNumber(0);
|
|
|
|
|
NetworkTableInstance.getDefault().getTable("limelight").getEntry("ledMode").setNumber(1);
|
2020-02-25 20:01:24 -07:00
|
|
|
}
|
|
|
|
|
|
2020-02-28 20:05:56 -07:00
|
|
|
public void limeOn(){
|
2020-02-25 20:01:24 -07:00
|
|
|
NetworkTableInstance.getDefault().getTable("limelight").getEntry("camMode").setNumber(0);
|
|
|
|
|
NetworkTableInstance.getDefault().getTable("limelight").getEntry("ledMode").setNumber(3);
|
|
|
|
|
}
|
2021-03-19 01:34:57 -06:00
|
|
|
|
|
|
|
|
public void changePipeline(int pipelineId)
|
|
|
|
|
{
|
|
|
|
|
NetworkTableInstance.getDefault().getTable("limelight").getEntry("pipeline").setNumber(pipelineId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public double getV()
|
|
|
|
|
{
|
|
|
|
|
return NetworkTableInstance.getDefault().getTable("limelight").getEntry("tv").getDouble(0);
|
|
|
|
|
}
|
|
|
|
|
public double getX()
|
|
|
|
|
{
|
|
|
|
|
return NetworkTableInstance.getDefault().getTable("limelight").getEntry("tx").getDouble(0);
|
|
|
|
|
}
|
|
|
|
|
public double getY()
|
|
|
|
|
{
|
|
|
|
|
return NetworkTableInstance.getDefault().getTable("limelight").getEntry("ty").getDouble(0);
|
|
|
|
|
}
|
2020-02-25 20:01:24 -07:00
|
|
|
|
2021-04-03 14:11:05 -06:00
|
|
|
int i = 0;
|
|
|
|
|
boolean onceThrough = false;
|
|
|
|
|
boolean pathFound = false;
|
2021-04-03 11:09:19 -06:00
|
|
|
public void identifyPath(){
|
|
|
|
|
|
2021-04-03 14:11:05 -06:00
|
|
|
if (!onceThrough)
|
2021-04-03 11:09:19 -06:00
|
|
|
{
|
2021-04-03 14:11:05 -06:00
|
|
|
changePipeline(2);
|
|
|
|
|
if (withinCoords(VisionConstants.aBlue))
|
|
|
|
|
{
|
|
|
|
|
pathFound = true;
|
|
|
|
|
galacticSearchPath = "A_BLUE";
|
|
|
|
|
}
|
2021-04-03 11:09:19 -06:00
|
|
|
|
2021-04-03 14:11:05 -06:00
|
|
|
changePipeline(4);
|
|
|
|
|
if (withinCoords(VisionConstants.bBlue))
|
|
|
|
|
{
|
|
|
|
|
pathFound = true;
|
|
|
|
|
galacticSearchPath = "B_BLUE";
|
|
|
|
|
}
|
2021-04-03 11:09:19 -06:00
|
|
|
|
2021-04-03 14:11:05 -06:00
|
|
|
changePipeline(1);
|
|
|
|
|
if (withinCoords(VisionConstants.aRed))
|
|
|
|
|
{
|
|
|
|
|
pathFound = true;
|
|
|
|
|
galacticSearchPath = "A_RED";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
changePipeline(3);
|
|
|
|
|
if (withinCoords(VisionConstants.bRed))
|
|
|
|
|
{
|
|
|
|
|
pathFound = true;
|
|
|
|
|
galacticSearchPath = "B_RED";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (pathFound == false)
|
|
|
|
|
{
|
|
|
|
|
galacticSearchPath = "PathNotFound";
|
|
|
|
|
}
|
|
|
|
|
SmartDashboard.putString("GalacticSearchPath", galacticSearchPath);
|
|
|
|
|
onceThrough = true;
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
i++;
|
|
|
|
|
SmartDashboard.putNumber("Counter", i);
|
|
|
|
|
}
|
|
|
|
|
if (i >= 50)
|
2021-04-03 11:09:19 -06:00
|
|
|
{
|
2021-04-03 14:11:05 -06:00
|
|
|
i=0;
|
|
|
|
|
pathFound = false;
|
|
|
|
|
onceThrough = false;
|
2021-04-03 11:09:19 -06:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean withinError(double angle, double goal)
|
|
|
|
|
{
|
|
|
|
|
if(goal > (angle - VisionConstants.searchError) && goal < (angle + VisionConstants.searchError))
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean withinCoords(double[] coords)
|
|
|
|
|
{
|
|
|
|
|
if (withinError(getX(), coords[0]) && withinError(getY(), coords[1]))
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-25 20:01:24 -07:00
|
|
|
@Override
|
|
|
|
|
public void periodic() {
|
|
|
|
|
// This method will be called once per scheduler run
|
|
|
|
|
}
|
|
|
|
|
}
|