Skip to content

Commit

Permalink
tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
Advay17 committed Sep 3, 2024
1 parent dd42649 commit db9e86c
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 10 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id "java"
id "edu.wpi.first.GradleRIO" version "2024.1.1"
id "edu.wpi.first.GradleRIO" version "2024.3.2"
}

java {
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/frc/robot/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@
* <p>It is advised to statically import this class (or one of its inner classes) wherever the
* constants are needed, to reduce verbosity.
*/
public final class Constants {}
public final class Constants {
public static double[] servoPresets={20, 90, 10, 50};
}
17 changes: 16 additions & 1 deletion src/main/java/frc/robot/RobotContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@
package frc.robot;

import edu.wpi.first.wpilibj.XboxController;
import frc.robot.commands.DriveCommands;
import frc.robot.subsystems.Servo;
import frc.robot.subsystems.XRPDrivetrain;
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.button.CommandJoystick;
import edu.wpi.first.wpilibj2.command.button.CommandXboxController;
import edu.wpi.first.wpilibj2.command.button.Trigger;

/**
* This class is where the bulk of the robot should be declared. Since Command-based is a
Expand All @@ -17,12 +22,16 @@
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();
private final CommandXboxController m_controller = new CommandXboxController(0);



/** The container for the robot. Contains subsystems, OI devices, and commands. */
public RobotContainer() {
// Configure the button bindings
configureButtonBindings();
m_xrpDrivetrain.setDefaultCommand(DriveCommands.arcadeDriveCommand(m_controller.getLeftY(), m_controller.getRightX()));
}

/**
Expand All @@ -31,7 +40,13 @@ public RobotContainer() {
* edu.wpi.first.wpilibj.Joystick} or {@link XboxController}), and then passing it to a {@link
* edu.wpi.first.wpilibj2.command.button.JoystickButton}.
*/
private void configureButtonBindings() {}
private void configureButtonBindings() {
//TODO:Task 4-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);
}

/**
* Use this to pass the autonomous command to the main {@link Robot} class.
Expand Down
18 changes: 12 additions & 6 deletions src/main/java/frc/robot/commands/DriveCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class DriveCommands {
* @param distance Distance that the XRP drives in inches
* @return Command that causes the XRP to execute the functions below
*/
public Command driveDistance(double distance){
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.
return new FunctionalCommand(
/*
Expand Down Expand Up @@ -63,7 +63,7 @@ public Command driveDistance(double distance){
* Usage is basically the same, however add new in front of the function call.
* Example: new DriveCommands.AltDriveDistance(5)
*/
public class AltDriveDistance extends Command{
public static class AltDriveDistance extends Command{
/**
* Distance in inches the command makes the XRP move.
*/
Expand Down Expand Up @@ -125,7 +125,7 @@ public boolean isFinished() {
* @param turnSpeed Speed the robot turns.
* @return Command to arcade drive the XRP
*/
public Command arcadeDriveCommand(double forwardSpeed, double turnSpeed){
public static Command arcadeDriveCommand(double forwardSpeed, 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.
Expand All @@ -136,7 +136,7 @@ public Command arcadeDriveCommand(double forwardSpeed, double turnSpeed){
);
}

public class TurnDegrees extends Command {
public static class TurnDegrees extends Command {
private final double m_degrees;
private final double m_speed;
private final XRPDrivetrain m_drive;
Expand Down Expand Up @@ -204,11 +204,17 @@ private double getAverageTurningDistance() {
* Commands can also be sequential, which is where they execute one after another. This is really good for automatic behavior.
* @return A command that drives forward 5 inches, turns 90 degrees, and drives forward 4 inches.
*/
public Command sequentialExampleCommand(){
public static Command sequentialExampleCommand(){
return new SequentialCommandGroup(
driveDistance(5),
new TurnDegrees(1, 90),
new DriveCommands.TurnDegrees(1, 90),
driveDistance(4)
);
}

//TODO: Task 6-Write a Command(function or class) that causes the XRP to drive until the distance returned by the rangefinder
//is less than 2 inches.

//TODO: Task 7-Write a Sequential Command Group to move the XRP backwards 2 inches, set the arm preset to index 1, spin the XRP 360 degrees
//and move the XRP forward 3 inches.
}
7 changes: 7 additions & 0 deletions src/main/java/frc/robot/commands/ServoCommands.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package frc.robot.commands;

public class ServoCommands {
//TODO: Task 3-Write commands to move the servo up, down, and to a specific preset by taking
//in one value for which preset to select.
//The presets are in the constants file.
}
11 changes: 11 additions & 0 deletions src/main/java/frc/robot/subsystems/Rangefinder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package frc.robot.subsystems;

import edu.wpi.first.wpilibj.xrp.XRPRangefinder;

public class Rangefinder {
private final XRPRangefinder rangefinder;
public Rangefinder(){
rangefinder=new XRPRangefinder();
}
//TODO:Task 4-Write a method to get the distance returned by the sensor in inches
}
7 changes: 6 additions & 1 deletion src/main/java/frc/robot/subsystems/Servo.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package frc.robot.subsystems;

import edu.wpi.first.wpilibj.xrp.XRPServo;
import edu.wpi.first.wpilibj2.command.SubsystemBase;

public class Servo extends SubsystemBase {
private final XRPServo m_armServo;
public Servo(){

// Device number 4 maps to the physical Servo 1 port on the XRP
m_armServo = new XRPServo(4);
}
//TODO:Task 2-Write functions to control the arm. You should be able to set the arm's angle and get the angle
//it is at.
}

0 comments on commit db9e86c

Please sign in to comment.