Skip to content

Commit da960ed

Browse files
committed
Merge branch 'AutoDev' of https://github.com/FRC1257/2024-Robot into AutoDev
2 parents 834b6b3 + 04d8430 commit da960ed

21 files changed

+150
-236
lines changed

src/main/java/frc/robot/Constants.java

-20
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,6 @@ public static Mode getRobotMode() {
7676
return Mode.REAL;
7777
}
7878

79-
public static class BuildConstants {
80-
public static int DIRTY = 1;
81-
public static String MAVEN_NAME = "Snail";
82-
public static String BUILD_DATE = "12/57";
83-
public static String GIT_SHA = "Snail";
84-
public static String GIT_DATE = "Snail";
85-
public static String GIT_BRANCH = "PivotArm";
86-
}
87-
8879
public static final class NeoMotorConstants {
8980
public static final double kFreeSpeedRpm = 5676;
9081
}
@@ -141,15 +132,4 @@ public static class ElectricalLayout {
141132
{4.258293028 ,0, 57},
142133
{5 ,0, 60}
143134
};
144-
145-
146-
/* public static final double[][] LookupTable = {
147-
{0, 0, 38},
148-
{1.22, 0, 42},
149-
{1.45, 0, 38},
150-
{3.49, 0, 53}
151-
{6, 0, 55}
152-
}; */
153-
154-
155135
}

src/main/java/frc/robot/Robot.java

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
import edu.wpi.first.wpilibj2.command.Command;
1515
import edu.wpi.first.wpilibj2.command.CommandScheduler;
16-
import frc.robot.Constants.BuildConstants;
1716

1817
/**
1918
* The VM is configured to automatically run this class, and to call the

src/main/java/frc/robot/RobotContainer.java

+39-38
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,13 @@ public class RobotContainer {
7777
// Dashboard inputs
7878
private final LoggedDashboardChooser<Command> autoChooser;
7979

80+
// crete mode changers
8081
private LoggedDashboardNumber autoWait = new LoggedDashboardNumber("AutoWait", 0);
8182
private LoggedDashboardNumber rightShooterVolts = new LoggedDashboardNumber("RightShooter", ShooterConstants.SHOOTER_FULL_VOLTAGE);
8283
private LoggedDashboardNumber leftShooterVolts = new LoggedDashboardNumber("LeftShooter", ShooterConstants.SHOOTER_FULL_VOLTAGE);
83-
private LoggedDashboardBoolean TurboMode = new LoggedDashboardBoolean("Turbo Mode",false);
84-
private LoggedDashboardBoolean BrakeMode = new LoggedDashboardBoolean("Brake Mode", true);
85-
private LoggedDashboardBoolean SetStartPosition = new LoggedDashboardBoolean("Set Start Position", false);
86-
private LoggedDashboardBoolean ShootSide = new LoggedDashboardBoolean("ShootSide", false);
84+
private LoggedDashboardBoolean brakeModeDashboard = new LoggedDashboardBoolean("Brake Mode", true);
85+
private LoggedDashboardBoolean setStartPosition = new LoggedDashboardBoolean("Set Start Position", false);
86+
8787
// Field
8888
private final Field2d field;
8989

@@ -192,7 +192,7 @@ public RobotContainer() {
192192
System.out.println("[Init] Setting up Named Commands");
193193

194194
NamedCommands.registerCommand("Shoot", shootSpeaker().andThen(zeroPosition()));
195-
NamedCommands.registerCommand("ShootSide", shootSpeakerSide().andThen(zeroPosition()));
195+
NamedCommands.registerCommand("shootSide", shootSpeakerSide().andThen(zeroPosition()));
196196
NamedCommands.registerCommand("ShootAnywhere", shootAnywhereAuto());
197197

198198
NamedCommands.registerCommand("Intake",
@@ -203,6 +203,7 @@ public RobotContainer() {
203203
NamedCommands.registerCommand("ZeroPivot", pivot.bringDownCommand());
204204

205205
NamedCommands.registerCommand("PrepShot", rotateArmSpeaker());
206+
// TODO clean these up later
206207
NamedCommands.registerCommand("PrepShootAnywhere", rotateArmtoSpeakerForever()
207208
.alongWith(shooter.runVoltageBoth(rightShooterVolts::get, leftShooterVolts::get)));
208209
NamedCommands.registerCommand("PrepPass", shooter.runVoltage(ShooterConstants.SHOOTER_UNJAM_VOLTAGE).alongWith(indexer.manualCommand(IndexerConstants.INDEXER_OUT_VOLTAGE)).withTimeout(0.1)
@@ -237,12 +238,11 @@ public RobotContainer() {
237238

238239
}
239240

240-
241+
// zero gyro
241242
public void reset() {
242243
drive.resetYaw();
243244
}
244245

245-
246246
/**
247247
* Use this method to define your button->command mappings. Buttons can be
248248
* created by instantiating a {@link GenericHID} or one of its subclasses
@@ -344,12 +344,12 @@ private void configureButtonBindings() {
344344
.deadlineWith(shooter.runVoltage(ShooterConstants.SHOOTER_FULL_VOLTAGE))
345345
.deadlineWith(indexer.manualCommand(IndexerConstants.INDEXER_IN_VOLTAGE)));
346346

347+
// add controller rumble triggers
347348
new Trigger(() -> (int) Timer.getMatchTime() == 30.0).onTrue(getRumbleDriver());
348349
new Trigger(indexer::isIntaked).onTrue(getRumbleOperator());
349350
new Trigger(this::isAimedAtSpeaker).onTrue(getRumbleDriver());
350-
351351

352-
352+
// add extra commands in tuning mode
353353
if (Constants.tuningMode) {
354354
SmartDashboard.putData("Pivot Sysid",
355355
new SequentialCommandGroup(
@@ -360,11 +360,10 @@ private void configureButtonBindings() {
360360
)
361361
);
362362
}
363-
364-
365363
}
366364

367365
public void setPivotPose3d() {
366+
// log the component positions for viewing in advantage scope
368367
Logger.recordOutput("PivotPoseThing",
369368
new Pose3d(
370369
new Translation3d(0, 0, 0.28),
@@ -386,9 +385,11 @@ public void resetRobotPose(Pose2d pose) {
386385
* @return the command to run in autonomous
387386
*/
388387
public Command getAutonomousCommand() {
388+
// make sure choosers are configured for correct alliance poses
389389
AutoChooser.setupChoosers();
390390
drive.updateDeadzoneChooser();
391391

392+
// if we are running a custom auto create one
392393
if (autoChooser.getSendableChooser().getSelected().equals("Custom")) {
393394
Command custom = MakeAutos.makeAutoCommand(
394395
drive,
@@ -399,17 +400,20 @@ public Command getAutonomousCommand() {
399400
indexer::isIntaked
400401
);
401402

403+
// add auto wait if needed
402404
if (autoWait.get() > 0) {
403405
return new WaitCommand(autoWait.get()).andThen(custom);
404406
}
405407

406408
return custom;
407409
}
408410

411+
// add auto wait if needed
409412
if (autoWait.get() > 0) {
410413
return new WaitCommand(autoWait.get()).andThen(autoChooser.get());
411414
}
412415

416+
// get path planner auto
413417
return autoChooser.get();
414418
}
415419

@@ -427,6 +431,9 @@ public Command joystickAmpPoint() {
427431
);
428432
}
429433

