Skip to content
This repository has been archived by the owner on Dec 2, 2024. It is now read-only.

Commit

Permalink
some logging things and drive simplification
Browse files Browse the repository at this point in the history
  • Loading branch information
carokhan committed Oct 11, 2024
1 parent 2414864 commit 6f4b11f
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 102 deletions.
34 changes: 34 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,37 @@ spotless {
endWithNewline()
}
}

// Create commit with working changes on event branches
task(eventDeploy) {
doLast {
if (project.gradle.startParameter.taskNames.any({ it.toLowerCase().contains("deploy") })) {

def branchPrefix = "event"
def branch = 'git branch --show-current'.execute().text.trim()
def commitMessage = "Update at '${new Date().toString()}'"

if (branch.startsWith(branchPrefix)) {
exec {
workingDir(projectDir)
executable 'git'
args 'add', '-A'
}
exec {
workingDir(projectDir)
executable 'git'
args 'commit', '-m', commitMessage
ignoreExitValue = true
}

println "Committed to branch: '$branch'"
println "Commit message: '$commitMessage'"
} else {
println "Not on an event branch, skipping commit"
}
} else {
println "Not running deploy task, skipping commit"
}
}
}
createVersionFile.dependsOn(eventDeploy)
10 changes: 5 additions & 5 deletions src/main/java/frc/robot/BuildConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ public final class BuildConstants {
public static final String MAVEN_GROUP = "";
public static final String MAVEN_NAME = "Forte-2-5";
public static final String VERSION = "unspecified";
public static final int GIT_REVISION = 79;
public static final String GIT_SHA = "547f9ab3941b5f47c4860c630df2611586daa420";
public static final String GIT_DATE = "2024-10-11 09:43:51 EDT";
public static final int GIT_REVISION = 81;
public static final String GIT_SHA = "2414864d99e03e5681d64c5f87a3ae1e1a43be3c";
public static final String GIT_DATE = "2024-10-11 06:01:33 EDT";
public static final String GIT_BRANCH = "main";
public static final String BUILD_DATE = "2024-10-11 09:50:21 EDT";
public static final long BUILD_UNIX_TIME = 1728654621885L;
public static final String BUILD_DATE = "2024-10-11 07:55:17 EDT";
public static final long BUILD_UNIX_TIME = 1728647717748L;
public static final int DIRTY = 1;

private BuildConstants() {}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/frc/robot/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
public final class Constants {
public static final double loopPeriodSecs = 0.02;

public static final Mode currentMode = Mode.REAL;
public static final Mode currentMode = Mode.SIM;

public static enum Mode {
/** Running on a real robot. */
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/frc/robot/Visualizer.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
import frc.robot.subsystems.climber.Climb;
import frc.robot.subsystems.intake.Intake;
import frc.robot.subsystems.pivot2.Pivot;
import org.littletonrobotics.junction.Logger;
import org.littletonrobotics.junction.AutoLogOutput;

public class Visualizer extends SubsystemBase {
private Mechanism2d m_main;
@AutoLogOutput private Mechanism2d m_main;

private MechanismLigament2d m_climberMech;
private MechanismLigament2d m_intakeMech;
Expand Down Expand Up @@ -133,6 +133,6 @@ public void periodic() {
m_pivotRelative.setAngle(Units.radiansToDegrees(m_pivot.getRelativeRadians()));
m_pivotTarget.setAngle(Units.radiansToDegrees(m_pivot.getTargetRadians()));

Logger.recordOutput("Visualizer/FullRobot", m_main);
// Logger.recordOutput("Visualizer/FullRobot", m_main);
}
}
65 changes: 0 additions & 65 deletions src/main/java/frc/robot/subsystems/drive/Drive.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,47 +119,6 @@ public void periodic() {
}
}

/**
* Runs the drive at the desired velocity.
*
* @param speeds Speeds in meters/sec
*/
public void runVelocity(ChassisSpeeds speeds) {
// Calculate module setpoints
ChassisSpeeds discreteSpeeds = ChassisSpeeds.discretize(speeds, 0.02);
SwerveModuleState[] setpointStates = kinematics.toSwerveModuleStates(discreteSpeeds);
SwerveDriveKinematics.desaturateWheelSpeeds(setpointStates, DriveConstants.maxLinearVelocity);

// Send setpoints to modules
SwerveModuleState[] optimizedSetpointStates = new SwerveModuleState[4];
for (int i = 0; i < 4; i++) {
// The module returns the optimized state, useful for logging
optimizedSetpointStates[i] = modules[i].runSetpoint(setpointStates[i]);
}

// Log setpoint states
Logger.recordOutput("SwerveStates/Setpoints", setpointStates);
Logger.recordOutput("SwerveStates/SetpointsOptimized", optimizedSetpointStates);
}

/** Stops the drive. */
public void stop() {
runVelocity(new ChassisSpeeds());
}

/**
* Stops the drive and turns the modules to an X arrangement to resist movement. The modules will
* return to their normal orientations the next time a nonzero velocity is requested.
*/
public void stopWithX() {
Rotation2d[] headings = new Rotation2d[4];
for (int i = 0; i < 4; i++) {
headings[i] = getModuleTranslations()[i].getAngle();
}
kinematics.resetHeadings(headings);
stop();
}

/** Returns the module states (turn angles and drive velocities) for all of the modules. */
@AutoLogOutput(key = "SwerveStates/Measured")
private SwerveModuleState[] getModuleStates() {
Expand All @@ -179,16 +138,6 @@ private SwerveModulePosition[] getModulePositions() {
return states;
}

/** Returns the maximum linear speed in meters per sec. */
public double getMaxLinearSpeedMetersPerSec() {
return DriveConstants.maxLinearVelocity;
}

/** Returns the maximum angular speed in radians per sec. */
public double getMaxAngularSpeedRadPerSec() {
return DriveConstants.maxAngularVelocity;
}

/** Returns an array of module translations. */
public static Translation2d[] getModuleTranslations() {
return new Translation2d[] {
Expand Down Expand Up @@ -241,21 +190,7 @@ public ChassisSpeeds getVelocity() {
speeds.vxMetersPerSecond, speeds.vyMetersPerSecond, speeds.omegaRadiansPerSecond);
}

public void resetOffsets() {
for (int i = 0; i < 4; i++) {
modules[i].resetOffset();
}
}

public Command resetOffsetsCmd() {
return run(() -> resetOffsets());
}

public Rotation2d getRotation() {
return gyroIO.getYaw();
}

public void resetGyro() {
gyroIO.reset();
}
}
15 changes: 0 additions & 15 deletions src/main/java/frc/robot/subsystems/drive/Module.java
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,6 @@ public void stop() {
velocitySetpoint = null;
}

/** Sets whether brake mode is enabled. */
public void setBrakeMode(boolean enabled) {
io.setDriveBrakeMode(enabled);
io.setTurnBrakeMode(enabled);
}

/** Returns the current turn angle of the module. */
public Rotation2d getAngle() {
return inputs.turnPosition;
Expand All @@ -212,17 +206,8 @@ public SwerveModuleState getState() {
return new SwerveModuleState(getVelocityMetersPerSec(), getAngle());
}

/** Returns the module positions received this cycle. */
public SwerveModulePosition[] getOdometryPositions() {
return odometryPositions;
}

/** Returns the timestamps of the samples received this cycle. */
public double[] getOdometryTimestamps() {
return inputs.odometryTimestamps;
}

public void resetOffset() {
io.resetOffset();
}
}
2 changes: 0 additions & 2 deletions src/main/java/frc/robot/subsystems/drive/ModuleIO.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,4 @@ public abstract void setDrivePIDFF(
public abstract void stop();

public abstract String getModuleName();

public abstract void resetOffset();
}
7 changes: 0 additions & 7 deletions src/main/java/frc/robot/subsystems/drive/ModuleIOReal.java
Original file line number Diff line number Diff line change
Expand Up @@ -342,11 +342,4 @@ public void stop() {
}
runTurnVoltage(0);
}

public void resetOffset() {
if (DriveConstants.wheelsStraight) {
absoluteEncoderOffset = Rotation2d.fromRadians(turnRelativeEncoder.getPosition());
turnRelativeEncoder.setPosition(getAbsoluteEncoder());
}
}
}
2 changes: 0 additions & 2 deletions src/main/java/frc/robot/subsystems/drive/ModuleIOReplay.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,4 @@ public void stop() {}
public String getModuleName() {
return null;
}

public void resetOffset() {}
}
2 changes: 0 additions & 2 deletions src/main/java/frc/robot/subsystems/drive/ModuleIOSim.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,4 @@ public void stop() {
public String getModuleName() {
return name;
}

public void resetOffset() {}
}

0 comments on commit 6f4b11f

Please sign in to comment.