Skip to content

Commit

Permalink
lift runs with new code (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
Griffin9881 committed Mar 21, 2024
1 parent 80177ce commit bc2c99a
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/main/java/frc/robot/DriverJoystick.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import edu.wpi.first.wpilibj2.command.RunCommand;
import frc.robot.commands.LiftUpCommand;
import frc.robot.commands.LiftDownCommand;
import frc.robot.commands.LiftDownManualCommand;

public class DriverJoystick extends XboxController1038 {
// Subsystem Dependencies
Expand Down Expand Up @@ -94,8 +95,7 @@ private DriverJoystick() {
rightBumper.whileTrue(new LiftUpCommand());
rightTrigger.whileTrue(new LiftDownCommand());

leftBumper.and(rightBumper).whileTrue(new LiftUpCommand());
leftTrigger.and(rightTrigger).whileTrue(new LiftDownCommand());
leftTrigger.whileTrue(new LiftDownManualCommand());
}

/**
Expand Down
9 changes: 4 additions & 5 deletions src/main/java/frc/robot/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@
import edu.wpi.first.hal.DriverStationJNI;
import edu.wpi.first.math.geometry.Pose2d;
import edu.wpi.first.wpilibj.TimedRobot;
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.CommandScheduler;
import edu.wpi.first.wpilibj2.command.SequentialCommandGroup;
import edu.wpi.first.wpilibj2.command.WaitCommand;
import frc.robot.autons.Auton;
import frc.robot.autons.AutonSelector;
import frc.robot.commands.LiftDownCommand;
import frc.robot.commands.LiftDownManualCommand;
import frc.robot.commands.LiftUpCommand;
import frc.robot.constants.SwerveModuleConstants;
import frc.robot.subsystems.Dashboard;
Expand Down Expand Up @@ -73,8 +71,9 @@ public void disabledExit() {
@Override
public void autonomousInit() {
new SequentialCommandGroup(
new LiftDownCommand(),
new LiftUpCommand()).schedule();
new LiftDownManualCommand(),
new LiftUpCommand())
.schedule();
driveTrain.zeroHeading();
autonomousCommand = autonSelector.chooseAuton();
// if (DriverStation.isFMSAttached()) {
Expand Down
28 changes: 28 additions & 0 deletions src/main/java/frc/robot/commands/LiftDownManualCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package frc.robot.commands;

import edu.wpi.first.wpilibj2.command.Command;
import frc.robot.subsystems.Lift;

public class LiftDownManualCommand extends Command {
private Lift lift = Lift.getInstance();

public LiftDownManualCommand() {
addRequirements(lift);
}

@Override
public void execute() {
lift.runLeftDown();
lift.runRightDown();
}

@Override
public boolean isFinished() {
return lift.leftLowerLimitReached() && lift.rightLowerLimitReached();
}

@Override
public void end(boolean interrupted) {
lift.stopMotors();
}
}
7 changes: 7 additions & 0 deletions src/main/java/frc/robot/subsystems/Dashboard.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class Dashboard extends SubsystemBase {
private DriveTrain driveTrain = DriveTrain.getInstance();
private Scoring scoring = Scoring.getInstance();
private Vision vision = Vision.getInstance();
private Lift lift = Lift.getInstance();

// Choosers
private SendableChooser<AutonChoices> autoChooser = new SendableChooser<>();
Expand All @@ -32,6 +33,7 @@ public class Dashboard extends SubsystemBase {
// Tabs
private final ShuffleboardTab driversTab = Shuffleboard.getTab("Drivers");
private final ShuffleboardTab controlsTab = Shuffleboard.getTab("Controls");
private final ShuffleboardTab tempTab = Shuffleboard.getTab("Temp");
private final NetworkTableInstance tableInstance = NetworkTableInstance.getDefault();

// Variables
Expand Down Expand Up @@ -101,6 +103,11 @@ private Dashboard() {
.withSize(4, 3)
.withWidget(BuiltInWidgets.kField);

tempTab.add("Vert", lift.getVerticalController())
.withPosition(0, 0);
tempTab.add("Err", lift.getErrorController())
.withPosition(1, 0);

PathPlannerLogging.setLogTargetPoseCallback((pose) -> {
field.getObject("target pose").setPose(pose);
});
Expand Down
12 changes: 8 additions & 4 deletions src/main/java/frc/robot/subsystems/Lift.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ private Lift() {
leftLiftMotor.setSmartCurrentLimit(NeoMotorConstants.kMaxNeoCurrent);
rightLiftMotor.setSmartCurrentLimit(NeoMotorConstants.kMaxNeoCurrent);

leftLiftEncoder.setPositionConversionFactor(LiftConstants.encoderConversion);
rightLiftEncoder.setPositionConversionFactor(LiftConstants.encoderConversion);

leftLiftMotor.burnFlash();
rightLiftMotor.burnFlash();

Expand Down Expand Up @@ -126,7 +129,7 @@ public boolean rightRatchetUnlocked() {
private void runLeft(double speed) {
speed = MathUtil.clamp(speed, LiftConstants.downSpeed, LiftConstants.upSpeed);
if (speed > 0 && this.leftRatchetUnlocked()) {
if (!(leftLiftEncoder.getPosition() < LiftConstants.maxExtension)) {
if (leftLiftEncoder.getPosition() < LiftConstants.maxExtension) {
leftLiftMotor.set(LiftConstants.maxExtension);
} else {
leftLiftMotor.stopMotor();
Expand All @@ -144,7 +147,7 @@ private void runLeft(double speed) {
private void runRight(double speed) {
speed = MathUtil.clamp(speed, LiftConstants.downSpeed, LiftConstants.upSpeed);
if (speed > 0 && this.rightRatchetUnlocked()) {
if ((!(rightLiftEncoder.getPosition() < LiftConstants.maxExtension))) {
if (rightLiftEncoder.getPosition() < LiftConstants.maxExtension) {
rightLiftMotor.set(speed);
} else {
rightLiftMotor.stopMotor();
Expand Down Expand Up @@ -200,6 +203,7 @@ public void periodic() {

double left = pitch > 0 ? power + clampedError : power;
double right = pitch < 0 ? power - clampedError : power;

runLeft(left);
runRight(right);
}
Expand Down Expand Up @@ -273,8 +277,8 @@ public double getRightPosition() {
* @return whether lift is up or not
*/
public boolean isLiftUp() {
return rightLiftEncoder.getPosition() < LiftConstants.maxExtension
&& leftLiftEncoder.getPosition() < LiftConstants.maxExtension;
return rightLiftEncoder.getPosition() >= LiftConstants.maxExtension
&& leftLiftEncoder.getPosition() >= LiftConstants.maxExtension;
}

/**
Expand Down

0 comments on commit bc2c99a

Please sign in to comment.