434+
/*
435+
* Compound Commands
436+
*/
430437
public Command zeroPosition() {
431438
return pivot.bringDownCommand()
432439
.deadlineWith(
@@ -462,14 +469,6 @@ public Command altShootAnywhere() {
462469
DRIVE_STRAFE));
463470
}
464471

465-
public boolean isPointedAtSpeaker() {
466-
return DriveCommands.pointedAtSpeaker(drive);
467-
}
468-
469-
public boolean isAimedAtSpeaker() {
470-
return DriveCommands.pointedAtSpeaker(drive) && pivot.atSetpoint();
471-
}
472-
473472
public Command shootAnywhere() {
474473
return (new WaitUntilCommand(this::isPointedAtSpeaker).andThen(shootNote()))
475474
.deadlineWith(lockOnSpeakerFull());
@@ -545,13 +544,9 @@ public Command shootNote() {
545544
.withTimeout(1.9));//.alongWith(new InstantCommand(() -> {NoteVisualizer.shoot().schedule();})); // run the visualizer
546545
}
547546

548-
/* // Brings the note forward and back for 0.5 seconds each to center it
549-
public Command intakeShimmyCommand() {
550-
return (indexer.manualCommand(IndexerConstants.INDEXER_IN_VOLTAGE)
551-
.alongWith(groundIntake.manualCommand(GroundIntakeConstants.GROUND_INTAKE_IN_VOLTAGE)))
552-
.withTimeout(ShooterConstants.SHOOTER_SPINUP_TIME)
553-
.andThen(indexer.manualCommand(IndexerConstants.INDEXER_OUT_VOLTAGE).withTimeout(ShooterConstants.SHOOTER_SPINUP_TIME));
554-
} */
547+
public Command intakeUntilIntaked(){
548+
return indexer.IntakeLoopCommand(IndexerConstants.INDEXER_IN_VOLTAGE_WEAK).deadlineWith(groundIntake.manualCommand(GroundIntakeConstants.GROUND_INTAKE_IN_VOLTAGE)).deadlineWith(shooter.runVoltage(0));
549+
}
555550

