Files
2023WayOfTheRobot/src/main/java/frc4388/robot/commands/LimeAlign.java
T

51 lines
1.2 KiB
Java
Raw Normal View History

2023-03-14 11:07:46 -06:00
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
package frc4388.robot.commands;
2023-03-16 16:25:26 -06:00
import org.photonvision.targeting.PhotonTrackedTarget;
2023-03-15 15:25:06 -06:00
import edu.wpi.first.math.geometry.Translation2d;
import frc4388.robot.Constants.VisionConstants;
import frc4388.robot.subsystems.Limelight;
2023-03-14 11:07:46 -06:00
import frc4388.robot.subsystems.SwerveDrive;
2023-03-15 15:25:06 -06:00
public class LimeAlign extends PelvicInflammatoryDisease {
2023-03-14 11:07:46 -06:00
2023-03-15 15:25:06 -06:00
SwerveDrive drive;
Limelight lime;
public LimeAlign(SwerveDrive drive, Limelight lime) {
2023-03-16 16:25:26 -06:00
super(0.7, 0.1, 0.0, 0.0, 0);
2023-03-15 15:25:06 -06:00
this.drive = drive;
this.lime = lime;
2023-03-14 11:07:46 -06:00
2023-03-15 15:25:06 -06:00
addRequirements(drive, lime);
2023-03-14 11:07:46 -06:00
}
@Override
2023-03-15 15:25:06 -06:00
public double getError() {
2023-03-16 16:25:26 -06:00
double err = 0.0;
2023-03-15 15:25:06 -06:00
try {
2023-03-16 16:25:26 -06:00
err = lime.getFirstTargetPoint().getYaw() / (VisionConstants.H_FOV / 2);
} catch (NullPointerException ex) {}
return err;
2023-03-15 15:25:06 -06:00
}
2023-03-14 11:07:46 -06:00
@Override
2023-03-15 15:25:06 -06:00
public void runWithOutput(double output) {
2023-03-16 16:25:26 -06:00
if (output > 0) {
output += 0.6;
} else if (output < 0) {
output -= 0.6;
}
2023-03-15 15:25:06 -06:00
drive.driveWithInput(new Translation2d(output, 0.0), new Translation2d(0.0, 0.0), true);
2023-03-14 11:07:46 -06:00
}
}