Skip to content

Commit

Permalink
added a command for zeroing the climber (#166)
Browse files Browse the repository at this point in the history
* added a command for zeroing the climber

* "cleaned up angry stuff" hyrum

* voltage import begone
  • Loading branch information
dunep authored Feb 24, 2024
1 parent 5156c66 commit 2b5f3b5
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/main/java/frc/robot/RobotPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ public static final class climberPref {
public static final SN_DoublePreference climberMotorDownSpeed = new SN_DoublePreference(
"climberMotorDownSpeed", -1);
public static final SN_BooleanPreference climberInverted = new SN_BooleanPreference("climberInverted", false);

public static final SN_DoublePreference climberZeroingVoltage = new SN_DoublePreference("climberZeroingVoltage", 1);
// TODO: add value to a defualt to climberZeoringVoltage
public static final SN_DoublePreference climberS = new SN_DoublePreference("climberS", 0);
public static final SN_DoublePreference climberV = new SN_DoublePreference("climberV", 0.12);
public static final SN_DoublePreference climberP = new SN_DoublePreference("climberP", 0.3);
Expand Down
59 changes: 59 additions & 0 deletions src/main/java/frc/robot/commands/ZeroClimber.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.

package frc.robot.commands;

import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj2.command.Command;
import frc.robot.RobotPreferences.climberPref;
import frc.robot.subsystems.Climber;

public class ZeroClimber extends Command {
Climber subClimber;

double zeroingTimestamp;

/** Creates a new ZeroClimber. */
public ZeroClimber(Climber subClimber) {
this.subClimber = subClimber;

addRequirements(subClimber);
}

// Called when the command is initially scheduled.
@Override
public void initialize() {
subClimber.setClimberSoftwareLimits(true, false);

subClimber.setClimberVoltage(0);
zeroingTimestamp = 0;
}

// Called every time the scheduler runs while the command is scheduled.
@Override
public void execute() {
subClimber.setClimberVoltage(climberPref.climberZeroingVoltage.getValue());
}

// Called once the command ends or is interrupted.
@Override
public void end(boolean interrupted) {
subClimber.setClimberSoftwareLimits(true, true);
}

// Returns true when the command should end.
@Override
public boolean isFinished() {
if (Math.abs(subClimber.getClimberVelocity()) <= Math.abs(climberPref.climberZeroingVoltage.getValue())) {
if (zeroingTimestamp == 0) {
zeroingTimestamp = Timer.getFPGATimestamp();
return false;
}

return (Timer.getFPGATimestamp() - zeroingTimestamp) >= climberPref.climberZeroingVoltage.getValue();
}
zeroingTimestamp = 0;
return false;
}
}

0 comments on commit 2b5f3b5

Please sign in to comment.