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

Constants #19

Merged
merged 6 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
Empty file modified gradlew
100644 → 100755
Empty file.
8 changes: 8 additions & 0 deletions src/main/java/frc/robot/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

package frc.robot;

import static java.lang.Math.PI;

/**
* The Constants class provides a convenient place for teams to hold robot-wide numerical or boolean
* constants. This class should not be used for any other purpose. All constants should be declared
Expand All @@ -23,6 +25,12 @@
*/
public final class Constants {
public static final Mode currentMode = Mode.SIM;
// *START OF CONSTANTS FOR SWERVE* (STILL MISSING WHEEL POSITIONS - Im not on the cad thingy so i
// cant see it)
double WHEEL_RADIUS = 0.0508;
gspamula marked this conversation as resolved.
Show resolved Hide resolved
double WHEEL_CIRCUMFERENCE = WHEEL_RADIUS * 2 * PI;
double DRIVE_GEAR_RATIO = 6.75;
double STEERING_RATIO = (150 / 7);
Copy link
Collaborator

Choose a reason for hiding this comment

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

where are these used?

Copy link
Collaborator

Choose a reason for hiding this comment

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

may want to remove them or comment them out if we don't use them.


public static enum Mode {
/** Running on a real robot. */
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/frc/robot/RobotContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public RobotContainer() {
// Real robot, instantiate hardware IO implementations
drive =
new Drive(
new GyroIOPigeon2(),
new GyroIOPigeon2(),
new ModuleIOSparkMax(0),
new ModuleIOSparkMax(1),
new ModuleIOSparkMax(2),
Expand Down
15 changes: 8 additions & 7 deletions src/main/java/frc/robot/subsystems/drive/Drive.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@

public class Drive extends SubsystemBase {
private static final double MAX_LINEAR_SPEED = Units.feetToMeters(14.5);
private static final double TRACK_WIDTH_X = Units.inchesToMeters(25.0);
private static final double TRACK_WIDTH_Y = Units.inchesToMeters(25.0);
private static final double TRACK_WIDTH_X = Units.inchesToMeters(20.75);
private static final double TRACK_WIDTH_Y = Units.inchesToMeters(20.75);
private static final double DRIVE_BASE_RADIUS =
Math.hypot(TRACK_WIDTH_X / 2.0, TRACK_WIDTH_Y / 2.0);
private static final double MAX_ANGULAR_SPEED = MAX_LINEAR_SPEED / DRIVE_BASE_RADIUS;
Expand Down Expand Up @@ -77,10 +77,11 @@ MAX_LINEAR_SPEED, DRIVE_BASE_RADIUS, new ReplanningConfig()),
Pathfinding.setPathfinder(new LocalADStarAK());
//noinspection ToArrayCallWithZeroLengthArrayArgument
PathPlannerLogging.setLogActivePathCallback(
(activePath) -> Logger.recordOutput(
"Odometry/Trajectory", activePath.toArray(new Pose2d[activePath.size()])));
(activePath) ->
Logger.recordOutput(
"Odometry/Trajectory", activePath.toArray(new Pose2d[activePath.size()])));
PathPlannerLogging.setLogTargetPoseCallback(
(targetPose) -> Logger.recordOutput("Odometry/TrajectorySetpoint", targetPose));
(targetPose) -> Logger.recordOutput("Odometry/TrajectorySetpoint", targetPose));
}

public void periodic() {
Expand Down Expand Up @@ -117,8 +118,8 @@ public void periodic() {
// If the gyro is connected, replace the theta component of the twist
// with the change in angle since the last loop cycle.
twist =
new Twist2d(
twist.dx, twist.dy, gyroInputs.yawPosition.minus(lastGyroRotation).getRadians());
new Twist2d(
twist.dx, twist.dy, gyroInputs.yawPosition.minus(lastGyroRotation).getRadians());
lastGyroRotation = gyroInputs.yawPosition;
}
// Apply the twist (change since last loop cycle) to the current pose
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/frc/robot/subsystems/drive/GyroIO.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
import org.littletonrobotics.junction.AutoLog;

public interface GyroIO {
default void updateInputs(GyroIOInputs inputs) {
}
default void updateInputs(GyroIOInputs inputs) {}

@AutoLog
class GyroIOInputs {
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/frc/robot/subsystems/drive/Module.java
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,7 @@ public SwerveModulePosition getPosition() {
return new SwerveModulePosition(getPositionMeters(), getAngle());
}

/**
* Returns the module position delta since the last call to this method.
*/
/** Returns the module position delta since the last call to this method. */
public SwerveModulePosition getPositionDelta() {
var delta = new SwerveModulePosition(getPositionMeters() - lastPositionMeters, getAngle());
lastPositionMeters = getPositionMeters();
Expand Down
35 changes: 10 additions & 25 deletions src/main/java/frc/robot/subsystems/drive/ModuleIO.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,20 @@
import org.littletonrobotics.junction.AutoLog;

public interface ModuleIO {
/**
* Updates the set of loggable inputs.
*/
default void updateInputs(ModuleIOInputs inputs) {
}
/** Updates the set of loggable inputs. */
default void updateInputs(ModuleIOInputs inputs) {}

/**
* Run the drive motor at the specified voltage.
*/
default void setDriveVoltage(double volts) {
}
/** Run the drive motor at the specified voltage. */
default void setDriveVoltage(double volts) {}

/**
* Run the turn motor at the specified voltage.
*/
default void setTurnVoltage(double volts) {
}
/** Run the turn motor at the specified voltage. */
default void setTurnVoltage(double volts) {}

/**
* Enable or disable brake mode on the drive motor.
*/
default void setDriveBrakeMode(boolean enable) {
}
/** Enable or disable brake mode on the drive motor. */
default void setDriveBrakeMode(boolean enable) {}

/**
* Enable or disable brake mode on the turn motor.
*/
default void setTurnBrakeMode(boolean enable) {
}
/** Enable or disable brake mode on the turn motor. */
default void setTurnBrakeMode(boolean enable) {}

@AutoLog
class ModuleIOInputs {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public class ModuleIOSparkMax implements ModuleIO {

@SuppressWarnings("FieldCanBeLocal")
private final boolean isTurnMotorInverted = true;

private final Rotation2d absoluteEncoderOffset;

public ModuleIOSparkMax(int index) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public class ModuleIOTalonFX implements ModuleIO {
// Gear ratios for SDS MK4i L2, adjust as necessary
@SuppressWarnings("FieldCanBeLocal")
private final double DRIVE_GEAR_RATIO = (50.0 / 14.0) * (17.0 / 27.0) * (45.0 / 15.0);

@SuppressWarnings("FieldCanBeLocal")
private final double TURN_GEAR_RATIO = 150.0 / 7.0;

Expand Down Expand Up @@ -119,7 +120,7 @@ public ModuleIOTalonFX(int index) {
turnCurrent = turnTalon.getStatorCurrent();

BaseStatusSignal.setUpdateFrequencyForAll(
100.0, drivePosition, turnPosition); // Required for odometry, use faster rate
100.0, drivePosition, turnPosition); // Required for odometry, use faster rate
BaseStatusSignal.setUpdateFrequencyForAll(
50.0,
driveVelocity,
Expand Down
Loading