556551
// Returns the estimated transformation over the next tick (The change in
557552
// position)
@@ -573,20 +568,30 @@ private double getEstimatedDistance() {
573568
return targetTransform.getTranslation().getNorm();
574569
}
575570

576-
// Gets RPM based on distance from speaker, taking into account the actual
577-
// shooting position
578-
/* private double getRPM() {
579-
return Lookup.getRPM(getEstimatedDistance());
580-
} */
571+
@AutoLogOutput(key = "PointedAtSpeaker")
572+
public boolean isPointedAtSpeaker() {
573+
return DriveCommands.pointedAtSpeaker(drive);
574+
}
575+
576+
@AutoLogOutput(key = "AimedAtSpeaker")
577+
public boolean isAimedAtSpeaker() {
578+
return DriveCommands.pointedAtSpeaker(drive) && pivot.atSetpoint();
579+
}
580+
581581

582582
// Gets angle based on distance from speaker, taking into account the actual
583583
// shooting position
584+
@AutoLogOutput(key = "ShootAnywhereAngle")
584585
private double getAngle() {
585586
double angle = Lookup.getAngle(getEstimatedDistance());
586587
Logger.recordOutput("ShootAnywhereAngle", angle);
587588
return angle;
588589
}
589590

591+
/*
592+
* Other Periodic Methods
593+
*/
594+
590595
public void LEDPeriodic() {
591596
BlinkinLEDController.isEndgame = DriverStation.getMatchTime() <= 30;
592597
BlinkinLEDController.isEnabled = DriverStation.isEnabled();
@@ -598,26 +603,22 @@ public void LEDPeriodic() {
598603

599604
public void disabledPeriodic() {
600605
LEDPeriodic();
601-
if (BrakeMode.get() != brakeMode) {
606+
if (brakeModeDashboard.get() != brakeMode) {
602607
brakeMode = !brakeMode;
603608
pivot.setBrake(brakeMode);
604609
}
605610

606-
if (SetStartPosition.get()) {
611+
if (setStartPosition.get()) {
607612
AutoChooser.setupChoosers();
608613
drive.updateDeadzoneChooser();
609614
resetRobotPose(AutoChooser.getStartPose());
610-
SetStartPosition.set(false);
615+
setStartPosition.set(false);
611616
}
612617

613618
setPivotPose3d();
614619
field.setRobotPose(drive.getPose());
615620
Logger.recordOutput("DriveAimed", DriveCommands.pointedAtSpeaker(drive));
616621
Logger.recordOutput("PivotAimed", pivot.atSetpoint());
617622
}
618-
619-
public Command intakeUntilIntaked(){
620-
return indexer.IntakeLoopCommand(IndexerConstants.INDEXER_IN_VOLTAGE_WEAK).deadlineWith(groundIntake.manualCommand(GroundIntakeConstants.GROUND_INTAKE_IN_VOLTAGE)).deadlineWith(shooter.runVoltage(0));
621-
}
622623

623624
}

src/main/java/frc/robot/commands/DriveCommands.java

+5-6
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.util.function.Supplier;
2323

2424
import org.littletonrobotics.junction.Logger;
25+
import org.littletonrobotics.junction.networktables.LoggedDashboardBoolean;
2526

2627
import edu.wpi.first.math.MathUtil;
2728
import edu.wpi.first.math.controller.PIDController;
@@ -45,12 +46,10 @@ public class DriveCommands {
4546
private static double slowMode = 1;
4647
// kSlowModeConstant;
4748

48-
private static PIDController angleController = new PIDController(kTurnSpeakerP,
49-
kTurnSpeakerI, kTurnSpeakerD);
50-
51-
private DriveCommands() {
52-
}
49+
private static PIDController angleController = new PIDController(kTurnSpeakerP, kTurnSpeakerI, kTurnSpeakerD);
50+
private static LoggedDashboardBoolean shootSide = new LoggedDashboardBoolean("ShootSide", false);
5351

52+
5453
/**
5554
* Field relative drive command using two joysticks (controlling linear and
5655
* angular velocities).
@@ -347,7 +346,7 @@ public static boolean pointedAtSpeaker(Drive drive) {
347346
}
348347

349348
public static boolean getPivotSideAngle() {
350-
if (SmartDashboard.getBoolean("ShootSide", false)) {
349+
if (shootSide.get()) {
351350
return false;
352351
}
353352
return true;

src/main/java/frc/robot/subsystems/drive/Drive.java

+5-35
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
import org.littletonrobotics.junction.AutoLogOutput;
2828
import org.littletonrobotics.junction.Logger;
29+
import org.littletonrobotics.junction.networktables.LoggedDashboardBoolean;
2930

3031
import com.pathplanner.lib.auto.AutoBuilder;
3132
import com.pathplanner.lib.path.GoalEndState;
@@ -51,7 +52,6 @@
5152
import edu.wpi.first.math.numbers.N3;
5253
import edu.wpi.first.wpilibj.DriverStation;
5354
import edu.wpi.first.wpilibj.DriverStation.Alliance;
54-
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
5555
import edu.wpi.first.wpilibj.Timer;
5656
import edu.wpi.first.wpilibj2.command.Command;
5757
import edu.wpi.first.wpilibj2.command.SubsystemBase;
@@ -107,6 +107,8 @@ public class Drive extends SubsystemBase {
107107

108108
private DeadzoneChooser deadzoneChooser = new DeadzoneChooser("Deadzone");
109109

110+
private LoggedDashboardBoolean useVisionDashboard = new LoggedDashboardBoolean("UseVision", true);
111+
110112
public Drive(
111113
GyroIO gyroIO,
112114
ModuleIO flModuleIO,
@@ -174,7 +176,7 @@ public Drive(
174176

175177
}, null, this));
176178

177-
SmartDashboard.putBoolean("UseVision", useVision);
179+
useVisionDashboard.set(useVision);
178180
}
179181

180182
public void periodic() {
@@ -186,7 +188,7 @@ public void periodic() {
186188
odometryLock.unlock();
187189
Logger.processInputs("Drive/Gyro", gyroInputs);
188190

189-
if (SmartDashboard.getBoolean("UseVision", useVision)) {
191+
if (useVisionDashboard.get()) {
190192
visionIO.updateInputs(visionInputs, getPose());
191193
Logger.processInputs("Vision", visionInputs);
192194
if (visionInputs.hasEstimate) {
@@ -448,36 +450,4 @@ public Command pathfindToTrajectory(PathPlannerPath path) {
448450
return AutoBuilder.pathfindThenFollowPath(path, kPathConstraints);
449451
}
450452

451-
public Command goToThaPose(Pose2d endPose) {
452-
List<Translation2d> bezierPoints = PathPlannerPath.bezierFromPoses(
453-
getPose(),
454-
endPose
455-
);
456-
457-
// Create the path using the bezier points created above
458-
PathPlannerPath path = new PathPlannerPath(
459-
bezierPoints,
460-
kPathConstraints, // The constraints for this path. If using a differential drivetrain, the angular constraints have no effect.
461-
new GoalEndState(0.0, Rotation2d.fromDegrees(-90)) // Goal end state. You can set a holonomic rotation here. If using a differential drivetrain, the rotation will have no effect.
462-
);
463-
return AutoBuilder.followPath(path);
464-
}
465-
466-
public Translation2d FindMidPose(Pose2d start, Pose2d end){
467-
return new Translation2d((start.getX()+end.getX())/2, (start.getY()+end.getY())/2);
468-
}
469-
470-
public Command driveFromPoseToPose(Pose2d start, Pose2d end) {
471-
return AutoBuilder.followPath(
472-
PathPlannerPath.fromPathPoints(
473-
List.of(
474-
new PathPoint(start.getTranslation(), new RotationTarget(0, start.getRotation(), true)),
475-
new PathPoint(FindMidPose(start, end), new RotationTarget(0, start.getRotation(), true)),
476-
new PathPoint(FindMidPose(new Pose2d(FindMidPose(start, end), new Rotation2d()), end), new RotationTarget(0, start.getRotation(), true)),
477-
new PathPoint(end.getTranslation(), new RotationTarget(0, end.getRotation(), true))
478-
),
479-
kPathConstraints,
480-
new GoalEndState(0, end.getRotation())));
481-
}
482-
483453
}

src/main/java/frc/robot/subsystems/drive/GyroIOReal.java

-14
Original file line numberDiff line numberDiff line change
@@ -212,20 +212,6 @@ public boolean navXConnected() {
212212
return navx.isConnected();
213213
}
214214

215-
/**
216-
* Displays the angles on {@code SmartDashboard}.
217-
*/
218-
public void outputValues() {
219-
SmartDashboard.putNumber("/Gyro/Yaw Angle", getYawAngle());
220-
SmartDashboard.putNumber("/Gyro/Roll Angle", getRollAngle());
221-
SmartDashboard.putNumber("/Gyro/Pitch Angle", getPitchAngle());
222-
223-
SmartDashboard.putNumber("Robot Angle", getRobotAngle());
224-
SmartDashboard.putNumber("Robot Angle Vel", getRobotAngleVelocity());
225-
// SmartDashboard.putNumber("Tilt Angle", getTiltAngle());
226-
SmartDashboard.putBoolean("Gyro Connected", navXConnected());
227-
}
228-
229215
public static GyroIOReal getInstance() {
230216
if (instance == null) {
231217
instance = new GyroIOReal();

0 commit comments

Comments
 (0)