2023-02-08 00:35:10 -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 java.io.File;
|
|
|
|
|
import java.io.FileNotFoundException;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.nio.file.Files;
|
|
|
|
|
import java.nio.file.Path;
|
|
|
|
|
import java.util.Scanner;
|
|
|
|
|
import java.util.function.Supplier;
|
|
|
|
|
|
|
|
|
|
import edu.wpi.first.math.geometry.Translation2d;
|
|
|
|
|
import edu.wpi.first.wpilibj2.command.CommandBase;
|
|
|
|
|
import frc4388.robot.subsystems.SwerveDrive;
|
|
|
|
|
import frc4388.utility.controller.DeadbandedXboxController;
|
|
|
|
|
|
|
|
|
|
public class JoystickPlayback extends CommandBase {
|
|
|
|
|
|
|
|
|
|
SwerveDrive swerve;
|
|
|
|
|
Scanner input;
|
|
|
|
|
|
|
|
|
|
/** Creates a new JoystickPlayback. */
|
|
|
|
|
public JoystickPlayback(SwerveDrive swerve) {
|
|
|
|
|
// Use addRequirements() here to declare subsystem dependencies.
|
|
|
|
|
this.swerve = swerve;
|
2023-02-10 20:53:33 -07:00
|
|
|
|
|
|
|
|
addRequirements(this.swerve);
|
2023-02-08 00:35:10 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Called when the command is initially scheduled.
|
|
|
|
|
@Override
|
|
|
|
|
public void initialize() {
|
|
|
|
|
try {
|
2023-02-10 20:53:33 -07:00
|
|
|
input = new Scanner(new File("/home/lvuser/JoystickInputs.txt"));
|
2023-02-08 00:35:10 -07:00
|
|
|
} catch (FileNotFoundException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
2023-02-10 20:53:33 -07:00
|
|
|
|
|
|
|
|
System.out.println("STARTING PLAYBACK");
|
|
|
|
|
System.out.println("STARTING PLAYBACK");
|
|
|
|
|
System.out.println("STARTING PLAYBACK");
|
|
|
|
|
System.out.println("STARTING PLAYBACK");
|
2023-02-08 00:35:10 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Called every time the scheduler runs while the command is scheduled.
|
|
|
|
|
@Override
|
|
|
|
|
public void execute() {
|
|
|
|
|
|
|
|
|
|
String line = "";
|
|
|
|
|
if (input.hasNextLine()) {
|
|
|
|
|
line = input.nextLine();
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-10 20:53:33 -07:00
|
|
|
String[] values = line.split(",");
|
2023-02-08 00:35:10 -07:00
|
|
|
|
2023-02-10 20:53:33 -07:00
|
|
|
double leftX = Double.parseDouble(values[0]);
|
|
|
|
|
double leftY = Double.parseDouble(values[1]);
|
|
|
|
|
double rightX = Double.parseDouble(values[2]);
|
|
|
|
|
double rightY = Double.parseDouble(values[3]);
|
2023-02-08 00:35:10 -07:00
|
|
|
|
|
|
|
|
this.swerve.driveWithInput(new Translation2d(leftX, leftY), new Translation2d(-rightX, rightY), true);
|
2023-02-10 20:53:33 -07:00
|
|
|
|
|
|
|
|
System.out.println("PLAYING");
|
2023-02-08 00:35:10 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Called once the command ends or is interrupted.
|
|
|
|
|
@Override
|
2023-02-10 17:33:19 -07:00
|
|
|
public void end(boolean interrupted) {
|
|
|
|
|
input.close();
|
|
|
|
|
}
|
2023-02-08 00:35:10 -07:00
|
|
|
|
|
|
|
|
// Returns true when the command should end.
|
|
|
|
|
@Override
|
|
|
|
|
public boolean isFinished() {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|