2025-07-11 14:07:53 -06:00
|
|
|
package frc4388.robot.commands.alignment;
|
2025-03-06 19:55:26 -07:00
|
|
|
|
|
|
|
|
import edu.wpi.first.math.geometry.Translation2d;
|
|
|
|
|
import edu.wpi.first.wpilibj2.command.Command;
|
|
|
|
|
import frc4388.robot.subsystems.Lidar;
|
|
|
|
|
import frc4388.robot.subsystems.SwerveDrive;
|
|
|
|
|
|
|
|
|
|
// Command to repeat a joystick movement for a specific time.
|
|
|
|
|
public class DriveUntilLiDAR extends Command {
|
|
|
|
|
private final SwerveDrive swerveDrive;
|
|
|
|
|
private final Translation2d leftStick;
|
|
|
|
|
private final Translation2d rightStick;
|
|
|
|
|
private final Lidar m_lidar;
|
|
|
|
|
private final double mindistance;
|
|
|
|
|
|
|
|
|
|
public DriveUntilLiDAR(
|
|
|
|
|
SwerveDrive swerveDrive,
|
|
|
|
|
Translation2d leftStick,
|
|
|
|
|
Translation2d rightStick,
|
|
|
|
|
Lidar lidar,
|
2025-07-11 14:07:53 -06:00
|
|
|
double mindistance) {
|
2025-03-06 19:55:26 -07:00
|
|
|
addRequirements(swerveDrive);
|
|
|
|
|
|
|
|
|
|
this.swerveDrive = swerveDrive;
|
|
|
|
|
this.leftStick = leftStick;
|
|
|
|
|
this.rightStick = rightStick;
|
|
|
|
|
this.m_lidar = lidar;
|
|
|
|
|
this.mindistance = mindistance;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void initialize() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void execute() {
|
2025-03-13 20:17:11 -06:00
|
|
|
swerveDrive.driveFine(leftStick, rightStick, 0.3);
|
2025-03-06 19:55:26 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean isFinished() {
|
2025-03-18 11:02:39 -06:00
|
|
|
if (Math.abs(m_lidar.getDistance()) < mindistance) {
|
|
|
|
|
swerveDrive.softStop();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
2025-03-06 19:55:26 -07:00
|
|
|
}
|
|
|
|
|
}
|