Skip to content

Commit

Permalink
Task 3 Completion
Browse files Browse the repository at this point in the history
  • Loading branch information
Wardah Saeed committed Oct 24, 2024
1 parent 5c50427 commit 6a14137
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/main/java/frc/robot/RobotContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public RobotContainer() {
//It uses lambdas to make the parameters suppliers, which means that instead of them being constant, they rerun each time the command is scheduled.
//The values are negated because the axes are flipped for some reason.
// m_xrpDrivetrain.setDefaultCommand(DriveCommands.arcadeDriveCommand(()-> -m_controller.getLeftY(), () -> -m_controller.getRightX()));
//TODO: Task 4-Comment out the above line by adding // to the left of it. Then, set the default command to be your tankDriveCommand.
// TODO: Task 4-Comment out the above line by adding // to the left of it. Then, set the default command to be your tankDriveCommand.
//HINT: In tank drive, the left wheel is controlled by the y axis of the left joystick and the y axis of the right joystick.
m_xrpDrivetrain.setDefaultCommand(DriveCommands.tankDriveCommand(()-> -m_controller.getLeftY(), () -> -m_controller.getRightY()));
}
Expand Down
25 changes: 5 additions & 20 deletions src/main/java/frc/robot/commands/DriveCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,17 @@ public static Command driveDistance(double distance){
//The first parameter is what happens upon initialization of the command, aka what should prepare the robot for the command to occur.
//Causes the XRP to stop to prepare for movement, and resets the sensors that detect how much the wheels have turned.
() -> {
RobotContainer.m_xrpDrivetrain.arcadeDrive(0, 0);
RobotContainer.m_xrpDrivetrain.tankDrive(0, 0);
RobotContainer.m_xrpDrivetrain.resetEncoders();
},

//The second parameter is what is called every time the scheduler runs while the command is scheduled., aka what the main portion of the command is.
//Causes the XRP to drive.
() -> RobotContainer.m_xrpDrivetrain.arcadeDrive(1, 0),
() -> RobotContainer.m_xrpDrivetrain.tankDrive(1, 0),

//The third parameter is what happens upon ending the command.
//Causes the XRP to stop.
interrupted -> RobotContainer.m_xrpDrivetrain.arcadeDrive(0, 0),
interrupted -> RobotContainer.m_xrpDrivetrain.tankDrive(0, 0),

//The fourth parameter is the boolean that determines if the command ended.
//Checks if the average distance traveled by both of the wheels is at least the distance the XRP needs to travel.
Expand Down Expand Up @@ -134,13 +134,13 @@ public boolean isFinished() {
* @param turnSpeed Speed the robot turns. Is a supplier, and therefore must be a method or a lambda.
* @return Command to arcade drive the XRP
*/
public static Command arcadeDriveCommand(Supplier<Double> forwardSpeed, Supplier<Double> turnSpeed){
public static Command tankDriveCommand(Supplier<Double> leftspeed, Supplier<Double> rightspeed){
//This uses an InstantCommand, which shouldn't be a class. An Instant Command immediately executes, and only takes in fields for what it should do
//and the required subsystems.
//Useful for simple commands.
return new InstantCommand(
//Tells the XRP to drive at the given speeds by using .get(), which gets the value returned by the supplier
()->RobotContainer.m_xrpDrivetrain.arcadeDrive(forwardSpeed.get(), turnSpeed.get()),
()->RobotContainer.m_xrpDrivetrain.tankDrive(leftspeed.get(), rightspeed.get()),
RobotContainer.m_xrpDrivetrain
);
}
Expand Down Expand Up @@ -222,21 +222,6 @@ public static Command turnDegrees(double degrees, double speed) {
//driveDistance or AltDriveDistance(choose 1)
//arcadeDriveCommand(rename as tankDriveCommand)
//Bonus(optional):TurnDegrees(either class or function, choose 1)
public static class AltDriveDistance extends Command {
private double distance;
RobotContainer.m_xrpDrivetrain.tankDrive();
public AltDriveDistance(double distance) {
addRequirements(RobotContainer.m_xrpDrivetrain);
}
}

public static Command tankDriveCommand(Supplier<Double> leftspeed, Supplier<Double> rightspeed){
return new InstantCommand(
//Tells the XRP to drive at the given speeds by using .get(), which gets the value returned by the supplier
()->RobotContainer.m_xrpDrivetrain.tankDrive(leftspeed.get(), rightspeed.get()),
RobotContainer.m_xrpDrivetrain
);
}


/**
Expand Down

0 comments on commit 6a14137

Please sign in to comment.