Skip to content

Commit

Permalink
Runs in sim now, button binding temporary
Browse files Browse the repository at this point in the history
  • Loading branch information
GooseJuice898 committed Oct 10, 2024
1 parent 034d44f commit 32feff9
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 16 deletions.
Binary file modified ctre_sim/Pigeon 2 - 020 - 0 - ext.dat
Binary file not shown.
Binary file added logs/Log_24-10-10_16-16-33.wpilog
Binary file not shown.
2 changes: 1 addition & 1 deletion src/main/java/frc/robot/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* constants are needed, to reduce verbosity.
*/
public final class Constants {
public static final Mode currentMode = Mode.REAL;
public static final Mode currentMode = Mode.SIM;

public static enum Mode {
/** Running on a real robot. */
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/frc/robot/RobotContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
package frc.robot;

import com.pathplanner.lib.auto.AutoBuilder;
import com.pathplanner.lib.auto.NamedCommands;
import edu.wpi.first.math.geometry.Pose2d;
import edu.wpi.first.math.geometry.Rotation2d;
import edu.wpi.first.wpilibj.GenericHID;
Expand Down Expand Up @@ -103,8 +102,7 @@ public RobotContainer() {
break;
}


//This can go away
// This can go away

// Set up auto routines
// NamedCommands.registerCommand(
Expand Down Expand Up @@ -154,7 +152,9 @@ private void configureButtonBindings() {
drive)
.ignoringDisable(true));

controller.y().onTrue(Commands.runEnd(() -> pivot.setGoal(45), () -> pivot.setGoal(0)));
controller
.y()
.whileTrue(Commands.runEnd(() -> pivot.setGoal(Math.PI / 4), () -> pivot.setGoal(0), pivot));
}

/**
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/frc/robot/subsystems/pivot/Pivot.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static Pivot getInstance() {
}

public static Pivot initialize(PivotIO io) {
if (Pivot.pivotInstance == null) {
if (Pivot.pivotInstance == null) {
pivotInstance = new Pivot(io);
}
return pivotInstance;
Expand All @@ -48,6 +48,7 @@ public static Pivot initialize(PivotIO io) {
@Override
public void periodic() {
io.updateInputs(inputs);
io.setVoltage(inputs.appliedVolts);
Logger.processInputs("Pivot", inputs);
}

Expand All @@ -56,7 +57,7 @@ public void runVoltage(double volts) {
}

public void setGoal(double goal) {
goalRad = goal;
io.setAngle(goal);
}

public void stop() {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/frc/robot/subsystems/pivot/PivotIO.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public interface PivotIO {
public static class PivotIOInputs {
public double positionRad = 0.0;
public double appliedVolts = 0.0;
public double velocityRevolutionsPerSec = 0.0;
public double velocityRadPerSec = 0.0;
public double[] currentAmps = new double[] {};
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/frc/robot/subsystems/pivot/PivotIOReal.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public PivotIOReal() {
@Override
public void updateInputs(PivotIOInputs inputs) {
inputs.positionRad = pivotEncoderRight.getPosition() * 2 * Math.PI;
inputs.velocityRevolutionsPerSec = pivotEncoderRight.getVelocity();
inputs.velocityRadPerSec = pivotEncoderRight.getVelocity() * 2 * Math.PI / 60;
inputs.appliedVolts = appliedVolts;

if (closedLoop) {
Expand Down
18 changes: 11 additions & 7 deletions src/main/java/frc/robot/subsystems/pivot/PivotIOSim.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,23 @@

public class PivotIOSim implements PivotIO {
private SingleJointedArmSim sim =
new SingleJointedArmSim(DCMotor.getNEO(1), 1.5, 0.004, 0, 0, 0, false, 0);
private PIDController pid = new PIDController(1.0, 0.0, 0.0);
new SingleJointedArmSim(DCMotor.getNEO(1), 1.5, 0.004, 0.2, 0, Math.PI, false, 0);
private PIDController pid = new PIDController(0.2, 0.0, 0.0);

private boolean closedLoop = false;
private boolean closedLoop = true;
private double ffVolts = 0.0;
private double appliedVolts = 0.0;

@Override
public void updateInputs(PivotIOInputs inputs) {
if (closedLoop) {
appliedVolts = MathUtil.clamp(pid.calculate(sim.getAngleRads()) + ffVolts, -12.0, 12.0);
sim.setInputVoltage(appliedVolts);
}
sim.update(0.02);

appliedVolts = MathUtil.clamp(pid.calculate(sim.getAngleRads()) + ffVolts, -12.0, 12.0);
sim.setInputVoltage(appliedVolts);

inputs.positionRad = sim.getAngleRads();
inputs.appliedVolts = appliedVolts;
inputs.velocityRadPerSec = sim.getVelocityRadPerSec();
}

@Override
Expand Down

0 comments on commit 32feff9

Please sign in to comment.