Skip to content

Commit

Permalink
Some Lift refactors
Browse files Browse the repository at this point in the history
Changes to get the run to position working.
  • Loading branch information
rhsftc committed Oct 25, 2024
1 parent c5b695b commit 30d6680
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class Lift extends SubSystem {
private final int LIFT_HIGH = 20;

private final double LIFT_MAX_POWER = .7;
private final int LIFT_POSITION_TOLERANCE = 10;

public Lift(RobotHardware robot) {
this.robot = robot;
Expand All @@ -32,6 +33,7 @@ public void init() {
// Make sure encoder is 0 at start
robot.liftMotor.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
robot.liftMotor.setZeroPowerBehavior(DcMotor.ZeroPowerBehavior.BRAKE);
robot.liftMotor.setTargetPositionTolerance(LIFT_POSITION_TOLERANCE);
}

@Override
Expand All @@ -42,7 +44,7 @@ public void start() {
public void update() {
switch (liftState) {
case Down:
if (robot.liftMotor.getCurrentPosition() < 5) {
if (Math.abs(robot.liftMotor.getCurrentPosition() - LIFT_DOWN) < LIFT_POSITION_TOLERANCE) {
if (xPressed) {
robot.liftMotor.setTargetPosition(LIFT_DOWN);
liftState = LiftPosition.LowBasket;
Expand All @@ -55,7 +57,7 @@ public void update() {
}
break;
case LowBasket:
if (robot.liftMotor.getCurrentPosition() < 5) {
if (Math.abs(robot.liftMotor.getCurrentPosition() - LIFT_LOW) < LIFT_POSITION_TOLERANCE) {
if (aPressed) {
robot.liftMotor.setTargetPosition(LIFT_DOWN);
liftState = LiftPosition.Down;
Expand All @@ -68,18 +70,19 @@ public void update() {
}
break;
case HighBasket:
if (robot.liftMotor.getCurrentPosition() < 5) {
if (Math.abs(robot.liftMotor.getCurrentPosition() - LIFT_HIGH) < LIFT_POSITION_TOLERANCE) {
if (aPressed) {
robot.liftMotor.setTargetPosition(LIFT_DOWN);
liftState = LiftPosition.Down;
}
}
break;
break;
default:
// if get here, there is a problem
robot.liftMotor.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
robot.liftMotor.setPower(0);
liftState = LiftPosition.Down;
return;
}

robot.liftMotor.setPower(LIFT_MAX_POWER);
Expand Down

0 comments on commit 30d6680

Please sign in to comment.