-
Notifications
You must be signed in to change notification settings - Fork 0
Initial Drive Subsystem and Path Handler #3
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
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
78d1af2
changed choreo settings
PotatoBoyH4 de438c0
Merge branch 'main' into drive
PotatoBoyH4 b24239c
Merge branch 'main' into drive
PotatoBoyH4 04aa220
created drive subsystem
PotatoBoyH4 4e2cf5c
finished driveSubsystem for now.
PotatoBoyH4 18cdcba
started on autons
PotatoBoyH4 67f818b
made pathHandler much, much better. still isn't finished
PotatoBoyH4 5e1d81d
finished pathHandler
PotatoBoyH4 6de09ea
small changes to driveSubsystem
PotatoBoyH4 87f3d00
added some fixes from marissa
PotatoBoyH4 257ce96
made the requested changes
PotatoBoyH4 edb0f04
spotlessApply
PotatoBoyH4 8177fb4
fixed a lot of tag servoing logic
PotatoBoyH4 abf7a7c
Merge branch 'main' into auton
mwitcpalek 73c2e4d
Merge branch 'auton' of github.com:strykeforce/reefscape into auton
mwitcpalek 6fe746c
spotless
mwitcpalek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
src/main/java/frc/robot/commands/auton/AutoCommandInterface.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| package frc.robot.commands.auton; | ||
|
|
||
| public interface AutoCommandInterface { | ||
| public void reassignAlliance(); | ||
| } |
106 changes: 106 additions & 0 deletions
106
src/main/java/frc/robot/commands/drive/DriveAutonCommand.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| package frc.robot.commands.drive; | ||
|
|
||
| import choreo.Choreo; | ||
| import choreo.trajectory.SwerveSample; | ||
| import choreo.trajectory.Trajectory; | ||
| import edu.wpi.first.math.geometry.Pose2d; | ||
| import edu.wpi.first.wpilibj.Timer; | ||
| import edu.wpi.first.wpilibj2.command.Command; | ||
| import frc.robot.commands.auton.AutoCommandInterface; | ||
| import frc.robot.subsystems.drive.DriveSubsystem; | ||
| import java.util.Optional; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| public class DriveAutonCommand extends Command implements AutoCommandInterface { | ||
| private final DriveSubsystem driveSubsystem; | ||
| private Trajectory<SwerveSample> trajectory; | ||
| private final Timer timer = new Timer(); | ||
| private static final Logger logger = LoggerFactory.getLogger(DriveAutonCommand.class); | ||
| private boolean isTherePath = false; | ||
| private String trajectoryName; | ||
| private boolean mirrorTrajectory = false; | ||
|
|
||
| private boolean resetOdometry; | ||
| private boolean lastPath; | ||
|
|
||
| public DriveAutonCommand( | ||
| DriveSubsystem driveSubsystem, | ||
| String trajectoryName, | ||
| boolean lastPath, | ||
| boolean resetOdometry) { | ||
|
|
||
| addRequirements(driveSubsystem); | ||
| this.driveSubsystem = driveSubsystem; | ||
| this.resetOdometry = resetOdometry; | ||
| this.lastPath = lastPath; | ||
| this.trajectoryName = trajectoryName; | ||
| Optional<Trajectory<SwerveSample>> tempTrajectory = Choreo.loadTrajectory(trajectoryName); | ||
| if (tempTrajectory.isPresent()) { | ||
| trajectory = tempTrajectory.get(); | ||
| isTherePath = true; | ||
| } else { | ||
| logger.error("Trajectory {} not found", trajectoryName); | ||
| isTherePath = false; | ||
| } | ||
| timer.start(); | ||
| } | ||
|
|
||
| @Override | ||
| public void reassignAlliance() { | ||
| mirrorTrajectory = driveSubsystem.shouldFlip(); | ||
| } | ||
|
|
||
| @Override | ||
| public void initialize() { | ||
| if (isTherePath) { | ||
| driveSubsystem.setAutoDebugMsg("Initialize " + trajectoryName); | ||
| Pose2d initialPose = new Pose2d(); | ||
| initialPose = trajectory.getInitialPose(mirrorTrajectory).get(); | ||
| if (resetOdometry) { | ||
| driveSubsystem.resetOdometry(initialPose); | ||
| } | ||
| driveSubsystem.setEnableHolo(true); | ||
| // driveSubsystem.recordAutoTrajectory(trajectory); | ||
| driveSubsystem.resetHolonomicController(); | ||
| driveSubsystem.grapherTrajectoryActive(true); | ||
| timer.reset(); | ||
| logger.info("Begin Trajectory: {}", trajectoryName); | ||
| SwerveSample desiredState = trajectory.sampleAt(timer.get(), mirrorTrajectory).get(); | ||
| driveSubsystem.calculateController(desiredState); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void execute() { | ||
| if (isTherePath) { | ||
| SwerveSample desiredState = trajectory.sampleAt(timer.get(), mirrorTrajectory).get(); | ||
| driveSubsystem.calculateController(desiredState); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isFinished() { | ||
| if (!isTherePath) { | ||
| return false; | ||
| } | ||
| return timer.hasElapsed(trajectory.getTotalTime()); | ||
| } | ||
|
|
||
| @Override | ||
| public void end(boolean interrupted) { | ||
| driveSubsystem.setEnableHolo(false); | ||
| // driveSubsystem.recordAutoTrajectory(null); | ||
|
|
||
| if (!interrupted && !lastPath) { | ||
| driveSubsystem.calculateController( | ||
| trajectory.sampleAt(trajectory.getTotalTime(), mirrorTrajectory).get()); | ||
| } else { | ||
| driveSubsystem.drive(0, 0, 0); | ||
| } | ||
|
|
||
| driveSubsystem.grapherTrajectoryActive(false); | ||
| logger.info("End Trajectory {}: {}", trajectoryName, timer.get()); | ||
| driveSubsystem.setAutoDebugMsg("End " + trajectoryName); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,151 @@ | ||
| package frc.robot.constants; | ||
|
|
||
| public class DriveConstants {} | ||
| import com.ctre.phoenix.motorcontrol.FeedbackDevice; | ||
| import com.ctre.phoenix.motorcontrol.LimitSwitchSource; | ||
| import com.ctre.phoenix.motorcontrol.can.TalonSRXConfiguration; | ||
| import com.ctre.phoenix.sensors.SensorVelocityMeasPeriod; | ||
| import com.ctre.phoenix6.configs.CurrentLimitsConfigs; | ||
| import com.ctre.phoenix6.configs.MotorOutputConfigs; | ||
| import com.ctre.phoenix6.configs.Pigeon2Configuration; | ||
| import com.ctre.phoenix6.configs.Slot0Configs; | ||
| import com.ctre.phoenix6.configs.TalonFXConfiguration; | ||
| import com.ctre.phoenix6.signals.NeutralModeValue; | ||
| import edu.wpi.first.math.geometry.Translation2d; | ||
|
|
||
| public class DriveConstants { | ||
| public static final double kDriveGearRatio = 6.5; | ||
| public static final double kWheelDiameterInches = 4.0; | ||
| public static final double kMaxSpeedMetersPerSecond = 12.0; | ||
| public static final double kSpeedStillThreshold = 0.1; // meters per second | ||
| public static final double kGyroRateStillThreshold = 10.0; // 25 5 degrees per second | ||
| public static final double kGyroDifferentThreshold = 5.0; // 5 degrees | ||
| public static final int kGyroDifferentCount = 3; | ||
|
|
||
| public static final double kRobotLength = 22.0; | ||
| public static final double kRobotWidth = 22.0; | ||
| public static final double kFieldMaxX = 690.0; | ||
|
|
||
| public static final double kPOmega = 4.5; | ||
| public static final double kIOmega = 0.0; | ||
| public static final double kDOmega = 0.0; | ||
| public static final double kMaxVelOmega = | ||
| (kMaxSpeedMetersPerSecond / Math.hypot(kRobotWidth / 2.0, kRobotLength / 2.0)) / 2.0; | ||
| public static final double kMaxAccelOmega = 5.0; | ||
|
|
||
| public static final double kPHolonomic = 3.0; // was 3 | ||
| public static final double kIHolonomic = 0.0000; | ||
| public static final double kDHolonomic = 0.00; // kPHolonomic/100 | ||
|
|
||
| public static Translation2d[] getWheelLocationMeters() { | ||
| final double x = kRobotLength / 2.0; // front-back, was ROBOT_LENGTH | ||
| final double y = kRobotWidth / 2.0; // left-right, was ROBOT_WIDTH | ||
| Translation2d[] locs = new Translation2d[4]; | ||
| locs[0] = new Translation2d(x, y); // left front | ||
| locs[1] = new Translation2d(x, -y); // right front | ||
| locs[2] = new Translation2d(-x, y); // left rear | ||
| locs[3] = new Translation2d(-x, -y); // right rear | ||
| return locs; | ||
| } | ||
|
|
||
| // temp stuff | ||
| public static final int kTempAvgCount = 25; | ||
| public static final double kTripTemp = 1300; | ||
| public static final double kRecoverTemp = 1290; | ||
| public static final double kNotifyTemp = 1295; | ||
|
|
||
| public static TalonSRXConfiguration | ||
| getAzimuthTalonConfig() { // will be changed to a TalonFXConfiguration | ||
| // constructor sets encoder to Quad/CTRE_MagEncoder_Relative | ||
| TalonSRXConfiguration azimuthConfig = new TalonSRXConfiguration(); | ||
|
|
||
| azimuthConfig.primaryPID.selectedFeedbackCoefficient = 1.0; | ||
| azimuthConfig.auxiliaryPID.selectedFeedbackSensor = FeedbackDevice.None; | ||
|
|
||
| azimuthConfig.forwardLimitSwitchSource = LimitSwitchSource.Deactivated; | ||
| azimuthConfig.reverseLimitSwitchSource = LimitSwitchSource.Deactivated; | ||
|
|
||
| azimuthConfig.continuousCurrentLimit = 10; | ||
| azimuthConfig.peakCurrentDuration = 0; | ||
| azimuthConfig.peakCurrentLimit = 0; | ||
|
|
||
| azimuthConfig.slot0.kP = 15.0; | ||
| azimuthConfig.slot0.kI = 0.0; | ||
| azimuthConfig.slot0.kD = 150.0; | ||
| azimuthConfig.slot0.kF = 1.0; | ||
| azimuthConfig.slot0.integralZone = 0; | ||
| azimuthConfig.slot0.allowableClosedloopError = 0; | ||
| azimuthConfig.slot0.maxIntegralAccumulator = 0; | ||
|
|
||
| azimuthConfig.motionCruiseVelocity = 800; | ||
| azimuthConfig.motionAcceleration = 10_000; | ||
| azimuthConfig.velocityMeasurementWindow = 64; | ||
| azimuthConfig.velocityMeasurementPeriod = SensorVelocityMeasPeriod.Period_100Ms; | ||
| azimuthConfig.voltageCompSaturation = 12; | ||
| azimuthConfig.voltageMeasurementFilter = 32; | ||
| azimuthConfig.neutralDeadband = 0.04; | ||
| return azimuthConfig; | ||
| } | ||
|
|
||
| public static TalonFXConfiguration getDriveTalonConfig() { | ||
| TalonFXConfiguration driveConfig = new TalonFXConfiguration(); | ||
|
|
||
| CurrentLimitsConfigs currentConfig = new CurrentLimitsConfigs(); | ||
| currentConfig.SupplyCurrentLimit = 60; | ||
|
|
||
| currentConfig.StatorCurrentLimit = 140; | ||
|
|
||
| currentConfig.SupplyCurrentLimitEnable = true; | ||
| currentConfig.StatorCurrentLimitEnable = true; | ||
|
|
||
| driveConfig.CurrentLimits = currentConfig; | ||
|
|
||
| Slot0Configs slot0Config = new Slot0Configs(); | ||
| slot0Config.kP = 0.5; // 0.16 using phoenix 6 migrate | ||
| slot0Config.kI = 0.5; // 0.0002 using phoenix 6 migrate | ||
| slot0Config.kD = 0.0; | ||
| slot0Config.kV = 0.12; // 0.047 using phoenix 6 migrate | ||
| driveConfig.Slot0 = slot0Config; | ||
|
|
||
| MotorOutputConfigs motorConfigs = new MotorOutputConfigs(); | ||
| motorConfigs.DutyCycleNeutralDeadband = 0.01; | ||
| motorConfigs.NeutralMode = NeutralModeValue.Brake; | ||
| driveConfig.MotorOutput = motorConfigs; | ||
|
|
||
| return driveConfig; | ||
| } | ||
|
|
||
| public static final int kPigeonCanID = 1000; // fix later | ||
|
|
||
| public static Pigeon2Configuration getPigeon2Configuration() { | ||
| Pigeon2Configuration config = new Pigeon2Configuration(); | ||
|
|
||
| config.MountPose.MountPoseYaw = -90.0; | ||
| config.MountPose.MountPoseRoll = 0.0; | ||
| config.MountPose.MountPosePitch = 0.0; | ||
|
|
||
| config.GyroTrim.GyroScalarX = 0.0; | ||
| config.GyroTrim.GyroScalarY = 0.0; | ||
| config.GyroTrim.GyroScalarZ = -2.12; | ||
|
|
||
| return config; | ||
| } | ||
|
|
||
| public static CurrentLimitsConfigs getSafeDriveLimits() { | ||
| CurrentLimitsConfigs currentConfig = new CurrentLimitsConfigs(); | ||
| currentConfig.SupplyCurrentLimit = 30; | ||
| currentConfig.SupplyCurrentLimitEnable = true; | ||
| currentConfig.StatorCurrentLimitEnable = false; | ||
| return currentConfig; | ||
| } | ||
|
|
||
| public static CurrentLimitsConfigs getNormDriveLimits() { | ||
| CurrentLimitsConfigs currentConfig = new CurrentLimitsConfigs(); | ||
| currentConfig.SupplyCurrentLimit = 30; | ||
|
|
||
| currentConfig.StatorCurrentLimit = 140; | ||
|
|
||
| currentConfig.SupplyCurrentLimitEnable = true; | ||
| currentConfig.StatorCurrentLimitEnable = true; | ||
| return currentConfig; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| package frc.robot.constants; | ||
|
|
||
| public class RobotConstants {} | ||
| public class RobotConstants { | ||
| public static final int kTalonConfigTimeout = 10; // ms | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| package frc.robot.constants; | ||
|
|
||
| public class RobotStateConstants {} | ||
| public class RobotStateConstants { | ||
| public static final double[] kNodeAngles = {0.0, 60.0, 120.0, 180.0, -120.0, -60.0}; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| package frc.robot.constants; | ||
|
|
||
| public class TagServoingConstants { | ||
| public static final double kAngleCloseEnough = 3.0; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.