Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Javadoc everything #18

Merged
merged 7 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/main/java/frc/robot/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@
* constants are needed, to reduce verbosity.
*/
public final class Constants {

/** Constants that are relating to the controllers. */
public static class Controllers {

/** Driver station port number for the drive controller. */
public static final int DRIVER_CONTROLLER_PORT = 0;
}

Expand Down
1 change: 1 addition & 0 deletions src/main/java/frc/robot/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import edu.wpi.first.wpilibj.RobotBase;

/* Probably don't put code here, most likely put it in RobotContainer. */
public final class Main {
private Main() {}

Expand Down
1 change: 1 addition & 0 deletions src/main/java/frc/robot/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.CommandScheduler;

/* Don't put code here, most likely put it in RobotContainer. */
public class Robot extends TimedRobot {
private Command autonomousCommand;

Expand Down
51 changes: 50 additions & 1 deletion src/main/java/frc/robot/RobotContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import frc.robot.commands.EnterXMode;
import frc.robot.subsystems.Drive;

/** Singleton class that contains all the robot's subsystems, commands, and button bindings. */
public class RobotContainer {

/*
Expand All @@ -32,6 +33,7 @@ public class RobotContainer {
* injecting a dependency through six or seven commands in a chain of command groups would be
* awful.
*/
/** Singleton instance of {@link Drive} */
public static Drive drive = new Drive();

/*
Expand All @@ -54,9 +56,11 @@ public class RobotContainer {
/* The CommandXboxController instance must be static to allow the getter methods for its axes
* to work.
*/
/** Xbox controller for the driver. */
public static CommandXboxController driverController =
new CommandXboxController(Constants.Controllers.DRIVER_CONTROLLER_PORT);

/** Constructor for {@link RobotContainer} */
public RobotContainer() {
configureBindings();

Expand All @@ -69,43 +73,88 @@ private void configureBindings() {
driverController.x().onTrue(enterXMode);
}

/**
* Gets the current autonomous command.
*
* @return The current autonomous command.
*/
public Command getAutonomousCommand() {
return Commands.print("No autonomous command configured");
}

public static double scaleAxis(double axis) {
private static double scaleAxis(double axis) {
double deadbanded = MathUtil.applyDeadband(axis, 0.1);
return Math.pow(deadbanded, 3);
}

/**
* Gets x-axis of left stick of driver controller.
*
* @return x-axis of left stick of driver controller.
*/
public static double getControllerLeftXAxis() {
return driverController.getLeftX();
}

/**
* Gets scaled x-axis of left stick of driver controller.
*
* @return scaled x-axis of left stick of driver controller.
*/
public static double getScaledControllerLeftXAxis() {
return scaleAxis(getControllerLeftXAxis());
}

/**
* Gets y-axis of left stick of driver controller.
*
* @return y-axis of left stick of driver controller.
*/
public static double getControllerLeftYAxis() {
return driverController.getLeftY();
}

/**
* Gets scaled y-axis of left stick of driver controller.
*
* @return scaled y-axis of left stick of driver controller.
*/
public static double getScaledControllerLeftYAxis() {
return scaleAxis(getControllerLeftYAxis());
}

/**
* Gets x-axis of right stick of driver controller.
*
* @return x-axis of right stick of driver controller.
*/
public static double getControllerRightXAxis() {
return driverController.getRightX();
}

/**
* Gets scaled x-axis of right stick of driver controller.
*
* @return scaled x-axis of right stick of driver controller.
*/
public static double getScaledControllerRightXAxis() {
return scaleAxis(getControllerRightXAxis());
}

/**
* Gets y-axis of right stick of driver controller.
*
* @return y-axis of right stick of driver controller.
*/
public static double getControllerRightYAxis() {
return driverController.getRightY();
}

/**
* Gets scaled y-axis of right stick of driver controller.
*
* @return scaled y-axis of right stick of driver controller.
*/
public static double getScaledControllerRightYAxis() {
return scaleAxis(getControllerRightYAxis());
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/frc/robot/commands/DriveFieldOriented.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import frc.robot.RobotContainer;
import frc.robot.subsystems.Drive;

/** Drives the robot in field-oriented mode. */
public class DriveFieldOriented extends Command {
private final Drive drive;

Expand Down
1 change: 1 addition & 0 deletions src/main/java/frc/robot/commands/DriveRobotOriented.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import frc.robot.RobotContainer;
import frc.robot.subsystems.Drive;

/** Drives the robot in robot-oriented mode. Default command for {@link Drive} subsystem. */
public class DriveRobotOriented extends Command {
private final Drive drive;

Expand Down
1 change: 1 addition & 0 deletions src/main/java/frc/robot/commands/EnterXMode.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import frc.robot.RobotContainer;
import frc.robot.subsystems.Drive;

/** Points the wheels toward the inside and stops the wheels from moving in any direction. */
public class EnterXMode extends Command {

private Drive drive;
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/frc/robot/subsystems/Drive.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import swervelib.SwerveDrive;
import swervelib.parser.SwerveParser;

/** The subsystem that represents the drivetrain. */
public class Drive extends SubsystemBase {
private SwerveDrive drive;

Expand All @@ -41,6 +42,14 @@ public Drive() {
drive.setMotorIdleMode(true);
}

/**
* Drives the robot in robot-oriented mode.
*
* @param x Robot velocity left to right in m/s. Left is positive.
* @param y Robot velocity forward and backward in m/s. Forward is positive.
* @param z Robot angular velocity around the z-axis in radians per second. Counter-clockwise is
* positive.
*/
public void driveRobotOriented(double x, double y, double z) {
x = x * getMaximumSpeed();
y = y * getMaximumSpeed();
Expand All @@ -50,6 +59,15 @@ public void driveRobotOriented(double x, double y, double z) {
drive.drive(translation, z, false, false);
}

/**
* Drives the robot in field-oriented mode.
*
* @param x Robot velocity left to right in m/s. Left is positive. Relative to the field.
* @param y Robot velocity forward and backward in m/s. Toward the opposing alliance wall is
* positive.
* @param z Robot angular velocity around the z-axis in radians per second. Counter-clockwise is
* positive.
*/
public void driveFieldOriented(double x, double y, double z) {
x = x * getMaximumSpeed();
y = y * getMaximumSpeed();
Expand All @@ -59,11 +77,13 @@ public void driveFieldOriented(double x, double y, double z) {
drive.drive(translation, z, true, false);
}

/** Stops all motors in the subsystem. */
public void stop() {
drive.drive(
Constants.Drive.EMPTY_TRANSLATION, 0, false, false, Constants.Drive.EMPTY_TRANSLATION);
}

/** Points the wheels toward the inside and stops the wheels from moving in any direction. */
public void enterXMode() {
drive.lockPose();
}
Expand All @@ -76,6 +96,7 @@ private double getMaximumAngularSpeed() {
return Constants.Drive.MAX_ANGULAR_SPEED;
}

/** Runs every scheduler run. */
@Override
public void periodic() {
// This method will be called once per scheduler run
Expand Down
Loading