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

swerve drive docstrings #5

Merged
merged 26 commits into from
Oct 29, 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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Base robot code for all 4829 robots.

Includes code for:
Includes code for:
- Simulation
- Swerve drive
- Threaded vision
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/frc/robot/BuildConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
/** Automatically generated file containing build version information. */
public final class BuildConstants {
public static final String MAVEN_GROUP = "";
public static final String MAVEN_NAME = "4829-BaseRobotCode-2025-1";
public static final String MAVEN_NAME = "4829-BaseRobotCode-1";
public static final String VERSION = "unspecified";
public static final int GIT_REVISION = 22;
public static final String GIT_SHA = "ee746c8ba2b3fd21fde3a8e41cdd2f213deee1be";
public static final String GIT_DATE = "2024-10-27 14:01:12 EDT";
public static final String GIT_BRANCH = "k";
public static final String BUILD_DATE = "2024-10-27 14:10:44 EDT";
public static final long BUILD_UNIX_TIME = 1730052644497L;
public static final int DIRTY = 1;
public static final int GIT_REVISION = 32;
public static final String GIT_SHA = "71a47d311fd066ba3b76be8d09eff3e03b893cd8";
public static final String GIT_DATE = "2024-10-28 22:21:12 EDT";
public static final String GIT_BRANCH = "docs";
public static final String BUILD_DATE = "2024-10-29 16:56:45 EDT";
public static final long BUILD_UNIX_TIME = 1730235405242L;
public static final int DIRTY = 0;

private BuildConstants() {}
}
22 changes: 17 additions & 5 deletions src/main/java/frc/robot/Constants.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package frc.robot;

import edu.wpi.first.math.util.Units;
import frc.robot.subsystems.swerve.SwerveConstants.*;

