Files
RiseOfRidgebotics2020/src/main/java/frc4388/robot/subsystems/LimeLight.java
T

109 lines
2.9 KiB
Java
Raw Normal View History

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 11:09:19 -06:00
public void identifyPath(){
changePipeline(1);
if (withinCoords(VisionConstants.aBlue))
{
galacticSearchPath = "A_BLUE";
}
changePipeline(2);
if (withinCoords(VisionConstants.bBlue))
{
galacticSearchPath = "B_BLUE";
}
changePipeline(1);
if (withinCoords(VisionConstants.aRed))
{
galacticSearchPath = "A_RED";
}
changePipeline(1);
if (withinCoords(VisionConstants.bRed))
{
galacticSearchPath = "B_RED";
}
SmartDashboard.putString("GalacticSearchPath", galacticSearchPath);
}
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
}
}