Skip to content

Commit 05590ec

Browse files
committed
2 parents 1e0c44e + f5c45a0 commit 05590ec

File tree

5 files changed

+111
-13
lines changed

5 files changed

+111
-13
lines changed

src/main/java/wmironpatriots/Robot.java

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ public Robot() {
225225

226226
// // * ELEVATOR LEVEL 3 COMMAND
227227
operatorController
228-
.b()
228+
.y()
229229
.whileTrue(
230230
tail.setTargetPoseCmmd(Tail.POSE_MOVE_ANGLE)
231231
.until(() -> tail.inSetpointRange() && elevator.inSetpointRange())
@@ -235,11 +235,11 @@ public Robot() {
235235

236236
// // * ELEVATOR LEVEL 4 COMMAND
237237
operatorController
238-
.y()
238+
.b()
239239
.whileTrue(
240240
tail.setTargetPoseCmmd(Tail.POSE_MOVE_ANGLE)
241241
.until(() -> tail.inSetpointRange() && elevator.inSetpointRange())
242-
.andThen(tail.setTargetPoseCmmd(Tail.POSE_L4)))
242+
.andThen(tail.setTargetPoseCmmd(Tail.POSE_L4).until(joystick.leftBumper()).andThen(tail.setTargetPoseCmmd(Tail.POSE_IN_ANGLE))))
243243
.whileTrue(
244244
elevator.setTargetPoseCmmd(Elevator.POSE_L4).onlyIf(() -> tail.inSetpointRange()));
245245

@@ -253,6 +253,16 @@ public Robot() {
253253
.whileFalse(tail.setRollerSpeedCmmd(0))
254254
.whileFalse(chute.runChuteSpeedCmmd(0.0));
255255

256+
// * AUTO CENTERING COMMAND
257+
258+
operatorController
259+
.povRight()
260+
.onTrue(
261+
tail.setRollerSpeedCmmd(.5)
262+
.alongWith(chute.runChuteSpeedCmmd(-.1))
263+
.until(() -> tail.beamTripped = true)
264+
.andThen(tail.setRollerTimecmmd(.5, 1)).alongWith(chute.runChuteSpeedCmmd(0)));
265+
256266
// // * OUTTAKING CORAL COMMAND
257267
operatorController
258268
.rightBumper()
@@ -269,6 +279,42 @@ public Robot() {
269279
.whileTrue(tail.setRollerSpeedCmmd(Tail.OUTPUTTING_SPEEDS))
270280
.onFalse(tail.setRollerSpeedCmmd(0.0));
271281

282+
// * ALGAE DESCORING
283+
284+
operatorController
285+
.povUp()
286+
.whileTrue(
287+
tail.setRollerSpeedCmmd(1)
288+
.alongWith(
289+
tail.setTargetPoseCmmd(Tail.POSE_MOVE_ANGLE)
290+
.until(() -> tail.inSetpointRange() && elevator.inSetpointRange())
291+
.andThen(tail.setTargetPoseCmmd(Tail.POSE_ALGAE_HIGH))))
292+
.whileTrue(
293+
elevator
294+
.setTargetPoseCmmd(Elevator.POSE_ALGAE_HIGH)
295+
.onlyIf(() -> tail.inSetpointRange()))
296+
.whileFalse(tail.setRollerSpeedCmmd(0));
297+
298+
operatorController
299+
.povDown()
300+
.whileTrue(
301+
tail.setRollerSpeedCmmd(1)
302+
.alongWith(
303+
tail.setTargetPoseCmmd(Tail.POSE_MOVE_ANGLE)
304+
.until(() -> tail.inSetpointRange() && elevator.inSetpointRange())
305+
.andThen(tail.setTargetPoseCmmd(Tail.POSE_ALGAE_LOW))))
306+
.whileTrue(
307+
elevator
308+
.setTargetPoseCmmd(Elevator.POSE_ALGAE_LOW)
309+
.onlyIf(() -> tail.inSetpointRange()))
310+
.whileFalse(tail.setRollerSpeedCmmd(0));
311+
312+
operatorController
313+
.povDown()
314+
.whileTrue(
315+
tail.setTargetPoseCmmd(Tail.POSE_ALGAE_LOW).alongWith(tail.setRollerSpeedCmmd(1)))
316+
.whileFalse(tail.setRollerSpeedCmmd(0));
317+
272318
// * SUPERSTRUCTURE INIT
273319
Map<Requests, Trigger> triggerMap = new HashMap<Superstructure.Requests, Trigger>();
274320

@@ -308,7 +354,7 @@ private void configureBindings() {
308354
* MaxAngularRate) // Drive counterclockwise with negative X (left)
309355
));
310356

311-
joystick.a().whileTrue(drivetrain.applyRequest(() -> brake));
357+
//joystick.a().whileTrue(drivetrain.applyRequest(() -> brake));
312358
joystick
313359
.b()
314360
.whileTrue(
@@ -325,7 +371,7 @@ private void configureBindings() {
325371
// joystick.povUp().and(joystick.x()).whileTrue(drivetrain.sysIdQuasistatic(Direction.kReverse));
326372

327373
// reset the field-centric heading on left bumper press
328-
joystick.leftBumper().onTrue(drivetrain.runOnce(() -> drivetrain.seedFieldCentric()));
374+
joystick.a().onTrue(drivetrain.runOnce(() -> drivetrain.seedFieldCentric()));
329375

330376
drivetrain.registerTelemetry(logger::telemeterize);
331377
}

src/main/java/wmironpatriots/subsystems/elevator/Elevator.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,13 @@ public abstract class Elevator extends SubsystemBase implements Logged {
2828
public static final double POSE_MAX_CARRIAGE_STAGE_ONE = 1.39903980829;
2929

3030
public static final double POSE_L1 = 0.0;
31-
public static final double POSE_L2 = 3.16;
32-
public static final double POSE_L3 = 7;
31+
public static final double POSE_L2 = (5.5 / 0.87835 / 3.14159 / 2 * 3); // 3.16;
32+
public static final double POSE_L3 = (13.5 / 0.87835 / 3.14159 / 2 * 3); // 7;
3333
public static final double POSE_L4 = 12.75;
3434

35+
public static final double POSE_ALGAE_HIGH = (10.5 / 0.87835 / 3.14159 / 2 * 3);
36+
public static final double POSE_ALGAE_LOW = (2.5 / 0.87835 / 3.14159 / 2 * 3);
37+
3538
// Visualizer constants
3639
public static final double MAX_ELEVATOR_HEIGHT_INCHES = 57;
3740
public static final double STAGE_ZERO_HEIGHT_INCHES = 32;

src/main/java/wmironpatriots/subsystems/tail/Tail.java

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
package wmironpatriots.subsystems.tail;
88

9+
import edu.wpi.first.wpilibj.Timer;
910
import edu.wpi.first.wpilibj2.command.Command;
1011
import monologue.Annotations.Log;
1112
import wmironpatriots.util.mechanismUtil.LoggedSubsystem;
@@ -27,9 +28,12 @@ public abstract class Tail implements LoggedSubsystem {
2728
public static final double POSE_MOVE_ANGLE = 8.2;
2829

2930
public static final double POSE_L1 = 5.56;
30-
public static final double POSE_L2 = 5;
31-
public static final double POSE_L3 = 5.56;
32-
public static final double POSE_L4 = 4;
31+
public static final double POSE_L2 = (20 * 5 / 36); // 5;
32+
public static final double POSE_L3 = (20 * 5 / 36); // 5.56;
33+
public static final double POSE_L4 = (30 * 5 / 36); // 4;
34+
35+
public static final double POSE_ALGAE_HIGH = (70 * 5 / 36); // uses formula
36+
public static final double POSE_ALGAE_LOW = (70 * 5 / 36); // uses formula
3337

3438
// Roller speeds
3539
public static final double INTAKING_SPEEDS = 2;
@@ -48,7 +52,7 @@ public abstract class Tail implements LoggedSubsystem {
4852
@Log protected boolean pivotMotorOk = false;
4953
@Log protected boolean rollerMotorOk = false;
5054

51-
@Log protected boolean beamTriggered = false;
55+
@Log public boolean beamTripped = true;
5256

5357
@Log protected double pivotSetpointRevs;
5458
@Log protected double pivotPoseRevs;
@@ -60,6 +64,8 @@ public abstract class Tail implements LoggedSubsystem {
6064
@Log protected double rollerAppliedVolts;
6165
@Log protected double rollerSupplyCurrentAmps;
6266

67+
Timer timer = new Timer();
68+
6369
/** Runs target position in radians from current zeroed pose */
6470
public Command setTargetPoseCmmd(double poseRes) {
6571
return this.run(
@@ -77,6 +83,17 @@ public Command setRollerSpeedCmmd(double speed) {
7783
});
7884
}
7985

86+
public Command setRollerTimecmmd(double speed, double time){
87+
return this.run(()->{
88+
runRollerSpeed(speed);
89+
timer.reset();
90+
timer.start();
91+
if (timer.hasElapsed(1)){
92+
runRollerSpeed(0);
93+
}
94+
});
95+
}
96+
8097
/** Zeroes tail pivot at current pose */
8198
public Command zeroPoseCmmd() {
8299
return this.run(
@@ -99,6 +116,13 @@ public Command runPoseZeroingCmmd() {
99116
});
100117
}
101118

119+
public Command setRollerPositionCommand(double revs) {
120+
return this.run(
121+
() -> {
122+
setRollerPosition(revs);
123+
});
124+
}
125+
102126
/** Stop all elevator motor input */
103127
public Command stopMotorInputCmmd() {
104128
return this.runOnce(() -> runPivotVolts(0.0));
@@ -126,7 +150,7 @@ public boolean inSetpointRange() {
126150

127151
/** Checks if both tail beambreaks are triggered */
128152
public boolean hasCoral() {
129-
return beamTriggered;
153+
return beamTripped;
130154
}
131155

132156
/** HARDWARE METHODS */
@@ -139,6 +163,8 @@ public boolean hasCoral() {
139163
/** Run roller motor with speed request */
140164
protected abstract void runRollerSpeed(double speed);
141165

166+
protected abstract void setRollerPosition(double revs);
167+
142168
/** Reset encoder to specific pose in rads */
143169
protected abstract void setEncoderPose(double poseRevs);
144170

src/main/java/wmironpatriots/subsystems/tail/TailIOComp.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,23 @@
1414
import com.ctre.phoenix6.signals.FeedbackSensorSourceValue;
1515
import com.ctre.phoenix6.signals.InvertedValue;
1616
import com.ctre.phoenix6.signals.NeutralModeValue;
17+
import com.revrobotics.RelativeEncoder;
1718
import com.revrobotics.spark.SparkBase.PersistMode;
1819
import com.revrobotics.spark.SparkBase.ResetMode;
1920
import com.revrobotics.spark.SparkLowLevel.MotorType;
2021
import com.revrobotics.spark.SparkMax;
2122
import com.revrobotics.spark.config.SparkBaseConfig.IdleMode;
2223
import com.revrobotics.spark.config.SparkMaxConfig;
24+
import edu.wpi.first.wpilibj.DigitalInput;
2325

2426
public class TailIOComp extends Tail {
2527
private final TalonFX pivot;
2628
private final SparkMax roller;
2729

30+
private final RelativeEncoder encoder;
31+
32+
private final DigitalInput beam;
33+
2834
private final TalonFXConfiguration pivotConf;
2935
private final SparkMaxConfig rollerConf;
3036

@@ -37,6 +43,10 @@ public TailIOComp() {
3743
pivot = new TalonFX(13, "rio");
3844
roller = new SparkMax(1, MotorType.kBrushless);
3945

46+
beam = new DigitalInput(8);
47+
48+
encoder = roller.getEncoder();
49+
4050
pivotConf = new TalonFXConfiguration();
4151
pivotConf.MotorOutput.NeutralMode = NeutralModeValue.Brake;
4252
pivotConf.MotorOutput.Inverted = InvertedValue.CounterClockwise_Positive;
@@ -72,6 +82,8 @@ public TailIOComp() {
7282
public void periodic() {
7383
pivotMotorOk = BaseStatusSignal.refreshAll(sigPose, sigVel, sigVolts, sigCurrent).isOK();
7484

85+
beamTripped = !beam.get();
86+
7587
pivotPoseRevs = sigPose.getValueAsDouble();
7688
pivotVelRPM = sigPose.getValueAsDouble();
7789
pivotAppliedVolts = sigVolts.getValueAsDouble();
@@ -96,6 +108,10 @@ protected void runRollerSpeed(double speed) {
96108
roller.setVoltage(speed);
97109
}
98110

111+
protected void setRollerPosition(double poseRevs) {
112+
encoder.setPosition(poseRevs);
113+
}
114+
99115
@Override
100116
protected void setEncoderPose(double poseRevs) {
101117
pivot.setPosition(poseRevs);

src/main/java/wmironpatriots/subsystems/tail/TailIOSim.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@ public void periodic() {
4545
pivotMotorOk = true;
4646
rollerMotorOk = true;
4747

48-
beamTriggered = true;
48+
beamTripped = true;
4949

50+
5051
pivotPoseRevs = tailSim.getAngleRads();
5152
pivotVelRPM = Units.radiansPerSecondToRotationsPerMinute(tailSim.getAngleRads());
5253
pivotAppliedVolts = pivotInputVoltage;
@@ -83,4 +84,10 @@ protected void stopRollers() {} // no rollers
8384

8485
@Override
8586
protected void pivotCoastingEnabled(boolean enabled) {} // Sim motors can't coast
87+
88+
@Override
89+
protected void setRollerPosition(double revs) {
90+
// TODO Auto-generated method stub
91+
throw new UnsupportedOperationException("Unimplemented method 'setRollerPosition'");
92+
}
8693
}

0 commit comments

Comments
 (0)