Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Delay testing the encoder #41

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions src/main/java/frc/robot/subsystems/Elevator.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.littletonrobotics.junction.Logger;

import com.chopshop166.chopshoplib.PersistenceCheck;
import com.chopshop166.chopshoplib.boxes.GenericBox;
import com.chopshop166.chopshoplib.logging.LoggedSubsystem;

import edu.wpi.first.math.controller.ProfiledPIDController;
Expand All @@ -25,6 +26,7 @@ public class Elevator extends LoggedSubsystem<Data, ElevatorMap> {
final double SLOW_DOWN_COEF = 0.5;
final double LOWER_SPEED = -0.15;
final double ZEROING_SPEED = -0.1;
final int ZEROING_DELAY = 5;
double holdHeight = 0;

NetworkTableInstance instance = NetworkTableInstance.getDefault();
Expand Down Expand Up @@ -61,20 +63,23 @@ public Command move(DoubleSupplier liftSpeed) {
}

public Command zero() {
return startSafe(() -> {
final GenericBox<Integer> box = new GenericBox<>(0);
return runOnce(() -> {
getMap().motor.resetValidators();
level = ElevatorPresets.OFF;
getData().motor.setpoint = ZEROING_SPEED;

}).until(() -> getMap().motor.validate() && armSafeSub.getAsBoolean()).andThen(resetCmd());
getData().motor.setpoint = ZEROING_SPEED;
box.accept(0);
}).andThen(run(() -> {
box.accept(box.get() + 1);
}).until(() -> box.get() > ZEROING_DELAY && getMap().motor.validate() && armSafeSub.getAsBoolean()))
.andThen(safeStateCmd(), resetCmd());
}

public Command moveTo(ElevatorPresets level) {
PersistenceCheck setPointPersistenceCheck = new PersistenceCheck(30, pid::atGoal);
return runOnce(() -> {
this.level = level;
pid.reset(getElevatorHeight(), getData().liftingHeightVelocity);

this.level = level;
pid.reset(getElevatorHeight(), getData().liftingHeightVelocity);
}).andThen(run(() -> {
Logger.recordOutput("PID at goal", pid.atGoal());
})).until(() -> {
Expand Down