66import static edu .wpi .first .units .Units .RotationsPerSecond ;
77import static edu .wpi .first .units .Units .Volts ;
88
9+ import edu .wpi .first .math .geometry .Pose2d ;
10+ import edu .wpi .first .math .geometry .Rotation3d ;
11+ import edu .wpi .first .math .geometry .Transform3d ;
12+ import edu .wpi .first .math .interpolation .InterpolatingDoubleTreeMap ;
913import edu .wpi .first .units .measure .MutAngle ;
1014import edu .wpi .first .units .measure .MutAngularVelocity ;
1115import edu .wpi .first .units .measure .MutVoltage ;
1418import edu .wpi .first .wpilibj2 .command .Command ;
1519import edu .wpi .first .wpilibj2 .command .SubsystemBase ;
1620import edu .wpi .first .wpilibj2 .command .sysid .SysIdRoutine ;
17- import java .util .function .BooleanSupplier ;
1821import java .util .function .Supplier ;
22+ // import org.curtinfrc.frc2026.sim.BallSim;
23+ // import org.curtinfrc.frc2026.util.FieldConstants;
1924import org .littletonrobotics .junction .Logger ;
2025
2126public class HoodedShooter extends SubsystemBase {
27+ // public static final Translation2d HUB_LOCATION =
28+ // new Translation2d(
29+ // FieldConstants.Hub.topCenterPoint.getX(), FieldConstants.Hub.topCenterPoint.getY());
2230 public static final double WHEEL_DIAMETER = 0.101 ;
31+ public static final Transform3d SHOOTER_TRANSFORM =
32+ new Transform3d (0 , 0 , 1 , new Rotation3d ()); // Not confirmed
33+
34+ public static final InterpolatingDoubleTreeMap DISTANCE_TO_SHOOTER_VELOCITY =
35+ new InterpolatingDoubleTreeMap ();
36+
37+ public static final InterpolatingDoubleTreeMap DISTANCE_TO_HOOD_ANGLE =
38+ new InterpolatingDoubleTreeMap ();
2339
2440 private final HoodIO hoodIO ;
2541 private final HoodIOInputsAutoLogged hoodInputs = new HoodIOInputsAutoLogged ();
2642
2743 private final ShooterIO shooterIO ;
2844 private final ShooterIOInputsAutoLogged shooterInputs = new ShooterIOInputsAutoLogged ();
2945
46+ private final Supplier <Pose2d > robotPose ;
47+
3048 private final Alert hoodMotorDisconnectedAlert ;
3149 private final Alert hoodMotorTempAlert ;
3250 private final Alert [] shooterMotorDisconnectedAlerts = new Alert [3 ];
@@ -40,16 +58,31 @@ public class HoodedShooter extends SubsystemBase {
4058 private final SysIdRoutine sysIdRoutineHood ;
4159
4260 private boolean hoodSoftLimitedForward () {
43- return hoodInputs .positionRotations > HoodIODev .FORWARD_LIMIT_ROTATIONS - 0.1 ;
61+ return hoodInputs .positionRotations
62+ > HoodIODev .FORWARD_LIMIT_ROTATIONS - HoodIODev .LIMIT_BUFFER_ROTATIONS ;
4463 }
4564
4665 private boolean hoodSoftLimitedReverse () {
47- return hoodInputs .positionRotations < HoodIODev .REVERSE_LIMIT_ROTATIONS + 0.1 ;
66+ return hoodInputs .positionRotations
67+ < HoodIODev .REVERSE_LIMIT_ROTATIONS + HoodIODev .LIMIT_BUFFER_ROTATIONS ;
4868 }
4969
50- public HoodedShooter (HoodIO hoodIO , ShooterIO shooterIO ) {
51- this .hoodIO = hoodIO ;
70+ // public BallSim ballSim = new BallSim(0.0, new Rotation2d(0.0), new Pose3d());
71+
72+ public HoodedShooter (ShooterIO shooterIO , HoodIO hoodIO , Supplier <Pose2d > robotPose ) {
5273 this .shooterIO = shooterIO ;
74+ this .hoodIO = hoodIO ;
75+ this .robotPose = robotPose ;
76+
77+ DISTANCE_TO_SHOOTER_VELOCITY .put (3.05 , 0.0 );
78+ DISTANCE_TO_SHOOTER_VELOCITY .put (2.035 , 0.0 );
79+ DISTANCE_TO_SHOOTER_VELOCITY .put (5.474 , 0.0 );
80+ DISTANCE_TO_SHOOTER_VELOCITY .put (4.0 , 0.0 );
81+
82+ DISTANCE_TO_HOOD_ANGLE .put (3.05 , 0.0 );
83+ DISTANCE_TO_HOOD_ANGLE .put (2.035 , 0.0 );
84+ DISTANCE_TO_HOOD_ANGLE .put (5.474 , 0.0 );
85+ DISTANCE_TO_HOOD_ANGLE .put (4.0 , 0.0 );
5386
5487 this .hoodMotorDisconnectedAlert = new Alert ("Hood motor disconnected." , AlertType .kError );
5588 this .hoodMotorTempAlert =
@@ -106,8 +139,8 @@ public void periodic() {
106139 shooterIO .updateInputs (shooterInputs );
107140 Logger .processInputs ("Hood" , hoodInputs );
108141 Logger .processInputs ("Shooter" , shooterInputs );
142+ // Logger.recordOutput("Ball", ballSim.update(0.02));
109143
110- // Update alerts
111144 hoodMotorDisconnectedAlert .set (!hoodInputs .motorConnected );
112145 hoodMotorTempAlert .set (hoodInputs .motorTemperature > 60 ); // in celcius
113146 for (int motor = 0 ; motor < 3 ; motor ++) {
@@ -116,16 +149,40 @@ public void periodic() {
116149 }
117150 }
118151
119- public Command setHoodPosition (double position ) {
120- return run (() -> hoodIO .setPosition (position ));
152+ // public Command shootAtHub() { // this assumes that the robot is facing the target
153+ // return run(
154+ // () -> {
155+ // double distanceLength = HUB_LOCATION.minus(robotPose.get().getTranslation()).getNorm();
156+
157+ // double hoodAngle = DISTANCE_TO_HOOD_ANGLE.get(distanceLength);
158+ // hoodAngle = (90 / 360); // angle conversion to rotations
159+ // double shooterVelocity = DISTANCE_TO_SHOOTER_VELOCITY.get(3.04833887);
160+ // hoodIO.setPosition(hoodAngle);
161+ // // shooterIO.setVelocity(20);
162+
163+ // ballSim =
164+ // new BallSim(
165+ // shooterVelocity,
166+ // Rotation2d.fromDegrees(89),
167+ // new Pose3d(robotPose.get())
168+ // .transformBy(new Transform3d(0.2, 0.0, 0.4, Rotation3d.kZero)));
169+ // });
170+ // }
171+
172+ public Command setHoodPosition (double positionDegrees ) {
173+ return run (
174+ () -> {
175+ hoodIO .setPosition (positionDegrees / 360 );
176+ Logger .recordOutput ("ROBOERT SMILE" , positionDegrees );
177+ });
121178 }
122179
123- public Command stopHood ( ) {
124- return run (() -> hoodIO .setVoltage (0 ));
180+ public Command setHoodVoltage ( double voltage ) {
181+ return run (() -> hoodIO .setVoltage (voltage ));
125182 }
126183
127- public Command setHoodVoltage ( Supplier < Double > voltage ) {
128- return run (() -> hoodIO .setVoltage (voltage . get () ));
184+ public Command stopHood ( ) {
185+ return run (() -> hoodIO .setVoltage (0 ));
129186 }
130187
131188 public Command setShooterVoltage (double voltage ) {
@@ -136,24 +193,24 @@ public Command stopShooter() {
136193 return run (() -> shooterIO .setVoltage (0 ));
137194 }
138195
139- public Command setShooterVelocity (double velocity , BooleanSupplier useFeedforward ) {
140- return run (() -> shooterIO .setVelocity (velocity , useFeedforward ));
196+ public Command setShooterVelocity (double velocityMetresPerSecond ) {
197+ return run (() -> shooterIO .setVelocity (velocityMetresPerSecond ));
141198 }
142199
143200 public Command setHoodedShooterPositionAndVelocity (
144- double position , double velocity , BooleanSupplier useFeedforward ) {
201+ double positionDegrees , double velocityMetresPerSecond ) {
145202 return run (
146203 () -> {
147- hoodIO .setPosition (position );
148- shooterIO .setVelocity (velocity , useFeedforward );
204+ hoodIO .setPosition (positionDegrees );
205+ shooterIO .setVelocity (velocityMetresPerSecond );
149206 });
150207 }
151208
152209 public Command stopHoodedShooter () {
153210 return run (
154211 () -> {
155212 hoodIO .setVoltage (0 );
156- shooterIO .setVoltage (0 );
213+ shooterIO .setVelocity (0 );
157214 });
158215 }
159216
0 commit comments