Skip to content

Commit

Permalink
Task 3 Completion
Browse files Browse the repository at this point in the history
  • Loading branch information
PriyanshuK-ACL committed Oct 22, 2024
1 parent 13ae719 commit 593c01c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
28 changes: 25 additions & 3 deletions src/main/java/frc/robot/commands/DriveCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,26 @@ public static Command arcadeDriveCommand(Supplier<Double> forwardSpeed, Supplier
);
}

/**
* A command that sets the speed of the robot based on an arcade control scheme, using an Instant Command.
* Because this value is something that changes based on controller input, we want the values to be rechecked periodically.
* For this, we use what is called a supplier, which is any function which returns a double.
* By using a supplier, instead of the drive speed being a constant 0, the command instead runs the supplier each time it runs to determine the correct speed.
* @param forwardSpeed Speed the robot goes forward. Is a supplier, and therefore must be a method or a lambda.
* @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 tankDriveCommand(Supplier<Double> forwardSpeed, Supplier<Double> turnSpeed){
//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
);
}

public static class TurnDegrees extends Command {
private final double m_degrees;
private final double m_speed;
Expand Down Expand Up @@ -213,9 +233,11 @@ public static Command TurnDegrees (double m_degrees, double m_speed){
//driveDistance or AltDriveDistance(choose 1)
//arcadeDriveCommand(rename as tankDriveCommand)
//Bonus(optional):TurnDegrees(either class or function, choose 1)
//public static Command AltDriveDistance (double distance){

// }
public static Command driveDistance1(double m_distance){
return driveDistance{m_distance};
}





Expand Down
3 changes: 3 additions & 0 deletions src/main/java/frc/robot/subsystems/XRPDrivetrain.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public XRPDrivetrain() {
m_rightMotor.setInverted(true);
}



public void arcadeDrive(double xaxisSpeed, double zaxisRotate) {
m_diffDrive.arcadeDrive(xaxisSpeed, zaxisRotate);
}
Expand All @@ -50,6 +52,7 @@ public void arcadeDrive(double xaxisSpeed, double zaxisRotate) {
//HINT:To see all the functions that the drivetrain has, type "m_diffDrive." without the quotes and look at the options generated by auto complete.
public void tankDriveCommand(double m_leftMotor, double m_rightMotor){
m_diffDrive.tankDrive(m_leftMotor, m_rightMotor);

}

public void resetEncoders() {
Expand Down

0 comments on commit 593c01c

Please sign in to comment.