Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit 3e2dbf7
Author: Isha290411 <[email protected]>
Date:   Sat Oct 26 11:51:21 2024 -0500

    made the lift actually work

    hardware issues, not software

commit d21da73
Author: Isha290411 <[email protected]>
Date:   Sat Oct 26 09:57:33 2024 -0500

    Update Lift.java

    trying to fix the lift motor and state machine

commit 69533f6
Author: Isha290411 <[email protected]>
Date:   Sat Oct 26 09:44:20 2024 -0500

    Update DriverControl.java

commit 50bda32
Author: Isha290411 <[email protected]>
Date:   Thu Oct 24 19:46:29 2024 -0500

    refactored the lift code

    made sure it would work

commit 2ec1302
Author: Isha290411 <[email protected]>
Date:   Thu Oct 24 18:10:03 2024 -0500

    Update RobotAutoDriveByGyro_Linear.java
  • Loading branch information
rhsftc committed Oct 26, 2024
1 parent 30d6680 commit 499e3dc
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,12 @@ public class DriverControl extends LinearOpMode {
// Prefix any hardware functions with "robot." to access this class.
public RobotHardware robot = new RobotHardware(this);
private final Lift lift = new Lift(robot);
//TODO Add class and code for Servo control of tilt mechanism.

// Use the new FtcLib gamepad extension.
GamepadEx gamepadOne = null;

@Override
public void runOpMode() {
// Use the FtcLib gamepad extension.
GamepadEx gamepadOne = new GamepadEx(gamepad1);
robot.init();
lift.init();
Expand Down Expand Up @@ -84,6 +85,7 @@ public void runOpMode() {
lift.update();

telemetry.addData("Status", "Run Time: " + runtime);
telemetry.addData("Lift State", lift.liftState);
telemetry.addData("Lift Target", "%d", robot.liftMotor.getTargetPosition());
telemetry.addData("Lift Position", "%d", robot.liftMotor.getCurrentPosition());
telemetry.addData("Lift Power", "%6.2f", robot.liftMotor.getPower());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void init() {
rightBackDrive = myOpMode.hardwareMap.get(DcMotor.class, "rightBackDrive");

liftMotor = myOpMode.hardwareMap.get(DcMotorEx.class, "liftMotor");
liftMotor.setDirection(DcMotor.Direction.REVERSE);
liftMotor.setDirection(DcMotor.Direction.FORWARD);
liftMotor.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);

leftFrontDrive.setDirection(DcMotor.Direction.FORWARD);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@
import org.firstinspires.ftc.teamcode.enums.LiftPosition;

public class Lift extends SubSystem {
private LiftPosition liftPosition;
private LiftPosition liftState;
public LiftPosition liftState;
private RobotHardware robot;
private boolean aPressed = false;
private boolean xPressed = false;
private boolean yPressed = false;
public boolean aPressed = false;
public boolean xPressed = false;
public boolean yPressed = false;

// Encoder positions for the lift.
//TODO Test to find the proper values.
private final int LIFT_DOWN = 0;
private final int LIFT_LOW = 10;
private final int LIFT_HIGH = 20;
private final int LIFT_LOW = 384;

private final int LIFT_HIGH = 768;

private final double LIFT_MAX_POWER = .7;
private final int LIFT_POSITION_TOLERANCE = 10;
Expand All @@ -28,12 +28,10 @@ public Lift(RobotHardware robot) {

@Override
public void init() {
liftPosition = LiftPosition.Down;
liftState = liftPosition;
liftState = LiftPosition.Down;
// 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 @@ -47,11 +45,16 @@ public void update() {
if (Math.abs(robot.liftMotor.getCurrentPosition() - LIFT_DOWN) < LIFT_POSITION_TOLERANCE) {
if (xPressed) {
robot.liftMotor.setTargetPosition(LIFT_DOWN);
robot.liftMotor.setTargetPosition(LIFT_LOW);
robot.liftMotor.setMode(DcMotor.RunMode.RUN_TO_POSITION);
robot.liftMotor.setPower(LIFT_MAX_POWER);
liftState = LiftPosition.LowBasket;
}

if (yPressed) {
robot.liftMotor.setTargetPosition(LIFT_HIGH);
robot.liftMotor.setMode(DcMotor.RunMode.RUN_TO_POSITION);
robot.liftMotor.setPower(LIFT_MAX_POWER);
liftState = LiftPosition.HighBasket;
}
}
Expand All @@ -60,11 +63,15 @@ public void update() {
if (Math.abs(robot.liftMotor.getCurrentPosition() - LIFT_LOW) < LIFT_POSITION_TOLERANCE) {
if (aPressed) {
robot.liftMotor.setTargetPosition(LIFT_DOWN);
robot.liftMotor.setMode(DcMotor.RunMode.RUN_TO_POSITION);
robot.liftMotor.setPower(LIFT_MAX_POWER);
liftState = LiftPosition.Down;
}

if (yPressed) {
robot.liftMotor.setTargetPosition(LIFT_HIGH);
robot.liftMotor.setMode(DcMotor.RunMode.RUN_TO_POSITION);
robot.liftMotor.setPower(LIFT_MAX_POWER);
liftState = LiftPosition.HighBasket;
}
}
Expand All @@ -73,6 +80,8 @@ public void update() {
if (Math.abs(robot.liftMotor.getCurrentPosition() - LIFT_HIGH) < LIFT_POSITION_TOLERANCE) {
if (aPressed) {
robot.liftMotor.setTargetPosition(LIFT_DOWN);
robot.liftMotor.setMode(DcMotor.RunMode.RUN_TO_POSITION);
robot.liftMotor.setPower(LIFT_MAX_POWER);
liftState = LiftPosition.Down;
}
}
Expand All @@ -82,20 +91,14 @@ public void update() {
robot.liftMotor.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
robot.liftMotor.setPower(0);
liftState = LiftPosition.Down;
return;
}

robot.liftMotor.setPower(LIFT_MAX_POWER);
}

// Respond to gamepad inputs.
public void setProperties(boolean buttonA, boolean buttonX, boolean buttonY) {
if (buttonA) {
liftPosition = LiftPosition.Down;
} else if (buttonX) {
liftPosition = LiftPosition.LowBasket;
} else if (buttonY) {
liftPosition = LiftPosition.HighBasket;
}
aPressed = buttonA;
xPressed = buttonX;
yPressed = buttonY;
}
}

0 comments on commit 499e3dc

Please sign in to comment.