diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..45c4356 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,34 @@ +# This is a basic workflow to build robot code. + +name: CI + +# Controls when the action will run. Triggers the workflow on push or pull request +# events but only for the main branch. +on: [push, pull_request] + +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + # This workflow contains a single job called "build" + build: + # The type of runner that the job will run on + runs-on: ubuntu-latest + + # This grabs the WPILib docker container + container: wpilib/roborio-cross-ubuntu:2024-22.04 + + # Steps represent a sequence of tasks that will be executed as part of the job + steps: + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it + - uses: actions/checkout@v4 + + # Declares the repository safe and not under dubious ownership. + - name: Add repository to git safe directories + run: git config --global --add safe.directory $GITHUB_WORKSPACE + + # Grant execute permission for gradlew + - name: Grant execute permission for gradlew + run: chmod +x gradlew + + # Runs a single command using the runners shell + - name: Compile and run tests on robot code + run: ./gradlew build diff --git a/README.md b/README.md new file mode 100644 index 0000000..a9edf57 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +A template file containing tasks for programming the XRP Robot in WPILib Java. diff --git a/src/main/java/frc/robot/RobotContainer.java b/src/main/java/frc/robot/RobotContainer.java index 66b7d66..232bff6 100644 --- a/src/main/java/frc/robot/RobotContainer.java +++ b/src/main/java/frc/robot/RobotContainer.java @@ -6,9 +6,12 @@ import edu.wpi.first.wpilibj.XboxController; import frc.robot.commands.DriveCommands; +import frc.robot.commands.ServoCommands; +import frc.robot.subsystems.Rangefinder; import frc.robot.subsystems.Servo; import frc.robot.subsystems.XRPDrivetrain; import edu.wpi.first.wpilibj2.command.Command; +import edu.wpi.first.wpilibj2.command.RepeatCommand; import edu.wpi.first.wpilibj2.command.button.CommandXboxController; import edu.wpi.first.wpilibj2.command.button.Trigger; @@ -22,6 +25,7 @@ public class RobotContainer { // The robot's subsystems and commands are defined here... public static final XRPDrivetrain m_xrpDrivetrain = new XRPDrivetrain(); public static final Servo m_servo = new Servo(); + public static final Rangefinder m_rangefinder = new Rangefinder(); public final CommandXboxController m_controller = new CommandXboxController(0); @@ -48,8 +52,12 @@ public RobotContainer() { private void configureButtonBindings() { //TODO: Task 7-Uncomment the lines below and replace the null values with the commands you created to move the servo up and down, such that the y button moves it up //and the a button moves it down. - // m_controller.y().whileTrue(null); - // m_controller.a().whileTrue(null); + //BONUS:Complete one of the following: Look into all of the different types of commands in the documentation for WPILib. Try to find a command that does not need to be encapsulated + //in a RepeatCommand to repeat, and replace the type of moveServoUp and moveServoDown(or whatever they are called) with that type of Command. + //Then, delete the RepeatCommand, because your command should already repeat. + + // m_controller.y().whileTrue(new RepeatCommand(null)); + // m_controller.a().whileTrue(new RepeatCommand(null)); } /** @@ -58,7 +66,7 @@ private void configureButtonBindings() { * @return the command to run in autonomous */ public Command getAutonomousCommand() { - // An ExampleCommand will run in autonomous + // The following command will run during autonomous return null; } } diff --git a/src/main/java/frc/robot/commands/DriveCommands.java b/src/main/java/frc/robot/commands/DriveCommands.java index db32b89..e369414 100644 --- a/src/main/java/frc/robot/commands/DriveCommands.java +++ b/src/main/java/frc/robot/commands/DriveCommands.java @@ -25,7 +25,7 @@ public class DriveCommands { * @return Command that causes the XRP to execute the functions below */ public static Command driveDistance(double distance){ - //A functional command is returned. A functional command is a basic command with parameters for initialization code, execution code, ending code, a boolean supplier to cause the command to end, and required subsystems. + //A functional command is returned. A functional command is a basic command with a constructor with parameters for initialization code, execution code, ending code, a boolean supplier to cause the command to end, and required subsystems. return new FunctionalCommand( /* * The arrow -> causes the code to be what is called a "lambda". This means that the code is considered to be a method without needing to define it like normal. @@ -66,6 +66,7 @@ public static Command driveDistance(double distance){ * Our team usually uses code that looks like the above command. * Usage is basically the same, however add new in front of the function call. * Example: new DriveCommands.AltDriveDistance(5) + * NOTE: Class Commands do not extend FunctionalCommand, however Function Commands do return FunctionalCommand. */ public static class AltDriveDistance extends Command{ /** @@ -191,17 +192,12 @@ has a wheel placement diameter (163 mm) - width of the wheel (8 mm) = 155 mm */ double inchPerDegree = Math.PI * 6.102 / 360; // Compare distance travelled from start to distance based on degree turn - return getAverageTurningDistance() >= (inchPerDegree * m_degrees); + return m_drive.getAverageTurningDistance() >= (inchPerDegree * m_degrees); } - private double getAverageTurningDistance() { - double leftDistance = Math.abs(m_drive.getLeftDistanceInch()); - double rightDistance = Math.abs(m_drive.getRightDistanceInch()); - return (leftDistance + rightDistance) / 2.0; - } } - //TODO: Task 1-Rewrite TurnDegrees as a function + //TODO: Task 1-Rewrite TurnDegrees as a function that returns a functional command //Code here: public static Command turnDegrees(double speed, double degrees){ @@ -222,7 +218,7 @@ public static Command turnDegrees(double speed, double degrees){ //TODO: Task 3-Rewrite the following functions to use tank drive //driveDistance or AltDriveDistance(choose 1) //arcadeDriveCommand(rename as tankDriveCommand) - //TurnDegrees(either class or function, choose 1) + //Bonus(optional):TurnDegrees(either class or function, choose 1) /** * Commands can also a part of command groups, which are sets of commands that run in certain ways. Sequential Command Groups @@ -241,7 +237,7 @@ public static Command sequentialExampleCommand(){ //TODO: Task 9-Write a Command(function or class) that causes the XRP to drive until the distance returned by the rangefinder //is less than 2 inches. Afterwards, test it by replacing the return value of getAutonomousCommand() in RobotContainer and setting it to instead return the command you wrote. - //TODO: Task 10-Write a Sequential Command Group to move the XRP backwards 2 inches, set the arm preset to index 1, spin the XRP 360 degrees + //TODO: Task 10-Write a Sequential Command Group to move the XRP backwards 2 inches(you may need to make new Commands or alter existing Commands for this), set the arm preset to index 1, spin the XRP 360 degrees //and move the XRP forward 3 inches while moving the arm to 0 degrees using a by Parallel Command group. Afterwards, test it by replacing //the return value of getAutonomousCommand() in RobotContainer and setting it to instead return the command you wrote. //HINT: Parallel Command Groups are written the same way as Sequential Command Groups. diff --git a/src/main/java/frc/robot/commands/ServoCommands.java b/src/main/java/frc/robot/commands/ServoCommands.java index 9d02334..a924e0d 100644 --- a/src/main/java/frc/robot/commands/ServoCommands.java +++ b/src/main/java/frc/robot/commands/ServoCommands.java @@ -2,6 +2,7 @@ package frc.robot.commands; public class ServoCommands { - //TODO: Task 6-Write commands to move the arm up, down, and to a specific preset by taking in an integer value for which preset to select. + //TODO: Task 6-Write commands to move the arm up, down, and to a specific preset. The latter should be done by taking in an integer input. //The presets are in the constants file. + } diff --git a/src/main/java/frc/robot/subsystems/Rangefinder.java b/src/main/java/frc/robot/subsystems/Rangefinder.java index 95d31b0..e0344ca 100644 --- a/src/main/java/frc/robot/subsystems/Rangefinder.java +++ b/src/main/java/frc/robot/subsystems/Rangefinder.java @@ -2,11 +2,13 @@ package frc.robot.subsystems; import edu.wpi.first.wpilibj.xrp.XRPRangefinder; +import edu.wpi.first.wpilibj2.command.SubsystemBase; -public class Rangefinder { - private final XRPRangefinder rangefinder; +public class Rangefinder extends SubsystemBase{ + private final XRPRangefinder m_rangefinder; public Rangefinder(){ - rangefinder=new XRPRangefinder(); + m_rangefinder=new XRPRangefinder(); } - //TODO: Task 8-Write a method to get the distance returned by the sensor in inches + //TODO: Task 8-Write a method to get the distance returned by the sensor in inches. + //HINT: Type 'm_rangefinder.' (without quotes) in a method body to see all of the different methods the rangefinder has. } diff --git a/src/main/java/frc/robot/subsystems/Servo.java b/src/main/java/frc/robot/subsystems/Servo.java index bc74941..7c7e35e 100644 --- a/src/main/java/frc/robot/subsystems/Servo.java +++ b/src/main/java/frc/robot/subsystems/Servo.java @@ -13,4 +13,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 2c119f5..1f7f69c 100644 --- a/src/main/java/frc/robot/subsystems/XRPDrivetrain.java +++ b/src/main/java/frc/robot/subsystems/XRPDrivetrain.java @@ -47,6 +47,7 @@ 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 resetEncoders() { m_leftEncoder.reset(); @@ -64,14 +65,11 @@ public double getRightDistanceInch() { public double getAverageDistanceInch() { return (getLeftDistanceInch()+getRightDistanceInch())/2; } - @Override - public void periodic() { - // This method will be called once per scheduler run - } - @Override - public void simulationPeriodic() { - // This method will be called once per scheduler run during simulation + public double getAverageTurningDistance() { + double leftDistance = Math.abs(getLeftDistanceInch()); + double rightDistance = Math.abs(getRightDistanceInch()); + return (leftDistance + rightDistance) / 2.0; } // @Override // public void periodic() {