Skip to content

Commit db1acbc

Browse files
Updates and testing
1 parent f9c49d2 commit db1acbc

File tree

15 files changed

+233
-63
lines changed

15 files changed

+233
-63
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
plugins {
22
id "java"
3-
id "edu.wpi.first.GradleRIO" version "2024.3.1"
3+
id "edu.wpi.first.GradleRIO" version "2024.3.2"
44
}
55

66
java {

src/main/deploy/pathplanner/autos/Blue-SpeakerRight-C0-C3-C8-C7-C6.auto

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"version": 1.0,
33
"startingPose": {
44
"position": {
5-
"x": 0.7693261898151704,
6-
"y": 6.568323745728334
5+
"x": 0.9454344324892869,
6+
"y": 6.454465827910569
77
},
88
"rotation": 59.0
99
},
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"version": 1.0,
3+
"startingPose": {
4+
"position": {
5+
"x": 1.2575195849614786,
6+
"y": 5.55492627078484
7+
},
8+
"rotation": 0
9+
},
10+
"command": {
11+
"type": "sequential",
12+
"data": {
13+
"commands": [
14+
{
15+
"type": "race",
16+
"data": {
17+
"commands": [
18+
{
19+
"type": "path",
20+
"data": {
21+
"pathName": "Limelight Path"
22+
}
23+
}
24+
]
25+
}
26+
}
27+
]
28+
}
29+
},
30+
"folder": "Testing Autos",
31+
"choreoAuto": false
32+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{
2+
"version": 1.0,
3+
"waypoints": [
4+
{
5+
"anchor": {
6+
"x": 1.2575195849614786,
7+
"y": 5.55492627078484
8+
},
9+
"prevControl": null,
10+
"nextControl": {
11+
"x": 2.2575195849614786,
12+
"y": 5.55492627078484
13+
},
14+
"isLocked": false,
15+
"linkedName": null
16+
},
17+
{
18+
"anchor": {
19+
"x": 2.873019197758706,
20+
"y": 5.55492627078484
21+
},
22+
"prevControl": {
23+
"x": 1.873019197758706,
24+
"y": 5.55492627078484
25+
},
26+
"nextControl": null,
27+
"isLocked": false,
28+
"linkedName": null
29+
}
30+
],
31+
"rotationTargets": [],
32+
"constraintZones": [],
33+
"eventMarkers": [],
34+
"globalConstraints": {
35+
"maxVelocity": 6.0,
36+
"maxAcceleration": 0.5,
37+
"maxAngularVelocity": 540.0,
38+
"maxAngularAcceleration": 720.0
39+
},
40+
"goalEndState": {
41+
"velocity": 0,
42+
"rotation": 0,
43+
"rotateFast": false
44+
},
45+
"reversed": false,
46+
"folder": "Tests",
47+
"previewStartingState": {
48+
"rotation": 0,
49+
"velocity": 0
50+
},
51+
"useDefaultConstraints": false
52+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ public static class ShooterPosPot {
252252
public static final double SHOOTERPOT_HALF_COURT = 13.0;
253253
public static final double SHOOTERPOT_HALF_CHAIN_COURT = 12.6;
254254

255-
public static final double SHOOTER_AT_PICKUP = 13.7;//MIN = 9.8 MAX = 10.8 //5.7
255+
public static final double SHOOTER_AT_PICKUP = 13.2;//MIN = 9.8 MAX = 10.8 //5.7
256256
public static final double SHOOTERPOS_RANGE = 0.5;
257257

258258
}

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

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import edu.wpi.first.wpilibj2.command.InstantCommand;
2626
import edu.wpi.first.wpilibj2.command.button.CommandXboxController;
2727
import frc.robot.commands.LED.LEDRunnable;
28+
import frc.robot.commands.auto.AutoLimelight;
2829
import frc.robot.commands.auto.AutoStartDelivery;
2930
import frc.robot.commands.auto.AutoStartDeliveryTemp;
3031
import frc.robot.commands.auto.AutoStartDeliveryToSensor;
@@ -97,7 +98,7 @@ public class RobotContainer {
9798
private void configureBindings() {
9899
drivetrain.registerTelemetry(logger::telemeterize);
99100
drivetrain.setDefaultCommand(new SwerveDriveCommand(drivetrain, driverJoystick, () -> getDrivetrainVelocityY(), () -> getAllianceColor()));
100-
led.setDefaultCommand(new LEDRunnable(led, ()-> intake.getIntakeSensor(), () -> delivery.getDeliveryTopSensor(), () -> shooter.getShooterUpToSpeed()).ignoringDisable(true));
101+
led.setDefaultCommand(new LEDRunnable(led, ()-> intake.getIntakeSensor(), () -> delivery.getDeliveryTopSensor(), () -> delivery.getDeliveryBottomSensor(), () -> shooter.getShooterUpToSpeed()).ignoringDisable(true));
101102

102103
//driverJoystick.back().whileTrue(new InstantCommand(() -> setMaxSpeed(Constants.Swerve.driveScale))).onFalse(new InstantCommand(() -> setMaxSpeed(1)));
103104
driverJoystick.povLeft().onTrue(new InstantCommand(() -> drivetrain.setRotationAngle(90)));
@@ -114,9 +115,9 @@ private void configureBindings() {
114115
)
115116
));
116117

117-
driverJoystick.a().whileTrue(new InstantCommand(() -> drivetrain.setVisionRotate(true))
118+
driverJoystick.a().whileTrue(new VisionRotate(drivetrain, driverJoystick, "limelight-blue", () -> allianceColor)
118119
.alongWith(new SetShooterPosByVision(shooterPot, () -> drivetrain.getPose(), () -> getAllianceColor(), () -> getDrivetrainVelocityX(), () -> delivery.getDeliveryTopSensor())));
119-
driverJoystick.a().onFalse(new InstantCommand(() -> drivetrain.setVisionRotate(false)));
120+
//driverJoystick.a().onFalse(new InstantCommand(() -> drivetrain.setVisionRotate(false)));
120121
//driverJoystick.leftStick().whileTrue(new SetShooterPosByVision(shooterPot, () -> drivetrain.getPose(), () -> getAllianceColor(), () -> getDrivetrainVelocityX(), () -> delivery.getDeliveryTopSensor()));
121122
// driverJoystick.b().onTrue(new InstantCommand(() -> delivery.engageNoteStop()));
122123
// driverJoystick.b().onFalse(new InstantCommand(() -> delivery.disengageNoteStop()));
@@ -127,12 +128,12 @@ private void configureBindings() {
127128
driverJoystick.rightBumper().onTrue(new InstantCommand(() -> drivetrain.setAngleToZero()));
128129
driverJoystick.rightBumper().onFalse(new InstantCommand(() -> drivetrain.setDriveAtAngleFalse()));
129130

130-
driverJoystick.leftTrigger().whileTrue(Commands.parallel(new HalfCourt(shooter, () -> drivetrain.getState().Pose.getY()),
131+
driverJoystick.leftTrigger().whileTrue(Commands.parallel(new HalfCourt(shooter, () -> isChainShot()),
131132
new InstantCommand(() -> drivetrain.setDriveAtAngleFalse()),
132133
new ConditionalCommand(
133134
new InstantCommand(() -> shooterPot.setSetpoint(Constants.ShooterPosPot.SHOOTERPOT_HALF_COURT)),
134135
new InstantCommand(() -> shooterPot.setSetpoint(Constants.ShooterPosPot.SHOOTERPOT_HALF_CHAIN_COURT)),
135-
() -> (drivetrain.getState().Pose.getY() >= Constants.FieldElements.cartman && drivetrain.getState().Pose.getY() <= Constants.FieldElements.longwood)
136+
() -> (isChainShot())
136137
),
137138
// new DelayedDelivery(delivery, Constants.Delivery.DELIVERY_FORWARD_SPEED, () -> shooter.getShooterUpToSpeed()),
138139
new ConditionalCommand(
@@ -192,7 +193,7 @@ private void configureBindings() {
192193
//operatorJoystick.back().whileTrue(new SetClimbSpeed(climb, () -> Utilities.deadband(operatorJoystick.getRightY(), 0.1)));
193194
//*************Operator Station *****************/
194195
//operatorStation.blueButton.onTrue(new InstantCommand(() -> climb.setClimberPosition(-65)));
195-
operatorStation.blueButton.whileTrue(new SetClimbSpeed(climb, () -> -0.6));
196+
//operatorStation.blueButton.whileTrue(new SetClimbSpeed(climb, () -> -0.6));
196197
operatorStation.whiteButton.whileTrue(new SetClimbSpeed(climb, () -> -0.6));
197198
operatorStation.yellowButton.whileTrue(new SetClimbSpeed(climb, () -> 0.6));
198199
operatorStation.blackButton.whileTrue(new InstantCommand(() -> drivetrain.setRotationAngle(getAmpRotationAngle()))
@@ -205,6 +206,7 @@ private void configureBindings() {
205206
operatorStation.clearSwitch.whileTrue(new DeliveryServoOverride(servo));
206207
operatorStation.redLeftSwitch.onTrue(new InstantCommand(() -> drivetrain.setRotationAngle(getEndgameRotationAngleLeft())));
207208
operatorStation.redRightSwitch.onTrue(new InstantCommand(() -> drivetrain.setRotationAngle(getEndgameRotationAngleRight())));
209+
operatorStation.blueButton.whileTrue(new AutoLimelight(() -> startNoteDetecton()));
208210

209211
//************* Test Joystick *****************/
210212
// testJoystick.a().onTrue(new InstantCommand(() -> climb.setClimberSetpoint(10)));
@@ -297,6 +299,8 @@ public RobotContainer() {
297299
NamedCommands.registerCommand("StopShooter", new InstantCommand(() -> shooter.setShooterDutyCycleZero()));
298300
NamedCommands.registerCommand("UseLimelight", new InstantCommand(() -> useLimelight()));
299301
NamedCommands.registerCommand("DontUseLimelight", new InstantCommand(() -> dontUseLimelight()));
302+
NamedCommands.registerCommand("AutoDetect", new AutoLimelight(() -> startNoteDetecton()));
303+
300304

301305

302306
/*
@@ -435,6 +439,26 @@ public PathPlannerPath goToAmp() {
435439
return path;
436440
}
437441

442+
public boolean isChainShot() {
443+
return drivetrain.getState().Pose.getY() >= Constants.FieldElements.cartman && drivetrain.getState().Pose.getY() <= Constants.FieldElements.longwood;
444+
}
445+
446+
public boolean startNoteDetecton() {
447+
if (allianceColor == "blue") {
448+
if (drivetrain.getState().Pose.getX() >= 5) {
449+
return true;
450+
} else {
451+
return false;
452+
}
453+
} else {
454+
if (drivetrain.getState().Pose.getX() <= 12) {
455+
return true;
456+
} else {
457+
return false;
458+
}
459+
}
460+
}
461+
438462
public boolean doWeHaveNote() {
439463
return(intake.getIntakeSensor() || delivery.getDeliveryBottomSensor() || delivery.getDeliveryTopSensor());
440464
}

src/main/java/frc/robot/commands/LED/LEDRunnable.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@
99

1010
public class LEDRunnable extends Command {
1111
private final LED led;
12-
private Supplier<Boolean> intakeSensor, deliveryTopSensor, upToSpeed;
12+
private Supplier<Boolean> intakeSensor, deliveryTopSensor, deliveryBottomSensor, upToSpeed;
1313

1414

15-
public LEDRunnable(LED led, Supplier<Boolean> intakeSensor, Supplier<Boolean> deliveryTopSensor, Supplier<Boolean> upToSpeed) {
15+
public LEDRunnable(LED led, Supplier<Boolean> intakeSensor, Supplier<Boolean> deliveryTopSensor, Supplier<Boolean> deliveryBottomSensor, Supplier<Boolean> upToSpeed) {
1616
this.led = led;
1717
this.intakeSensor = intakeSensor;
1818
this.deliveryTopSensor = deliveryTopSensor;
19+
this.deliveryBottomSensor = deliveryBottomSensor;
1920
this.upToSpeed = upToSpeed;
2021

2122
addRequirements(led);
@@ -26,7 +27,7 @@ public void execute() {
2627
led.setColor(Color.kGreen);
2728
} else if (DriverStation.isTeleopEnabled() && deliveryTopSensor.get()) {
2829
led.setColor(Color.kBlue);
29-
} else if (DriverStation.isTeleopEnabled() && intakeSensor.get()) {
30+
} else if (DriverStation.isTeleopEnabled() && (intakeSensor.get() || deliveryBottomSensor.get())) {
3031
led.setColor(Color.kRed);
3132
} else if (DriverStation.isTeleopEnabled()) {
3233
led.setColor(Color.kBlack);
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package frc.robot.commands.auto;
2+
3+
import java.util.function.Supplier;
4+
5+
import edu.wpi.first.wpilibj2.command.Command;
6+
import frc.robot.nerdyfiles.vision.LimelightHelpers;
7+
8+
public class AutoLimelight extends Command{
9+
private boolean seeNote = false;
10+
private Supplier<Boolean> startDetection;
11+
12+
public AutoLimelight(Supplier<Boolean> startDetection) {
13+
this.startDetection = startDetection;
14+
}
15+
16+
@Override
17+
public void initialize() {
18+
}
19+
20+
@Override
21+
public void execute() {
22+
if (startDetection.get()) {
23+
var lastResult = LimelightHelpers.getLatestResults("limelight-coral").targetingResults;
24+
seeNote = lastResult.valid;
25+
}
26+
}
27+
28+
@Override
29+
public void end(boolean interrupted) {
30+
}
31+
32+
@Override
33+
public boolean isFinished() {
34+
return seeNote;
35+
}
36+
}

src/main/java/frc/robot/commands/shooter/HalfCourt.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
import java.util.function.Supplier;
44

55
import edu.wpi.first.wpilibj2.command.Command;
6-
import frc.robot.Constants;
76
import frc.robot.subsystems.Shooter;
87

98
public class HalfCourt extends Command {
109
private Shooter shooter;
11-
private Supplier<Double> robotY;
10+
private Supplier<Boolean> chainShot;
1211

13-
public HalfCourt(Shooter shooter, Supplier<Double> robotY) {
12+
public HalfCourt(Shooter shooter, Supplier<Boolean> chainShot) {
1413
this.shooter = shooter;
14+
this.chainShot = chainShot;
1515
addRequirements(shooter);
1616
}
1717

@@ -22,11 +22,11 @@ public void initialize() {
2222

2323
@Override
2424
public void execute() {
25-
// if (robotY.get() >= Constants.FieldElements.cartman && robotY.get() <= Constants.FieldElements.longwood) {
26-
// shooter.halfCourtChain();
27-
// } else {
25+
if (chainShot.get()) {
2826
shooter.halfCourt();
29-
// }
27+
} else {
28+
shooter.halfCourtChain();
29+
}
3030
}
3131

3232
@Override

src/main/java/frc/robot/commands/shooterPosition/SetShooterPosByVision.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public void initialize() {
4242
} else {
4343
LimelightHelpers.setPriorityTagID("limelight-blue", 4);
4444
}
45+
4546
}
4647

4748
@Override
@@ -83,13 +84,21 @@ public void execute() {
8384
// SmartDashboard.putNumber("Shooter/New Position Setpoint", newSetpoint);
8485
// SmartDashboard.putNumber("Shooter/Mod New Position Setpoint", modNewSetpoint);
8586
// SmartDashboard.putNumber("Shooter/X Velocity", xVelocity.get());
86-
if (currentY <= Constants.FieldElements.midFieldInMeters && topSensor.get()) { //TODO
87+
if (midfield() && topSensor.get()) { //TODO
8788
shooterPosPot.setSetpoint(modNewSetpoint);
8889
} else {
8990
shooterPosPot.setSetpoint(Constants.ShooterPosPot.SHOOTER_AT_PICKUP);
9091
}
9192
}
9293

94+
public boolean midfield() {
95+
if (allianceColor.get() == "blue") {
96+
return currentY <= Constants.FieldElements.midFieldInMeters;
97+
} else {
98+
return currentY >= Constants.FieldElements.midFieldInMeters;
99+
}
100+
}
101+
93102
@Override
94103
public void end(boolean interrupted) {
95104
shooterPosPot.getAndSetSetPoint();

0 commit comments

Comments
 (0)