Skip to content

Commit 0a6595b

Browse files
authored
Merge pull request #27 from IgniteRobotics/faeture/launch-interface
Re-merging Faeture/launch interface
2 parents f51ca82 + 6696622 commit 0a6595b

File tree

8 files changed

+39
-44
lines changed

8 files changed

+39
-44
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import frc.robot.subsystems.drive.DrivetrainSubsystem;
2323
import frc.robot.subsystems.indexer.IndexerSubsystem;
2424
import frc.robot.subsystems.intake.IntakeSubsystem;
25+
import frc.robot.subsystems.shooter.ShooterSubsystem;
2526

2627
@Logged
2728
public class RobotContainer {
@@ -44,6 +45,9 @@ public class RobotContainer {
4445
@Logged(name = "Climber")
4546
public final ClimberSubsystem climber = new ClimberSubsystem();
4647

48+
@Logged(name = "Shooter")
49+
public final ShooterSubsystem shooter = new ShooterSubsystem();
50+
4751
private final SendableChooser<Command> autoChooser;
4852

4953
public RobotContainer() {

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,4 @@ public class DriveConstants {
3131

3232
public static final double TRANSLATION_ALIGN_KP = 0.0001;
3333
public static final double ROTATION_ALIGN_KP = 6.28;
34-
3534
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ public DrivetrainSubsystem() {
4141
applyDriveGains();
4242
configureAutoBuilder();
4343
configureCANrange();
44+
// TODO: remove. debugging.
45+
periodic();
4446
}
4547

4648
@Override

src/main/java/frc/robot/subsystems/shooter/LaunchRequestBuilder.java

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,19 @@
44

55
package frc.robot.subsystems.shooter;
66

7-
import edu.wpi.first.math.geometry.Pose3d;
87
import edu.wpi.first.math.geometry.Rotation2d;
98
import edu.wpi.first.units.measure.Angle;
109
import edu.wpi.first.units.measure.AngularVelocity;
1110
import edu.wpi.first.units.measure.LinearVelocity;
12-
import java.util.function.Supplier;
1311

1412
/** Add your docs here. */
15-
public abstract class LaunchRequestBuilder {
13+
public interface LaunchRequestBuilder {
1614

1715
public record LaunchRequest(
1816
Angle launchHoodTarget,
1917
AngularVelocity launchVelocity,
2018
LinearVelocity driveVelocity,
2119
Rotation2d driveAngle) {}
2220

23-
Supplier<Pose3d> targetPose;
24-
25-
protected LaunchRequestBuilder(Supplier<Pose3d> targetPose) {
26-
this.targetPose = targetPose;
27-
}
28-
29-
public abstract LaunchRequestBuilder getInstance(Supplier<Pose3d> targetPose);
30-
31-
public abstract LaunchRequest createLaunchRequest();
21+
public LaunchRequest createLaunchRequest();
3222
}

src/main/java/frc/robot/subsystems/shooter/MappedLauchRequestBuilder.java

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,14 @@
2626
import java.util.function.Supplier;
2727

2828
/** Add your docs here. */
29-
public class MappedLauchRequestBuilder extends LaunchRequestBuilder {
29+
public class MappedLauchRequestBuilder implements LaunchRequestBuilder {
3030

31-
private MappedLauchRequestBuilder instance;
32-
33-
private MappedLauchRequestBuilder(Supplier<Pose3d> targetPose) {
34-
super(targetPose);
35-
}
31+
private Supplier<Pose3d> targetPose;
3632

3733
private LaunchRequest currentLaunchRequest;
3834

39-
@Override
40-
public MappedLauchRequestBuilder getInstance(Supplier<Pose3d> targetPose) {
41-
if (this.instance != null) {
42-
instance = new MappedLauchRequestBuilder(targetPose);
43-
return instance;
44-
} else {
45-
this.targetPose = targetPose;
46-
return instance;
47-
}
35+
public MappedLauchRequestBuilder(Supplier<Pose3d> targetPose) {
36+
this.targetPose = targetPose;
4837
}
4938

5039
private double loopPeriodSecs = 0.02;
@@ -125,7 +114,6 @@ public MappedLauchRequestBuilder getInstance(Supplier<Pose3d> targetPose) {
125114
passingTimeOfFlightMap.put(passingMaxDistance, 0.0);
126115
}
127116

128-
@Override
129117
public LaunchRequest createLaunchRequest() {
130118

131119
boolean passing = targetPose.get().getZ() == 0.0; // target pose is the floor, so we're passing.
@@ -180,6 +168,8 @@ public LaunchRequest createLaunchRequest() {
180168
// calcuate rotation angle
181169
Rotation2d driveAngle =
182170
getDriveAngle(lookaheadPose, targetPose.get().getTranslation().toTranslation2d());
171+
// if no last drive angle, default to the robot's current pose info.
172+
if (lastDriveAngle == null) lastDriveAngle = estimatedRobotPose.getRotation();
183173

184174
// calculate hood angle
185175
double hoodAngle =

src/main/java/frc/robot/subsystems/shooter/ParabolicLaunchRequestBuilder.java

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,14 @@
1414
import java.util.function.Supplier;
1515

1616
/** Add your docs here. */
17-
public class ParabolicLaunchRequestBuilder extends LaunchRequestBuilder {
17+
public class ParabolicLaunchRequestBuilder implements LaunchRequestBuilder {
1818

19-
private ParabolicLaunchRequestBuilder instance;
19+
private Supplier<Pose3d> targetPose;
2020

2121
private ParabolicLaunchRequestBuilder(Supplier<Pose3d> targetPose) {
22-
super(targetPose);
22+
this.targetPose = targetPose;
2323
}
2424

25-
@Override
26-
public ParabolicLaunchRequestBuilder getInstance(Supplier<Pose3d> targetPose) {
27-
if (this.instance != null) {
28-
instance = new ParabolicLaunchRequestBuilder(targetPose);
29-
return instance;
30-
} else {
31-
this.targetPose = targetPose;
32-
return instance;
33-
}
34-
}
35-
36-
@Override
3725
public LaunchRequest createLaunchRequest() {
3826
double y1 = ShooterConstants.SHOOTER_HEIGHT.in(Meters);
3927
double x2 =

src/main/java/frc/robot/subsystems/shooter/ShooterConstants.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import com.ctre.phoenix6.configs.Slot0Configs;
66
import com.ctre.phoenix6.configs.SoftwareLimitSwitchConfigs;
77
import com.ctre.phoenix6.controls.DutyCycleOut;
8+
import edu.wpi.first.math.geometry.Pose3d;
9+
import edu.wpi.first.math.geometry.Rotation3d;
810
import edu.wpi.first.units.measure.Angle;
911
import edu.wpi.first.units.measure.Current;
1012
import edu.wpi.first.units.measure.Distance;
@@ -73,4 +75,19 @@ public static SoftwareLimitSwitchConfigs createHoodSoftwareLimitSwitchConfigs()
7375
public static final Distance MIN_VERTEX_DISTANCE = Inch.of(23.5);
7476
public static final Angle MIN_HOOD_ANGLE = Degrees.of(0); // TODO: Get Better Estimate
7577
public static final double OPTIMAL_ENTRY_SLOPE = -1; // TODO: Tune
78+
79+
// TODO: verify these!
80+
// funnel poses.
81+
public static final Pose3d BLUE_TARGET =
82+
new Pose3d(
83+
Distance.ofBaseUnits(4.623, Meters),
84+
Distance.ofBaseUnits(4.041, Meters),
85+
Distance.ofBaseUnits(1.435, Meters),
86+
Rotation3d.kZero);
87+
public static final Pose3d RED_TARGET =
88+
new Pose3d(
89+
Distance.ofBaseUnits(12.276, Meters),
90+
Distance.ofBaseUnits(4.041, Meters),
91+
Distance.ofBaseUnits(1.435, Meters),
92+
Rotation3d.kZero);
7693
}

src/main/java/frc/robot/subsystems/shooter/ShooterSubsystem.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ public class ShooterSubsystem extends SubsystemBase {
2222
private final TalonFX flywheelMotor;
2323
private final TalonFX hoodMotor;
2424

25+
private final LaunchRequestBuilder launchRequestBuilder;
26+
2527
@Logged(name = "Velocity Target", importance = Importance.CRITICAL)
2628
private AngularVelocity velocityTarget; // Rotations Per Second
2729

@@ -79,12 +81,15 @@ public ShooterSubsystem() {
7981
hoodMotor.getConfigurator().apply(ShooterConstants.createHoodSoftwareLimitSwitchConfigs());
8082
hoodTarget = Rotations.of(0);
8183
hoodControl = new PositionTorqueCurrentFOC(0);
84+
85+
launchRequestBuilder = new MappedLauchRequestBuilder(() -> ShooterConstants.BLUE_TARGET);
8286
}
8387

8488
@Override
8589
public void periodic() {
8690
flywheelMotor.setControl(velocityControl.withVelocity(velocityTarget.in(RotationsPerSecond)));
8791
hoodMotor.setControl(hoodControl.withVelocity(hoodTarget.in(Rotations)));
92+
launchRequestBuilder.createLaunchRequest();
8893
}
8994

9095
public Command spinFlywheelCommand() {

0 commit comments

Comments
 (0)