Skip to content

Commit d72a06d

Browse files
committed
Fixing loop to command
1 parent a9e7d2a commit d72a06d

File tree

9 files changed

+39
-105
lines changed

9 files changed

+39
-105
lines changed

src/main/java/frc/robot/FieldConstants.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ public class FieldConstants {
3535
public static final class StagingLocations {
3636
public static double centerlineX = fieldLength / 2.0;
3737
// TODO: FIX THIS
38-
public static final double stagingThreshold = 0;
39-
public static final double ampThreshold = 0;
38+
public static final double stagingThreshold = 5;
39+
public static final double ampThreshold = 5;
4040

4141
// need to update
4242
public static double centerlineFirstY = Units.inchesToMeters(29.638);

src/main/java/frc/robot/commands/elevator/AmpPlaceCommand.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
package frc.robot.commands.elevator;
22

3-
import static frc.robot.Constants.ElevatorConstants.*;
3+
import static frc.robot.Constants.ScoringConstants.*;
44
import static frc.robot.Constants.WristConstants.*;
55

66
import edu.wpi.first.wpilibj2.command.SequentialCommandGroup;
77
import frc.robot.commands.shooter.ShootAtAngleCommand;
8-
import frc.robot.commands.wrist.WristToPositionCommand;
98
import frc.robot.subsystems.elevator.ElevatorSubsystem;
109
import frc.robot.subsystems.shooter.ShooterSubsystem;
1110
import frc.robot.subsystems.transport.TransportSubsystem;
@@ -27,8 +26,8 @@ public AmpPlaceCommand(
2726
this.wristSubsystem = wristSubsystem;
2827
this.transportSubsystem = transportSubsystem;
2928
addCommands(
30-
new ElevatorToPositionCommand(elevatorSubsystem, ELEVATOR_AMP_POS),
31-
new WristToPositionCommand(wristSubsystem, WRIST_AMP_POSITION),
29+
elevatorSubsystem.setElevatorPositionCommand(AMP_ELEVATOR_HEIGHT),
30+
wristSubsystem.setPosiitonCommand(WRIST_AMP_POSITION),
3231
new ShootAtAngleCommand(
3332
shooterSubsystem, transportSubsystem, wristSubsystem, WRIST_AMP_POSITION));
3433
}

src/main/java/frc/robot/commands/elevator/ElevatorToPositionCommand.java

Lines changed: 0 additions & 34 deletions
This file was deleted.

src/main/java/frc/robot/commands/elevator/ElevatorWristParallelCommand.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
package frc.robot.commands.elevator;
22

3-
import static frc.robot.Constants.ElevatorConstants.*;
43
import static frc.robot.Constants.WristConstants.*;
54

65
import edu.wpi.first.wpilibj2.command.ParallelCommandGroup;
7-
import frc.robot.commands.wrist.WristToPositionCommand;
86
import frc.robot.subsystems.elevator.ElevatorSubsystem;
97
import frc.robot.subsystems.wrist.WristSubsystem;
108

@@ -18,7 +16,7 @@ public ElevatorWristParallelCommand(
1816
this.wristSubsystem = wristSubsystem;
1917

2018
addCommands(
21-
new WristToPositionCommand(wristSubsystem, WRIST_MIN),
22-
new ElevatorToPositionCommand(elevatorSubsystem, 0));
19+
wristSubsystem.setPosiitonCommand(WRIST_MIN),
20+
elevatorSubsystem.setElevatorPositionCommand(0));
2321
}
2422
}

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import edu.wpi.first.math.geometry.Rotation2d;
66
import edu.wpi.first.wpilibj2.command.ParallelCommandGroup;
7-
import frc.robot.commands.wrist.WristToPositionCommand;
87
import frc.robot.subsystems.shooter.ShooterSubsystem;
98
import frc.robot.subsystems.wrist.WristSubsystem;
109

@@ -19,7 +18,6 @@ public RunWristAndFlywheels(
1918
this.shooterSubsystem = shooterSubsystem;
2019

2120
addCommands(
22-
new WristToPositionCommand(wristSubsystem, shootingAngle),
23-
shooterSubsystem.runFlyRPM(SHOOTING_RPM));
21+
wristSubsystem.setPosiitonCommand(shootingAngle), shooterSubsystem.runFlyRPM(SHOOTING_RPM));
2422
}
2523
}

src/main/java/frc/robot/commands/wrist/WristToPositionCommand.java

Lines changed: 0 additions & 38 deletions
This file was deleted.

