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

128 make lift use pids #129

Merged
merged 23 commits into from
Mar 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
9c3d013
Deleted unnessasary commands for PID lift
Griffin9881 Mar 16, 2024
d2a7ab1
updated driverJoystick with new PID lift
Griffin9881 Mar 16, 2024
ca9dc8c
updated commands for new PID lift
Griffin9881 Mar 16, 2024
060ad10
added new constants for pid lift
Griffin9881 Mar 16, 2024
3e83d76
made lift pid still tuning needed
Griffin9881 Mar 16, 2024
0be85b7
made encoder conversion for lift pID
Griffin9881 Mar 16, 2024
889014f
made set p i and d functions for lift
Griffin9881 Mar 16, 2024
899a253
added tolerance for lift PID
Griffin9881 Mar 16, 2024
fd189c3
fixed the PID for lift subsystem to be good:
Griffin9881 Mar 16, 2024
3d527ba
Merge branch 'main' into 128-make-lift-use-pids
Griffin9881 Mar 16, 2024
1ac16f3
started fixing changes wes asked for
Griffin9881 Mar 16, 2024
9ff65bb
merge conflict
Griffin9881 Mar 18, 2024
f6853fa
fixed changes for lift that wes sugguested
Griffin9881 Mar 18, 2024
8d4b9d0
Merge branch 'main' into 128-make-lift-use-pids
Griffin9881 Mar 18, 2024
3632c90
deleteed unused import
Griffin9881 Mar 19, 2024
12bb5e2
Merge branch 'main' into 128-make-lift-use-pids
Griffin9881 Mar 21, 2024
80177ce
removed dashboqrd graph
Griffin9881 Mar 21, 2024
bc2c99a
lift runs with new code (WIP)
Griffin9881 Mar 21, 2024
711d9d9
made a third PID controller for the lift
Griffin9881 Mar 23, 2024
438fd27
tuned PID for lift
Griffin9881 Mar 23, 2024
1f51ad9
got rid of temp tab
Griffin9881 Mar 23, 2024
2e3f4f3
got rid of lift on dashboard
Griffin9881 Mar 23, 2024
07f06af
Merge branch 'main' into 128-make-lift-use-pids
Griffin9881 Mar 23, 2024
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
15 changes: 4 additions & 11 deletions src/main/java/frc/robot/DriverJoystick.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@
import edu.wpi.first.wpilibj2.command.InstantCommand;
import edu.wpi.first.wpilibj2.command.RunCommand;
import frc.robot.commands.LiftUpCommand;
import frc.robot.commands.LeftLiftDownCommand;
import frc.robot.commands.LeftLiftUpCommand;
import frc.robot.commands.LiftDownCommand;
import frc.robot.commands.RightLiftDownCommand;
import frc.robot.commands.RightLiftUpCommand;
import frc.robot.commands.LiftDownManualCommand;

