Skip to content

Commit

Permalink
Task 2 Completion
Browse files Browse the repository at this point in the history
  • Loading branch information
Wardah Saeed committed Oct 24, 2024
1 parent ac976dc commit cfdc926
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/main/java/frc/robot/RobotContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ public RobotContainer() {
//This causes the xrp to drive based on the left joystick y and right joystick x of the controller by default.
//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()));
// 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.
//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
17 changes: 16 additions & 1 deletion src/main/java/frc/robot/commands/DriveCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,23 @@ 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
);



/**
* Commands can also a part of command groups, which are sets of commands that run in certain ways. Sequential Command Groups
* are commands that execute one after another. This is useful for auto behavior.
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/frc/robot/subsystems/Servo.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ public Servo(){
//TODO: Task 5-Write functions to control the arm. You should be able to set the arm's angle and get the angle
//it is at.
//HINT: Type 'm_armServo.' (without quotes) in a method body to see all of the different methods the servo has.
}

}
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 @@ -48,6 +48,9 @@ public void arcadeDrive(double xaxisSpeed, double zaxisRotate) {
//TODO:Task 2-Write a function that makes the robot take in a left wheel speed and a right wheel speed, and move at those speeds.
//HINT:This is called a tank drive, maybe there is a function that can easily allow for it?
//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 tankDrive(double leftspeed, double rightspeed) {
m_diffDrive.tankDrive(leftspeed, rightspeed);
}

public void resetEncoders() {
m_leftEncoder.reset();
Expand Down

0 comments on commit cfdc926

Please sign in to comment.