Making Galactic Search work

untested
This commit is contained in:
ryan123rudder
2021-03-19 01:34:57 -06:00
parent d5a4d6cab3
commit d9fc99ba4a
5 changed files with 196 additions and 23 deletions
@@ -0,0 +1,39 @@
/*----------------------------------------------------------------------------*/
/* 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.commands.auto;
import edu.wpi.first.wpilibj2.command.RamseteCommand;
import edu.wpi.first.wpilibj2.command.SequentialCommandGroup;
import frc4388.robot.subsystems.LimeLight;
// NOTE: Consider using this command inline, rather than writing a subclass. For more
// information, see:
// https://docs.wpilib.org/en/latest/docs/software/commandbased/convenience-features.html
public class GalacticSearch extends SequentialCommandGroup {
/**
* Creates a new GalacticSearch.
*/
public GalacticSearch(LimeLight m_limeLight, RamseteCommand[] paths) {
if (m_limeLight.galacticSearchPath == "A_RED")
{
addCommands(paths[0]);
}
else if (m_limeLight.galacticSearchPath == "A_BLUE")
{
addCommands(paths[1]);
}
else if (m_limeLight.galacticSearchPath == "B_RED")
{
addCommands(paths[2]);
}
else if (m_limeLight.galacticSearchPath == "B_BLUE")
{
addCommands(paths[3]);
}
}
}
@@ -0,0 +1,101 @@
/*----------------------------------------------------------------------------*/
/* 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.commands.auto;
import edu.wpi.first.networktables.NetworkTableInstance;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import edu.wpi.first.wpilibj2.command.CommandBase;
import frc4388.robot.Constants.VisionConstants;
import frc4388.robot.subsystems.LimeLight;
public class IdentifyPath extends CommandBase {
LimeLight m_limeLight;
double xAngle;
double yAngle;
double target;
public String path;
public IdentifyPath(LimeLight limeLight) {
m_limeLight = limeLight;
addRequirements(m_limeLight);
m_limeLight.limeOff();
}
// Called when the command is initially scheduled.
@Override
public void initialize() {
m_limeLight.limeOn();
path = "";
}
// Called every time the scheduler runs while the command is scheduled.
@Override
public void execute() {
target = m_limeLight.getV();
xAngle = m_limeLight.getX();
yAngle = m_limeLight.getY();
m_limeLight.changePipeline(1); //Dual Targetting
//Identify which of four paths
if (withinError(yAngle, VisionConstants.bothCloseVisibleY)) //BLUE PATHS
{
if(withinError(xAngle, VisionConstants.farLeftVisibleX)) //A PATH
{
path = "A_BLUE";
}
if(withinError(xAngle, VisionConstants.farRightVisibleX)) //B PATH
{
path = "B_BLUE";
}
}
else // RED PATHS
{
if(withinError(yAngle, VisionConstants.closeLeftVisibleY)) //A PATH
{
path = "A_RED";
}
if(withinError(yAngle, VisionConstants.closeRightVisibleY)) //B PATH
{
path = "B_RED";
}
}
}
public boolean withinError(double angle, double input)
{
if(input > (angle - VisionConstants.searchError) && input < (angle + VisionConstants.searchError))
{
return true;
}
else
{
return false;
}
}
// Called once the command ends or is interrupted.
@Override
public void end(boolean interrupted) {
}
// Returns true when the command should end.
@Override
public boolean isFinished() {
if (path != "")
{
SmartDashboard.putString("GalacticSearchPath", path);
m_limeLight.galacticSearchPath = path;
return true;
}
return false;
}
}