public class DriverJoystick extends XboxController1038 {
// Subsystem Dependencies
Expand Down Expand Up @@ -95,14 +92,10 @@ private DriverJoystick() {
.onTrue(new InstantCommand(vision::enable0, vision))
.onFalse(new InstantCommand(vision::disable0, vision));

leftBumper.and(rightBumper.negate()).whileTrue(new LeftLiftUpCommand());
leftTrigger.and(rightTrigger.negate()).whileTrue(new LeftLiftDownCommand());
rightBumper.whileTrue(new LiftUpCommand());
rightTrigger.whileTrue(new LiftDownCommand());

rightBumper.and(leftBumper.negate()).whileTrue(new RightLiftUpCommand());
rightTrigger.and(leftTrigger.negate()).whileTrue(new RightLiftDownCommand());

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

/**
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/frc/robot/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import edu.wpi.first.wpilibj2.command.SequentialCommandGroup;
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 @@ -71,8 +71,10 @@ 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
27 changes: 0 additions & 27 deletions src/main/java/frc/robot/commands/LeftLiftDownCommand.java

This file was deleted.

33 changes: 0 additions & 33 deletions src/main/java/frc/robot/commands/LeftLiftUpCommand.java

This file was deleted.

20 changes: 15 additions & 5 deletions src/main/java/frc/robot/commands/LiftDownCommand.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package frc.robot.commands;

import edu.wpi.first.math.controller.PIDController;
import edu.wpi.first.wpilibj2.command.Command;
import frc.robot.constants.LiftConstants;
import frc.robot.subsystems.Lift;

public class LiftDownCommand extends Command {
Expand All @@ -11,9 +13,18 @@ public LiftDownCommand() {
}

@Override
public void execute() {
lift.runLeftDown();
lift.runRightDown();
public void initialize() {
PIDController leftController = lift.getLeftVerticalController();
leftController.setP(LiftConstants.kVerticalDownP);
leftController.setI(LiftConstants.kVerticalDownI);
leftController.setD(LiftConstants.kVerticalDownD);
PIDController rightController = lift.getRightVerticalController();
rightController.setP(LiftConstants.kVerticalDownP);
rightController.setI(LiftConstants.kVerticalDownI);
rightController.setD(LiftConstants.kVerticalDownD);
lift.enable();
Griffin9881 marked this conversation as resolved.
Show resolved Hide resolved
lift.setSetpointLeft(LiftConstants.minLiftInches);
lift.setSetpointRight(LiftConstants.minLiftInches);
}

@Override
Expand All @@ -23,7 +34,6 @@ public boolean isFinished() {

@Override
public void end(boolean interrupted) {
lift.stopLeftMotor();
lift.stopRightMotor();
lift.disable();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,26 @@
import edu.wpi.first.wpilibj2.command.Command;
import frc.robot.subsystems.Lift;

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

public RightLiftDownCommand() {
public LiftDownManualCommand() {
addRequirements(lift);
}

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

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

@Override
public void end(boolean interrupted) {
lift.stopRightMotor();
lift.stopMotors();
}
}
28 changes: 16 additions & 12 deletions src/main/java/frc/robot/commands/LiftUpCommand.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package frc.robot.commands;

import edu.wpi.first.math.controller.PIDController;
import edu.wpi.first.wpilibj2.command.Command;
import frc.robot.constants.LiftConstants;
import frc.robot.subsystems.Lift;

public class LiftUpCommand extends Command {
Expand All @@ -12,14 +14,18 @@ public LiftUpCommand() {

@Override
public void initialize() {
lift.disableLeftRatchet();
lift.disableRightRatchet();
}

@Override
public void execute() {
lift.runLeftUp();
lift.runRightUp();
lift.disableRatchets();
PIDController leftController = lift.getLeftVerticalController();
leftController.setP(LiftConstants.kVerticalLeftUpP);
leftController.setI(LiftConstants.kVerticalLeftUpI);
leftController.setD(LiftConstants.kVerticalLeftUpD);
PIDController rightController = lift.getRightVerticalController();
rightController.setP(LiftConstants.kVerticalRightUpP);
rightController.setI(LiftConstants.kVerticalRightUpI);
rightController.setD(LiftConstants.kVerticalRightUpD);
lift.enable();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

enable should be in initialize

lift.setSetpointLeft(LiftConstants.maxLiftInches - 0.5);
lift.setSetpointRight(LiftConstants.maxLiftInches);
}

@Override
Expand All @@ -29,9 +35,7 @@ public boolean isFinished() {

@Override
public void end(boolean interrupted) {
lift.stopLeftMotor();
lift.stopRightMotor();
lift.enableLeftRatchet();
lift.enableRightRatchet();
lift.enableRatchets();
lift.disable();
}
}
33 changes: 0 additions & 33 deletions src/main/java/frc/robot/commands/RightLiftUpCommand.java

This file was deleted.

28 changes: 26 additions & 2 deletions src/main/java/frc/robot/constants/LiftConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,32 @@ public class LiftConstants {
public static final double rightRatchetLockPos = 0.55;
public static final double rightRatchetUnlockPos = 0.65;

public static final double motorSpeed = 0.55;
public static final double backwardsMotorSpeed = -0.9;
public static final double upSpeed = 0.55;
public static final double downSpeed = -0.9;

public static final double maxExtension = 195;
public static final double minExtension = 0;
public static final double maxLiftInches = 27;
public static final double minLiftInches = 0;

public static final double maxPower = 1.0;

public static final double kVerticalDownP = 0.06;
public static final double kVerticalDownI = 0.015;
public static final double kVerticalDownD = 0.0;

public static final double kVerticalLeftUpP = 0.001;
public static final double kVerticalLeftUpI = 0.0;
public static final double kVerticalLeftUpD = 0.0;

public static final double kVerticalRightUpP = 0.0028;
public static final double kVerticalRightUpI = 0.0;
public static final double kVerticalRightUpD = 0.0;

public static final double kErrorP = 0.001;
public static final double kErrorI = 0.0;
public static final double kErrorD = 0.0;

public static final double tolerance = 0;
public static final double encoderConversion = 1 / (maxExtension / maxLiftInches);
}
7 changes: 0 additions & 7 deletions src/main/java/frc/robot/subsystems/Dashboard.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import edu.wpi.first.math.trajectory.Trajectory;
import edu.wpi.first.networktables.GenericEntry;
import edu.wpi.first.networktables.NetworkTableInstance;
import edu.wpi.first.wpilibj.BuiltInAccelerometer;
import edu.wpi.first.wpilibj.shuffleboard.BuiltInWidgets;
import edu.wpi.first.wpilibj.shuffleboard.Shuffleboard;
import edu.wpi.first.wpilibj.shuffleboard.ShuffleboardTab;
Expand All @@ -33,7 +32,6 @@ public class Dashboard extends SubsystemBase {
// Tabs
private final ShuffleboardTab driversTab = Shuffleboard.getTab("Drivers");
private final ShuffleboardTab controlsTab = Shuffleboard.getTab("Controls");
private final ShuffleboardTab graphTab = Shuffleboard.getTab("Graph");
private final NetworkTableInstance tableInstance = NetworkTableInstance.getDefault();

// Variables
Expand Down Expand Up @@ -102,11 +100,6 @@ private Dashboard() {
.withPosition(2, 1)
.withSize(4, 3)
.withWidget(BuiltInWidgets.kField);
BuiltInAccelerometer acc = new BuiltInAccelerometer();
graphTab.addDouble("acc", acc::getZ)
.withPosition(0, 0)
.withSize(2, 2)
.withWidget(BuiltInWidgets.kGraph);

PathPlannerLogging.setLogTargetPoseCallback((pose) -> {
field.getObject("target pose").setPose(pose);
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/frc/robot/subsystems/DriveTrain.java
Original file line number Diff line number Diff line change
Expand Up @@ -230,4 +230,13 @@ public double getTurnRate() {
public double getRoll() {
return -gyro.getRoll().getValue();
}

/**
* Returns the pitch value of the robot.
*
* @return the robot's pitch in degrees, from ? to ?
*/
public double getPitch() {
return gyro.getPitch().getValue();
}
}
Loading
Loading