2022-02-17 19:54:24 -07: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;
|
|
|
|
|
|
|
|
|
|
import edu.wpi.first.wpilibj2.command.CommandBase;
|
2022-02-24 19:32:33 -07:00
|
|
|
import frc4388.robot.Constants.ShooterConstants;
|
2022-02-19 11:05:44 -07:00
|
|
|
import frc4388.robot.subsystems.SwerveDrive;
|
|
|
|
|
import frc4388.robot.subsystems.Turret;
|
2022-02-17 19:54:24 -07:00
|
|
|
|
2022-02-19 11:05:44 -07:00
|
|
|
public class AimToCenter extends CommandBase {
|
2022-02-17 19:54:24 -07:00
|
|
|
/** Creates a new AimWithOdometry. */
|
2022-02-19 11:05:44 -07:00
|
|
|
Turret m_turret;
|
|
|
|
|
SwerveDrive m_drive;
|
|
|
|
|
|
|
|
|
|
// use odometry to find x and y later
|
|
|
|
|
double x = 0;
|
|
|
|
|
double y = 0;
|
|
|
|
|
double m_targetAngle;
|
2022-02-24 18:12:57 -07:00
|
|
|
|
2022-02-19 11:05:44 -07:00
|
|
|
// public static Gains m_aimGains;
|
|
|
|
|
|
|
|
|
|
public AimToCenter(Turret turret, SwerveDrive drive) {
|
2022-02-17 19:54:24 -07:00
|
|
|
// Use addRequirements() here to declare subsystem dependencies.
|
2022-02-19 11:05:44 -07:00
|
|
|
m_turret = turret;
|
|
|
|
|
m_drive = drive;
|
|
|
|
|
addRequirements(m_turret, m_drive);
|
2022-02-17 19:54:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Called when the command is initially scheduled.
|
|
|
|
|
@Override
|
2022-02-19 11:05:44 -07:00
|
|
|
public void initialize() {
|
|
|
|
|
}
|
2022-02-17 19:54:24 -07:00
|
|
|
|
|
|
|
|
// Called every time the scheduler runs while the command is scheduled.
|
|
|
|
|
@Override
|
|
|
|
|
public void execute() {
|
2022-02-19 15:05:49 -07:00
|
|
|
if (x > 0) {
|
2022-02-24 18:12:57 -07:00
|
|
|
m_targetAngle = 180 + Math.atan(y / x) - m_drive.gyro.getAngle();
|
|
|
|
|
}
|
2022-02-24 19:26:58 -07:00
|
|
|
else if (x < 0) {
|
2022-02-24 18:12:57 -07:00
|
|
|
m_targetAngle = 360 + Math.atan(y / x) - m_drive.gyro.getAngle();
|
|
|
|
|
}
|
2022-02-24 19:26:58 -07:00
|
|
|
else if (x == 0 && y > 0) {
|
2022-02-24 18:12:57 -07:00
|
|
|
m_targetAngle = 270 - m_drive.gyro.getAngle();
|
2022-02-19 15:05:49 -07:00
|
|
|
}
|
2022-02-24 19:26:58 -07:00
|
|
|
else if (x == 0 && y < 0) {
|
2022-02-19 15:05:49 -07:00
|
|
|
m_targetAngle = 90 - m_drive.gyro.getAngle();
|
|
|
|
|
}
|
2022-02-24 18:12:57 -07:00
|
|
|
|
2022-02-19 13:32:39 -07:00
|
|
|
m_turret.runshooterRotatePID(m_targetAngle);
|
2022-02-22 17:14:48 -07:00
|
|
|
|
|
|
|
|
}
|
2022-02-24 18:12:57 -07:00
|
|
|
|
|
|
|
|
public boolean isDeadzone() {
|
2022-02-24 19:32:33 -07:00
|
|
|
if ((ShooterConstants.DEADZONE_LEFT < m_targetAngle) && (m_targetAngle < ShooterConstants.DEADZONE_RIGHT)) {
|
2022-02-24 18:12:57 -07:00
|
|
|
return true;
|
2022-02-22 17:14:48 -07:00
|
|
|
} else {
|
2022-02-24 18:12:57 -07:00
|
|
|
return false;
|
2022-02-22 17:14:48 -07:00
|
|
|
}
|
2022-02-19 11:05:44 -07:00
|
|
|
}
|
2022-02-24 18:12:57 -07:00
|
|
|
|
2022-02-17 19:54:24 -07:00
|
|
|
// Called once the command ends or is interrupted.
|
|
|
|
|
@Override
|
2022-02-24 18:12:57 -07:00
|
|
|
public void end(boolean interrupted) {
|
|
|
|
|
}
|
2022-02-17 19:54:24 -07:00
|
|
|
|
|
|
|
|
// Returns true when the command should end.
|
|
|
|
|
@Override
|
|
|
|
|
public boolean isFinished() {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|