Skip to content

Commit 0173454

Browse files
committed
Merge remote-tracking branch 'origin/main' into auto
2 parents f96d7d7 + c136819 commit 0173454

21 files changed

Lines changed: 301 additions & 123 deletions

.idea/modules.xml

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#This file is generated by updateDaemonJvm
2+
toolchainVersion=17

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,26 @@
44

55
package frc.robot;
66

7+
import static frc.robot.config.VisionConfig.photonPoseEstimatorForward;
8+
import static frc.robot.config.VisionConfig.result;
9+
710
import edu.wpi.first.epilogue.Epilogue;
811
import edu.wpi.first.epilogue.Logged;
912
import edu.wpi.first.wpilibj.DataLogManager;
1013
import edu.wpi.first.wpilibj.DriverStation;
1114
import edu.wpi.first.wpilibj.TimedRobot;
1215
import edu.wpi.first.wpilibj2.command.Command;
1316
import edu.wpi.first.wpilibj2.command.CommandScheduler;
17+
import frc.robot.config.TunerConstants;
18+
import frc.robot.config.VisionConfig;
19+
import frc.robot.subsystems.CommandSwerveDrivetrain;
20+
import java.util.Optional;
21+
import org.photonvision.EstimatedRobotPose;
1422

1523
@Logged
1624
public class Robot extends TimedRobot {
1725
private Command m_autonomousCommand;
26+
private final CommandSwerveDrivetrain drivetrain = TunerConstants.createDrivetrain();
1827

1928
private final RobotContainer m_robotContainer;
2029

@@ -28,6 +37,19 @@ public Robot() {
2837
@Override
2938
public void robotPeriodic() {
3039
CommandScheduler.getInstance().run();
40+
Optional<EstimatedRobotPose> visionEst =
41+
VisionConfig.photonPoseEstimatorForward.estimateCoprocMultiTagPose(result);
42+
if (visionEst.isEmpty()) {
43+
visionEst = VisionConfig.photonPoseEstimatorForward.estimateLowestAmbiguityPose(result);
44+
} else {
45+
drivetrain.addVisionMeasurement(
46+
photonPoseEstimatorForward
47+
.estimateAverageBestTargetsPose(result)
48+
.get()
49+
.estimatedPose
50+
.toPose2d(),
51+
visionEst.get().timestampSeconds);
52+
}
3153
}
3254

3355
@Override

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

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import edu.wpi.first.wpilibj2.command.button.CommandXboxController;
2020
import frc.robot.commands.*;
2121
import frc.robot.config.CANMappings;
22+
import frc.robot.config.HopperConfig;
2223
import frc.robot.config.TunerConstants;
2324
import frc.robot.subsystems.*;
2425

@@ -30,19 +31,27 @@ public class RobotContainer {
3031
private Climb climb = new Climb();
3132
private Intake intake = new Intake();
3233
private Kicker kicker = new Kicker();
33-
private CommandXboxController controller = new CommandXboxController(0);
34+
private CommandXboxController controller = new CommandXboxController(1);
3435
private SwerveDriveState driveState = new SwerveDriveState();
3536
private final SendableChooser<Command> autoChooser;
37+
public static boolean isExtended = false;
3638

3739
private Command shootGroup =
3840
Commands.parallel(
3941
new KickerCommand(kicker, KickerCommand.Position.INTAKE),
40-
new HopperCommand(hopper, HopperCommand.Position.SHOOT_RETRACT),
42+
Commands.runEnd(
43+
() -> hopper.slowMove(HopperConfig.HOPPER_RETRACT_ROTATION),
44+
() -> hopper.stop(),
45+
hopper).withDeadline(Commands.waitSeconds(2)),
4146
new IntakeCommand(intake, IntakeCommand.Position.SLOW_INTAKE))
4247
.finallyDo(
4348
interrupt ->
4449
CommandScheduler.getInstance()
45-
.schedule(new HopperCommand(hopper, HopperCommand.Position.SHOOT_EXTEND)));
50+
.schedule(
51+
Commands.runEnd(
52+
() -> hopper.move(HopperConfig.HOPPER_EXTEND_ROTATION),
53+
() -> hopper.stop(),
54+
hopper).withDeadline(Commands.waitSeconds(2))));
4655

4756
public RobotContainer() {
4857
autoChooser = AutoBuilder.buildAutoChooser("Test");
@@ -75,12 +84,22 @@ private void configureBindings() {
7584
.x()
7685
.and(() -> !shootGroup.isScheduled())
7786
.toggleOnTrue(new IntakeCommand(intake, IntakeCommand.Position.INTAKE));
87+
88+
controller
89+
.povRight()
90+
.and(() -> !shootGroup.isScheduled())
91+
.toggleOnTrue(new IntakeCommand(intake, IntakeCommand.Position.OUTTAKE));
7892
// Right Stick Down = Extend/Retract Hopper
7993
controller
8094
.rightStick()
8195
.and(() -> !shootGroup.isScheduled())
82-
.onTrue(new HopperCommand(hopper, HopperCommand.Position.EXTEND_RETRACT));
83-
// Right Trigger = Climb Retract
96+
.onTrue(
97+
Commands.runEnd(
98+
() -> hopper.move(Hopper.getRotation(isExtended)), () -> hopper.stop(), hopper)
99+
.withDeadline(Commands.waitSeconds(2))
100+
.andThen(Commands.runOnce(() -> isExtended = !isExtended)));
101+
102+
// // Right Trigger = Climb Retract
84103
controller
85104
.rightTrigger()
86105
.whileTrue(new ClimbCommand(climb, ClimbCommand.Position.DIRECTIONAL_CLIMB));
@@ -104,6 +123,7 @@ private void configureBindings() {
104123
.a()
105124
.toggleOnTrue(
106125
new FlywheelCommand(flywheel, FlywheelCommand.Position.CALCULATED_SHOT, drivetrain));
126+
controller.povDown().onTrue(Commands.runOnce(() -> hopper.zero(), hopper));
107127
}
108128

109129
public Command getAutonomousCommand() {

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

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,24 +70,21 @@ public void execute() {
7070

7171
// Default driving mode
7272
case TELEOP:
73-
subsystem.applyRequest(
74-
() ->
75-
drive
76-
.withVelocityX(
77-
-leftY.getAsDouble() * MaxSpeed) // Drive forward with negative Y (forward)
78-
.withVelocityY(-leftX.getAsDouble() * MaxSpeed) // Drive left with negative X
79-
.withRotationalRate(
80-
-rightX.getAsDouble()
81-
* MaxAngularRate)); // Drive counterclockwise with negative X
82-
// System.out.println("Drivetrain: Teleop");
73+
subsystem.setControl(
74+
drive
75+
.withVelocityX(
76+
-leftY.getAsDouble() * MaxSpeed) // Drive forward with negative Y (forward)
77+
.withVelocityY(-leftX.getAsDouble() * MaxSpeed) // Drive left with negative X
78+
.withRotationalRate(
79+
-rightX.getAsDouble()
80+
* MaxAngularRate)); // Drive counterclockwise with negative X
8381
break;
8482

8583
// (Needs check) Mode for when shots are from a still position
8684
case STILL_SHOT:
8785
// make X with wheels, set wheels to brake mode
8886
applyRequest.ModuleStates = states;
8987
subsystem.setControl(applyRequest);
90-
subsystem.setControl(brakeRequest);
9188
System.out.println("Drivetrain: Still Shot Configuration");
9289
break;
9390

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import edu.wpi.first.epilogue.Logged;
44
import edu.wpi.first.wpilibj2.command.Command;
5+
import frc.robot.RobotContainer;
56
import frc.robot.config.HopperConfig;
67
import frc.robot.subsystems.Hopper;
78

@@ -15,11 +16,12 @@ public static enum Position {
1516

1617
private Hopper subsystem;
1718
private HopperCommand.Position pose;
18-
private static boolean isExtended = false;
19+
private boolean isExtended;
1920

20-
public HopperCommand(Hopper subsystem, HopperCommand.Position pose) {
21+
public HopperCommand(Hopper subsystem, HopperCommand.Position pose, boolean isExtended) {
2122
this.pose = pose;
2223
this.subsystem = subsystem;
24+
this.isExtended = isExtended;
2325

2426
addRequirements(subsystem);
2527
}
@@ -31,13 +33,15 @@ public void initialize() {
3133
// (Needs check) If hopper already extended, retract, and if hopper retracted, extend
3234
case EXTEND_RETRACT:
3335
if (isExtended) {
34-
// System.out.println("Hopper: Retracting");
36+
System.out.println("Hopper: Retracting");
3537
subsystem.move(HopperConfig.HOPPER_RETRACT_ROTATION);
36-
isExtended = false;
38+
RobotContainer.isExtended = false;
39+
System.out.println(RobotContainer.isExtended);
3740
} else {
38-
// System.out.println("Hopper: Extending");
41+
System.out.println("Hopper: Extending");
3942
subsystem.move(HopperConfig.HOPPER_EXTEND_ROTATION);
40-
isExtended = true;
43+
RobotContainer.isExtended = true;
44+
System.out.println(RobotContainer.isExtended);
4145
}
4246
break;
4347

src/main/java/frc/robot/config/FlywheelConfig.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,17 @@ public class FlywheelConfig {
2222
// Set
2323
public static final double FLYWHEEL_LEFT_MAX_CRUISE_VELOCITY = 3000;
2424
public static final double FLYWHEEL_LEFT_TARGET_ACCELERATION = 500;
25-
public static final double FLYWHEEL_LEFT_P = 10;
25+
public static final double FLYWHEEL_LEFT_P = 0.5;
2626
public static final double FLYWHEEL_LEFT_I = 0;
2727
public static final double FLYWHEEL_LEFT_D = 0;
28-
public static final double FLYWHEEL_LEFT_S = 0;
29-
public static final double FLYWHEEL_LEFT_V = 0;
28+
public static final double FLYWHEEL_LEFT_S = 0.18;
29+
public static final double FLYWHEEL_LEFT_V = 0.115;
3030
public static final double FLYWHEEL_LEFT_A = 0;
3131

3232
// Set
3333
public static final double FLYWHEEL_OUTTAKE_SPEED = 0;
34-
public static final double FLYWHEEL_HUB_SHOT_SPEED = 0;
34+
public static final double FLYWHEEL_HUB_SHOT_SPEED = 40;
3535
public static final double FLYWHEEL_TOWER_SHOT_SPEED = 0;
36-
public static final double FLYWHEEL_DEFAULT_SHOT_SPEED = 0;
36+
public static final double FLYWHEEL_DEFAULT_SHOT_SPEED = 40;
3737
public static final double FLYWHEEL_TOLERANCE = 5;
3838
}

src/main/java/frc/robot/config/HopperConfig.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,20 @@ public class HopperConfig {
88
// Set
99
public static final double HOPPER_MAX_CRUISE_VELOCITY = 3000;
1010
public static final double HOPPER_TARGET_ACCELERATION = 500;
11-
public static final double HOPPER_P = 0;
11+
public static final double HOPPER_P = 1.5;
1212
public static final double HOPPER_I = 0;
1313
public static final double HOPPER_D = 0;
14+
public static final double HOPPER_S = 0;
15+
public static final double HOPPER_V = 0;
16+
public static final double HOPPER_A = 0;
1417

15-
public static final double SLOW_HOPPER_P = 0;
18+
public static final double SLOW_HOPPER_P = 1;
1619
public static final double SLOW_HOPPER_I = 0;
1720
public static final double SLOW_HOPPER_D = 0;
1821

19-
public static final double HOPPER_TOLERANCE = 0.01;
22+
public static final double HOPPER_TOLERANCE = 0.2;
2023

2124
// Set
22-
public static final double HOPPER_EXTEND_ROTATION = 0.0;
23-
public static final double HOPPER_RETRACT_ROTATION = 0.0;
25+
public static final double HOPPER_EXTEND_ROTATION = 4.1;
26+
public static final double HOPPER_RETRACT_ROTATION = 0.1;
2427
}

src/main/java/frc/robot/config/IntakeConfig.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ public class IntakeConfig {
66
public static final double INTAKE_GEAR_RATIO = 1;
77

88
// Set
9-
public static final double INTAKE_INTAKE_SPEED = 0;
10-
public static final double INTAKE_OUTTAKE_SPEED = 0;
9+
public static final double INTAKE_INTAKE_SPEED = 4;
10+
public static final double INTAKE_OUTTAKE_SPEED = 4;
1111
public static final double INTAKE_SLOW_SPEED = 0;
1212
}

src/main/java/frc/robot/config/KickerConfig.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ public class KickerConfig {
1616
public static final double KICKER_V = 0;
1717
public static final double KICKER_A = 0;
1818

19-
public static final double KICKER_INTAKE_SPEED = 0;
20-
public static final double KICKER_OUTTAKE_SPEED = 0;
19+
public static final double KICKER_INTAKE_SPEED = 11;
20+
public static final double KICKER_OUTTAKE_SPEED = 11;
2121

2222
public static final double KICKER_FRONT_INTAKE_SPEED = 0;
2323
public static final double KICKER_FRONT_OUTTAKE_SPEED = 0;

0 commit comments

Comments
 (0)