src/main/java/frc/robot/subsystems/elevator/ElevatorSubsystem.java

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,18 @@ private void configMotors() {
7777
() -> elevatorEncoder.setVelocityConversionFactor(METERS_PER_REV / 60),
7878
() -> elevatorEncoder.getVelocityConversionFactor() == METERS_PER_REV / 60,
7979
MiscConstants.CONFIGURATION_ATTEMPTS);
80-
faultInitializing |= RaiderUtils.applyAndCheckRev(elevatorMotor::burnFlashWithDelay, () -> true, MiscConstants.CONFIGURATION_ATTEMPTS);
80+
faultInitializing |=
81+
RaiderUtils.applyAndCheckRev(
82+
elevatorMotor::burnFlashWithDelay, () -> true, MiscConstants.CONFIGURATION_ATTEMPTS);
8183

82-
elevatorEventEntry.append("Elevator motor initialized" + (faultInitializing ? " with faults" : ""));
84+
elevatorEventEntry.append(
85+
"Elevator motor initialized" + (faultInitializing ? " with faults" : ""));
8386
elevatorAlert.set(faultInitializing);
8487
}
8588

8689
public void atBottomLimit() {
8790
if (bottomLimit.get()) {
88-
leftMotor.setPosition(0);
91+
elevatorEncoder.setPosition(0);
8992
}
9093
}
9194

@@ -99,19 +102,19 @@ public boolean atGoal() {
99102
}
100103

101104
public void setEncoderPosition(double position) {
102-
leftMotor.setPosition(position);
105+
elevatorEncoder.setPosition(position);
103106
}
104107

105108
public void setVoltage(double voltage) {
106-
leftMotor.setVoltage(voltage);
109+
elevatorMotor.setVoltage(voltage);
107110
}
108111

109112
public double getPosition() {
110-
return leftMotor.getPosition().getValue();
113+
return elevatorEncoder.getPosition();
111114
}
112115

113116
public void stopMove() {
114-
leftMotor.setVoltage(0);
117+
elevatorMotor.setVoltage(0);
115118
}
116119

117120
public Command runElevatorCommand(double voltage) {
@@ -127,22 +130,22 @@ public Command runElevatorCommand(double voltage) {
127130
}
128131

129132
public Command setElevatorPositionCommand(double position) {
130-
return this.run(() -> this.setDesiredPosition(position));
133+
return this.run(
134+
() -> {
135+
controller.setGoal(position);
136+
double feedbackOutput = controller.calculate(getPosition());
137+
TrapezoidProfile.State currentSetpoint = controller.getSetpoint();
138+
139+
setVoltage(
140+
feedbackOutput + feedforward.calculate(getPosition(), currentSetpoint.velocity));
141+
});
131142
}
132143

133144
@Override
134-
public void periodic() {
135-
double feedbackOutput = controller.calculate(getPosition());
136-
137-
TrapezoidProfile.State currentSetpoint = controller.getSetpoint();
138-
double combinedOutput = feedbackOutput + feedforward.calculate(currentSetpoint.velocity);
139-
leftMotor.setVoltage(combinedOutput);
140-
atBottomLimit();
141-
logValues();
142-
}
145+
public void periodic() {}
143146

144147
private void logValues() {
145-
leftMotor.logValues();
148+
elevatorMotor.logValues();
146149
if (FF_GAINS.hasChanged()) {
147150
feedforward = FF_GAINS.createFeedforward();
148151
}

src/main/java/frc/robot/subsystems/slapdown/SlapdownSubsystem.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,15 @@ private double getPosition() {
143143
}
144144

145145
public Command setRotationGoalCommand(Rotation2d goal) {
146-
return this.run(() -> this.setRotationGoal(goal)).until(rotationController::atGoal);
146+
return this.run(
147+
() -> {
148+
this.setRotationGoal(goal);
149+
double feedbackOutput = rotationController.calculate(getPosition());
150+
TrapezoidProfile.State currentSetpoint = rotationController.getSetpoint();
151+
152+
setRotationVoltage(
153+
feedbackOutput + rotationFF.calculate(getPosition(), currentSetpoint.velocity));
154+
});
147155
}
148156

149157
public Command setFeederVoltageCommand(double voltage) {

src/main/java/frc/robot/subsystems/wrist/WristSubsystem.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public class WristSubsystem extends SubsystemBase {
3535
"/wrist/pid", WRIST_PID_GAINS, TRAPEZOIDAL_PROFILE_GAINS);
3636

3737
private final DoubleTelemetryEntry wristVoltageReq =
38-
new DoubleTelemetryEntry("/wrist/voltage", TUNING_MODE);
38+
new DoubleTelemetryEntry("/wrist/voltage", true);
3939
private final EventTelemetryEntry wristEventEntry = new EventTelemetryEntry("/wrist/events");
4040

4141
public WristSubsystem() {

0 commit comments

Comments
 (0)