public final class Constants {

Expand All @@ -16,14 +15,16 @@ public class LogPaths {
public static enum Mode {
/** Running on a real robot. */
REAL,

/** Running a physics simulator. */
SIM,

/** Replaying from a log file. */
REPLAY
}

/**
* This is where we place constants related to hardware on a robot that aren't specific to any
* singular subsystem.
*/
public static final class HardwareConstants {
public static final double TIMEOUT_S = 0.02;

Expand All @@ -32,18 +33,29 @@ public static final class HardwareConstants {
public static final String CANIVORE_CAN_BUS_STRING = "canivore 1";
public static final String RIO_CAN_BUS_STRING = "rio";

/**
* For some reason, falcons normally have a deadband threshold of 4%. This is incredibly high!
* It makes it very hard to do precise movements, so with this constant we set the threshold to
* the lowest possible value.
*/
public static final double MIN_FALCON_DEADBAND = 0.001;

public static final double DEADBAND_VALUE = 0.05;
}

/**
* This is where constants used to describe the game's field go. This will have the dimensions of
* the field, but also the coordinates of obstacles, game pieces, or other places of interest.
*/
public static final class FieldConstants {
// TODO: Now that I think about it, I'm pretty sure these measurements stay the same every year,
// so consider setting them in the base code
public static final double FIELD_LENGTH_METERS = Units.inchesToMeters(0 - 9);
public static final double FIELD_WIDTH_METERS = Units.inchesToMeters(0 - 9);
}

public static final class JoystickConstants {
public static final int DRIVER_JOYSTICK_ID = 0;
public static final int OPERATOR_JOYSTICK_ID = 1;

public static final double DEADBAND_VALUE = 0.05;
}
}
9 changes: 7 additions & 2 deletions src/main/java/frc/robot/commands/drive/DriveCommandBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

package frc.robot.commands.drive;

import static edu.wpi.first.units.Units.*;

import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj2.command.Command;
import frc.robot.extras.interpolators.MultiLinearInterpolator;
Expand All @@ -21,7 +19,7 @@
private final Vision vision;
private final SwerveDrive swerveDrive;

private double lastTimeStampSeconds = 0;

Check warning on line 22 in src/main/java/frc/robot/commands/drive/DriveCommandBase.java

View workflow job for this annotation

GitHub Actions / Lint

Avoid using redundant field initializer for 'lastTimeStampSeconds'

Java will initialize fields with known default values so any explicit initialization of those same defaults is redundant and results in a larger class file (approximately three additional bytecode instructions per field). RedundantFieldInitializer (Priority: 3, Ruleset: Performance) https://docs.pmd-code.org/pmd-doc-7.7.0/pmd_rules_java_performance.html#redundantfieldinitializer

Check warning on line 22 in src/main/java/frc/robot/commands/drive/DriveCommandBase.java

View workflow job for this annotation

GitHub Actions / Lint

Avoid using redundant field initializer for 'lastTimeStampSeconds'

Java will initialize fields with known default values so any explicit initialization of those same defaults is redundant and results in a larger class file (approximately three additional bytecode instructions per field). RedundantFieldInitializer (Priority: 3, Ruleset: Performance) https://docs.pmd-code.org/pmd-doc-7.7.0/pmd_rules_java_performance.html#redundantfieldinitializer

/**
* An abstract class that handles pose estimation while driving.
Expand All @@ -34,6 +32,7 @@
this.vision = vision;
// It is important that you do addRequirements(driveSubsystem, vision) in whatever
// command extends this
// DO NOT do addRequirements here, it will break things
}

@Override
Expand All @@ -55,6 +54,12 @@

double distanceFromClosestAprilTag = vision.getLimelightAprilTagDistance(limelightNumber);

// Depending on how many april tags we see, we change our confidence as more april tags
// results in a much more accurate pose estimate
// TODO: check if this is necessary anymore with MT2, also we might want to set the limelight
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check if what is necessary?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// so it only uses 1 april tag, if they set up the field wrong (they can set april tags +-1
// inch I believe)
// using multiple *could* really mess things up.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nope. see image
CAD973F1-AAA1-4D48-8738-D2BADC7D0FF4
from here.

if (vision.getNumberOfAprilTags(limelightNumber) == 1) {
double[] standardDeviations =
oneAprilTagLookupTable.getLookupValue(distanceFromClosestAprilTag);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import frc.robot.extras.simulation.field.SimulatedField;

public class OdometryTimestampsSim {
public static double[] getTimeStamps() {
public static double[] getTimestamps() {
final double[] odometryTimestamps = new double[5];
for (int i = 0; i < 5; i++)
odometryTimestamps[i] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import frc.robot.extras.simulation.gamePiece.CrescendoNoteSimulation;
import frc.robot.extras.simulation.gamePiece.GamePieceSimulation;
import frc.robot.extras.simulation.mechanismSim.IntakeSimulation;
import frc.robot.extras.simulation.mechanismSim.swervePhysicsSim.AbstractDriveTrainSimulation;
import frc.robot.extras.simulation.mechanismSim.swerve.AbstractDriveTrainSimulation;
import frc.robot.extras.util.GeomUtil;
import java.util.*;
import org.dyn4j.dynamics.Body;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import edu.wpi.first.math.geometry.Translation2d;
import frc.robot.extras.simulation.field.SimulatedField;
import frc.robot.extras.simulation.gamePiece.GamePieceSimulation;
import frc.robot.extras.simulation.mechanismSim.swervePhysicsSim.AbstractDriveTrainSimulation;
import frc.robot.extras.simulation.mechanismSim.swerve.AbstractDriveTrainSimulation;
import frc.robot.extras.util.GeomUtil;
import java.util.ArrayDeque;
import java.util.Queue;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package frc.robot.extras.simulation.mechanismSim.swervePhysicsSim;
package frc.robot.extras.simulation.mechanismSim.swerve;

import edu.wpi.first.math.geometry.Pose2d;
import edu.wpi.first.math.kinematics.ChassisSpeeds;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
// Original source:
// https://github.com/Shenzhen-Robotics-Alliance/maple-sim/blob/main/src/main/java/org/ironmaple/simulation/drivesims/BrushlessMotorSim.java

package frc.robot.extras.simulation.mechanismSim.swervePhysicsSim;
package frc.robot.extras.simulation.mechanismSim.swerve;

import edu.wpi.first.math.MathUtil;
import edu.wpi.first.math.system.plant.DCMotor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package frc.robot.extras.simulation.mechanismSim.swervePhysicsSim;
package frc.robot.extras.simulation.mechanismSim.swerve;

import static frc.robot.extras.simulation.field.SimulatedField.*;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package frc.robot.extras.simulation.mechanismSim.swervePhysicsSim;
package frc.robot.extras.simulation.mechanismSim.swerve;

import edu.wpi.first.math.geometry.Pose2d;
import edu.wpi.first.math.geometry.Rotation2d;
Expand Down
Loading
Loading