Skip to content

Commit

Permalink
Amp, auto-align, autos
Browse files Browse the repository at this point in the history
  • Loading branch information
keckothedragon committed Oct 14, 2024
1 parent d128ffc commit 9699572
Show file tree
Hide file tree
Showing 18 changed files with 235 additions and 130 deletions.
25 changes: 25 additions & 0 deletions src/main/deploy/pathplanner/autos/New New Auto.auto
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"version": 1.0,
"startingPose": {
"position": {
"x": 2.018336848061597,
"y": 5.5410316277334815
},
"rotation": 0
},
"command": {
"type": "sequential",
"data": {
"commands": [
{
"type": "path",
"data": {
"pathName": "New Path"
}
}
]
}
},
"folder": null,
"choreoAuto": false
}
106 changes: 106 additions & 0 deletions src/main/deploy/pathplanner/paths/New Path.path
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
{
"version": 1.0,
"waypoints": [
{
"anchor": {
"x": 1.901478536053158,
"y": 5.599460783737701
},
"prevControl": null,
"nextControl": {
"x": 2.901478536053158,
"y": 5.599460783737701
},
"isLocked": false,
"linkedName": null
},
{
"anchor": {
"x": 5.845446566337974,
"y": 6.602494628476801
},
"prevControl": {
"x": 4.845446566337974,
"y": 6.602494628476801
},
"nextControl": {
"x": 6.845446566337974,
"y": 6.602494628476801
},
"isLocked": false,
"linkedName": null
},
{
"anchor": {
"x": 6.897171374413923,
"y": 5.044383801697615
},
"prevControl": {
"x": 6.8713089703759485,
"y": 5.823439215087208
},
"nextControl": {
"x": 6.923033778451898,
"y": 4.2653283883080215
},
"isLocked": false,
"linkedName": null
},
{
"anchor": {
"x": 4.336026702895636,
"y": 3.7394659842700477
},
"prevControl": {
"x": 5.629530240673767,
"y": 4.002397186289034
},
"nextControl": {
"x": 3.0425231651175055,
"y": 3.4765347822510613
},
"isLocked": false,
"linkedName": null
},
{
"anchor": {
"x": 1.8625257653836784,
"y": 5.6384135544071805
},
"prevControl": {
"x": 2.452524465250592,
"y": 4.5574741683291204
},
"nextControl": null,
"isLocked": false,
"linkedName": null
}
],
"rotationTargets": [
{
"waypointRelativePos": 1.95,
"rotationDegrees": 180.0,
"rotateFast": false
}
],
"constraintZones": [],
"eventMarkers": [],
"globalConstraints": {
"maxVelocity": 3.0,
"maxAcceleration": 3.0,
"maxAngularVelocity": 540.0,
"maxAngularAcceleration": 720.0
},
"goalEndState": {
"velocity": 0,
"rotation": 0,
"rotateFast": false
},
"reversed": false,
"folder": null,
"previewStartingState": {
"rotation": 0,
"velocity": 0
},
"useDefaultConstraints": true
}
44 changes: 25 additions & 19 deletions src/main/java/frc/robot/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static final class DriveConstants {
Math.hypot(kTrackWidthX / 2.0, kTrackWidthY / 2.0);
public static final double kMaxAngularSpeed = kMaxLinearSpeed / kDriveBaseRadius;
public static final LoggedTunableNumber kTeleopRotationSpeed =
new LoggedTunableNumber("Teleop Rotation Speed", kMaxAngularSpeed);
new LoggedTunableNumber("Teleop Rotation Speed", 10.0);

public static final Translation2d[] kModuleTranslations =
new Translation2d[] {
Expand All @@ -65,6 +65,14 @@ public static final class DriveConstants {
public static final double kDriveGearRatio =
(50.0 / 14.0) * (16.0 / 28.0) * (45.0 / 15.0); // L3 ratio
public static final double kTurnGearRatio = 150.0 / 7.0;

// everything is backwards dont flame me for having negative p
public static final LoggedTunableNumber kHeadingP =
new LoggedTunableNumber("Drive Heading P", -4.0);
public static final LoggedTunableNumber kHeadingI =
new LoggedTunableNumber("Drive Heading I", 0.0);
public static final LoggedTunableNumber kHeadingD =
new LoggedTunableNumber("Drive Heading D", 0.05);
}

public static final class AprilTagVisionConstants {
Expand Down Expand Up @@ -132,27 +140,25 @@ public static final class IntakeConstants {
}

public static final class IndexerConstants {
public static final LoggedTunableNumber kIntakingVelocity =
new LoggedTunableNumber("Indexer Intake Velocity", -8.0);
public static final LoggedTunableNumber kIndexingVelocity =
new LoggedTunableNumber("Indexer Indexing Velocity", -8.0);
public static final LoggedTunableNumber kReversingVelocity =
new LoggedTunableNumber("Indexer Reverse Velocity", 8.0);
public static final LoggedTunableNumber kShootingVelocity =
new LoggedTunableNumber("Indexer Shooting Velocity", -10.0);
public static final LoggedTunableNumber kEjectingVelocity =
new LoggedTunableNumber("Indexer Eject Velocity", 8.0);
public static final LoggedTunableNumber kIdleVoltage =
new LoggedTunableNumber("Indexer Idle Voltage", 0.0);
public static final LoggedTunableNumber kIntakingVoltage =
new LoggedTunableNumber("Indexer Intake Voltage", -8.0);
public static final LoggedTunableNumber kIndexingVoltage =
new LoggedTunableNumber("Indexer Indexing Voltage", -8.0);
public static final LoggedTunableNumber kReversingVoltage =
new LoggedTunableNumber("Indexer Reverse Voltage", 8.0);
public static final LoggedTunableNumber kShootingVoltage =
new LoggedTunableNumber("Indexer Shooting Voltage", -12.0);
public static final LoggedTunableNumber kEjectingVoltage =
new LoggedTunableNumber("Indexer Eject Voltage", 8.0);

public static final LoggedTunableNumber kShootingTimeout =
new LoggedTunableNumber("Indexer Shooting Timeout", 1.0);
new LoggedTunableNumber("Indexer Shooting Timeout", 1.5);
public static final LoggedTunableNumber kIndexingTimeout =
new LoggedTunableNumber("Indexer Indexing Timeout", 0.1);
public static final LoggedTunableNumber kReverseTimeout =
new LoggedTunableNumber("Indexer Reverse Timeout", 0.5);

public static final LoggedTunableNumber kIndexerP = new LoggedTunableNumber("Indexer P", 0.4);
public static final LoggedTunableNumber kIndexerI = new LoggedTunableNumber("Indexer I", 0.0);
public static final LoggedTunableNumber kIndexerD = new LoggedTunableNumber("Indexer D", 0.0);
new LoggedTunableNumber("Indexer Reverse Timeout", 0.2);

// Simulation constants
public static final DCMotor kSimGearbox = DCMotor.getNEO(1);
Expand Down Expand Up @@ -187,9 +193,9 @@ public static final class ShooterConstants {
new LoggedTunableNumber("Bottom Flywheel kV", 0.13);

public static final LoggedTunableNumber kAmpTopVelocity =
new LoggedTunableNumber("Amp Top Velocity", 5.0);
new LoggedTunableNumber("Amp Top Velocity", -3.5);
public static final LoggedTunableNumber kAmpBottomVelocity =
new LoggedTunableNumber("Amp Bottom Velocity", 7.0);
new LoggedTunableNumber("Amp Bottom Velocity", 58.0);

public static final LoggedTunableNumber kSubwooferTopVelocity =
new LoggedTunableNumber("Subwoofer Top Velocity", 60.0);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/frc/robot/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ public void robotPeriodic() {
// finished or interrupted commands, and running subsystem periodic() methods.
// This must be called from the robot's periodic block in order for anything in
// the Command-based framework to work.
var start = Timer.getFPGATimestamp();
double start = Timer.getFPGATimestamp();

CommandScheduler.getInstance().run();

Logger.recordOutput("PeriodicTime/CommandScheduler", Timer.getFPGATimestamp() - start);
Logger.recordOutput("PeriodicTime/CommandScheduler", (double) Timer.getFPGATimestamp() - start);

robotContainer.updateRobotState();
}
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/frc/robot/RobotContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ private void configureSubsystems() {

/** Configure the commands. */
private void configureCommands() {
m_autoChooser = new LoggedDashboardChooser<>("AutoChooser");
m_autoChooser = new LoggedDashboardChooser<>("Auto Chooser");
m_autoFactory = new AutoFactory(m_drive);

// Configure autos here
Expand Down Expand Up @@ -343,6 +343,14 @@ private void configureButtonBindings() {
m_shooter.updateState(ShooterState.kIdle);
m_drive.updateProfile(DriveProfiles.kDefault);
}));

m_driverControls
.resetPoseAuto()
.onTrue(
Commands.runOnce(
() -> {
m_drive.setPose(new Pose2d(14.764, 5.594, new Rotation2d(Math.PI)));
}));
}

/**
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/frc/robot/RobotState.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import frc.robot.subsystems.shooter.Shooter;
import frc.robot.subsystems.shooter.Shooter.ShooterPosition;
import frc.robot.subsystems.shooter.Shooter.ShooterState;
import frc.robot.util.AllianceFlipUtil;
import frc.robot.util.ShooterMath;
import frc.robot.util.SubsystemProfiles;
import java.util.HashMap;
Expand Down Expand Up @@ -91,7 +90,7 @@ public static RobotState getInstance() {
}

public void updateRobotState() {
var start = Timer.getFPGATimestamp();
double start = Timer.getFPGATimestamp();

m_profiles.getPeriodicFunction().run();

Expand Down Expand Up @@ -225,8 +224,8 @@ public void updateRobotAction(RobotAction newAction) {
case kAmpLineup:
m_intake.updateState(IntakeState.kIdle);
m_shooter.updateState(ShooterState.kAmp);
m_drive.updateProfile(DriveProfiles.kAmpLineup);
m_drive.setDesiredHeading(AllianceFlipUtil.apply(Rotation2d.fromDegrees(90)));
m_drive.updateProfile(DriveProfiles.kDefault);
// m_drive.setDesiredHeading(AllianceFlipUtil.apply(Rotation2d.fromDegrees(90)));

break;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/frc/robot/commands/auto/AutoFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

public class AutoFactory extends Command {
public static final PIDConstants kLinearPID = new PIDConstants(2.5, 0.0, 0.0);
public static final PIDConstants kAngularPID = new PIDConstants(4, 1.6, 0.0);
public static final PIDConstants kAngularPID = new PIDConstants(1.2, 0.0, 0.0);

private final Drive m_drive;

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/frc/robot/oi/DriverControls.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,6 @@ public interface DriverControls {
public Trigger cancelAmpLineup();

public Trigger subwooferShot();

public Trigger resetPoseAuto();
}
5 changes: 5 additions & 0 deletions src/main/java/frc/robot/oi/DriverControlsPS5.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,9 @@ public Trigger cancelAmpLineup() {
public Trigger subwooferShot() {
return m_controller.cross();
}

@Override
public Trigger resetPoseAuto() {
return m_controller.square();
}
}
5 changes: 5 additions & 0 deletions src/main/java/frc/robot/oi/DriverControlsXbox.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,9 @@ public Trigger cancelAmpLineup() {
public Trigger subwooferShot() {
return m_controller.a();
}

@Override
public Trigger resetPoseAuto() {
return m_controller.x();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public AprilTagVision(AprilTagVisionIO... ios) {

@Override
public void periodic() {
var start = Timer.getFPGATimestamp();
double start = Timer.getFPGATimestamp();

for (int i = 0; i < m_ios.length; i++) {
m_ios[i].updateInputs(m_inputs[i]);
Expand Down
24 changes: 22 additions & 2 deletions src/main/java/frc/robot/subsystems/drive/Drive.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import frc.robot.Constants.DriveConstants;
import frc.robot.subsystems.aprilTagVision.AprilTagVision.VisionObservation;
import frc.robot.util.LocalADStarAK;
import frc.robot.util.LoggedTunableNumber;
import frc.robot.util.SubsystemProfiles;
import java.util.HashMap;
import java.util.concurrent.locks.Lock;
Expand All @@ -64,7 +65,11 @@ public enum DriveProfiles {
private ChassisSpeeds m_desiredChassisSpeeds = new ChassisSpeeds();

private Rotation2d m_desiredHeading = new Rotation2d();
private PIDController m_headingController = new PIDController(0.1, 0, 0.09);
private PIDController m_headingController =
new PIDController(
DriveConstants.kHeadingP.get(),
DriveConstants.kHeadingI.get(),
DriveConstants.kHeadingD.get());

private Rotation2d m_rawGyroRotation = new Rotation2d();
private SwerveModulePosition[] m_lastModulePositions = // For delta tracking
Expand Down Expand Up @@ -149,7 +154,7 @@ public Drive(
}

public void periodic() {
var start = Timer.getFPGATimestamp();
double start = Timer.getFPGATimestamp();

m_odometryLock.lock(); // Prevents odometry updates while reading data
m_gyroIO.updateInputs(m_gyroInputs);
Expand All @@ -158,6 +163,17 @@ public void periodic() {
}
m_odometryLock.unlock();

LoggedTunableNumber.ifChanged(
hashCode(),
() -> {
m_headingController.setP(DriveConstants.kHeadingP.get());
m_headingController.setI(DriveConstants.kHeadingI.get());
m_headingController.setD(DriveConstants.kHeadingD.get());
},
DriveConstants.kHeadingP,
DriveConstants.kHeadingI,
DriveConstants.kHeadingD);

m_profiles.getPeriodicFunction().run();

Logger.processInputs("Drive/Gyro", m_gyroInputs);
Expand Down Expand Up @@ -218,6 +234,7 @@ public void defaultPeriodic() {
runVelocity(m_desiredChassisSpeeds);

Logger.recordOutput("Drive/DesiredHeading", m_desiredHeading.getDegrees());
Logger.recordOutput("Drive/CurrentHeading", getPose().getRotation().getDegrees());
Logger.recordOutput("Drive/DesiredSpeeds", m_desiredChassisSpeeds);
}

Expand Down Expand Up @@ -247,6 +264,9 @@ public ChassisSpeeds calculateAutoAlignSpeeds() {
m_desiredChassisSpeeds.omegaRadiansPerSecond =
m_headingController.calculate(
getPose().getRotation().getRadians(), m_desiredHeading.getRadians());
Logger.recordOutput("AutoAlign/Curr", getPose().getRotation().getRadians());
Logger.recordOutput("AutoAlign/Des", m_desiredHeading.getRadians());
Logger.recordOutput("AutoAlign/Out", m_desiredChassisSpeeds.omegaRadiansPerSecond);
}

return m_desiredChassisSpeeds;
Expand Down
Loading

0 comments on commit 9699572

Please sign in to comment.