diff --git a/src/main/java/frc/robot/RobotContainer.java b/src/main/java/frc/robot/RobotContainer.java index 232bff6..e53805e 100644 --- a/src/main/java/frc/robot/RobotContainer.java +++ b/src/main/java/frc/robot/RobotContainer.java @@ -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())); } /** diff --git a/src/main/java/frc/robot/commands/DriveCommands.java b/src/main/java/frc/robot/commands/DriveCommands.java index 2167b1f..e246bae 100644 --- a/src/main/java/frc/robot/commands/DriveCommands.java +++ b/src/main/java/frc/robot/commands/DriveCommands.java @@ -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 leftspeed, Supplier 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. diff --git a/src/main/java/frc/robot/subsystems/Servo.java b/src/main/java/frc/robot/subsystems/Servo.java index 7c7e35e..8bd4bdb 100644 --- a/src/main/java/frc/robot/subsystems/Servo.java +++ b/src/main/java/frc/robot/subsystems/Servo.java @@ -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. -} + +} diff --git a/src/main/java/frc/robot/subsystems/XRPDrivetrain.java b/src/main/java/frc/robot/subsystems/XRPDrivetrain.java index 1f7f69c..2298c14 100644 --- a/src/main/java/frc/robot/subsystems/XRPDrivetrain.java +++ b/src/main/java/frc/robot/subsystems/XRPDrivetrain.java @@ -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();