-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from grt192/climb-merge
Climb merge
- Loading branch information
Showing
7 changed files
with
189 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/main/java/frc/robot/commands/climb/ClimbLowerCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package frc.robot.commands.climb; | ||
|
||
import edu.wpi.first.wpilibj2.command.Command; | ||
import frc.robot.subsystems.climb.ClimbSubsystem; | ||
|
||
public class ClimbLowerCommand extends Command { | ||
private ClimbSubsystem climbSubsystem; | ||
|
||
public ClimbLowerCommand(ClimbSubsystem climbSubsystem){ | ||
this.climbSubsystem = climbSubsystem; | ||
this.addRequirements(climbSubsystem); | ||
} | ||
|
||
@Override | ||
public void initialize() { | ||
System.out.println("LOWERING CLIMB..."); | ||
climbSubsystem.goToExtension(0); | ||
} | ||
|
||
@Override | ||
public boolean isFinished() { | ||
return climbSubsystem.isAtExtension(); | ||
} | ||
|
||
@Override | ||
public void execute() {} | ||
|
||
@Override | ||
public void end(boolean interrupted) { | ||
System.out.println(interrupted ? "CLIMB LOWERING INTERRUPTED!" : "CLIMB LOWERED!"); | ||
} | ||
|
||
} |
34 changes: 34 additions & 0 deletions
34
src/main/java/frc/robot/commands/climb/ClimbRaiseCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package frc.robot.commands.climb; | ||
|
||
import edu.wpi.first.wpilibj2.command.Command; | ||
import frc.robot.subsystems.climb.ClimbSubsystem; | ||
import static frc.robot.Constants.ClimbConstants.*; | ||
|
||
public class ClimbRaiseCommand extends Command { | ||
private ClimbSubsystem climbSubsystem; | ||
|
||
public ClimbRaiseCommand(ClimbSubsystem climbSubsystem){ | ||
this.climbSubsystem = climbSubsystem; | ||
this.addRequirements(climbSubsystem); | ||
} | ||
|
||
@Override | ||
public void initialize() { | ||
System.out.println("RAISING CLIMB..."); | ||
climbSubsystem.goToExtension(EXTENSION_LIMIT_METERS); | ||
} | ||
|
||
@Override | ||
public boolean isFinished() { | ||
return climbSubsystem.isAtExtension(); | ||
} | ||
|
||
@Override | ||
public void execute() {} | ||
|
||
@Override | ||
public void end(boolean interrupted) { | ||
System.out.println(interrupted ? "CLIMB RAISING INTERRUPTED!" : "CLIMB RAISED!"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package frc.robot.subsystems.climb; | ||
|
||
import static frc.robot.Constants.ClimbConstants.*; | ||
|
||
import com.revrobotics.CANSparkBase.IdleMode; | ||
import com.revrobotics.CANSparkBase.SoftLimitDirection; | ||
import com.revrobotics.CANSparkMax; | ||
import com.revrobotics.RelativeEncoder; | ||
|
||
import edu.wpi.first.math.MathUtil; | ||
import edu.wpi.first.wpilibj.DigitalInput; | ||
import frc.robot.util.MotorUtil; | ||
|
||
public class ClimbArm { | ||
private final CANSparkMax winchMotor; | ||
private RelativeEncoder extensionEncoder; | ||
|
||
private final DigitalInput zeroLimitSwitch; | ||
|
||
private double desiredExtension = 0; | ||
|
||
public ClimbArm(int WINCH_MOTOR_ID, int ZERO_LIMIT_ID) { | ||
winchMotor = MotorUtil.createSparkMax(WINCH_MOTOR_ID, (sparkMax) -> { | ||
sparkMax.setIdleMode(IdleMode.kBrake); | ||
sparkMax.setInverted(false); | ||
|
||
extensionEncoder = sparkMax.getEncoder(); | ||
extensionEncoder.setPositionConversionFactor(AXLE_PERIMETER_METERS / WINCH_REDUCTION); | ||
extensionEncoder.setPosition(0); | ||
|
||
sparkMax.setSoftLimit(SoftLimitDirection.kForward, (float) EXTENSION_LIMIT_METERS); | ||
sparkMax.enableSoftLimit(SoftLimitDirection.kForward, true); | ||
sparkMax.setSoftLimit(SoftLimitDirection.kReverse, 0); | ||
sparkMax.enableSoftLimit(SoftLimitDirection.kReverse, true); | ||
}); | ||
|
||
zeroLimitSwitch = new DigitalInput(LEFT_ZERO_LIMIT_ID); | ||
} | ||
|
||
public void update() { | ||
if (zeroLimitSwitch != null && zeroLimitSwitch.get()) | ||
resetEncoder(); | ||
|
||
if (extensionEncoder.getPosition() == 0 && !zeroLimitSwitch.get()) | ||
System.out.println(this.toString() + "encoder uncalibrated!"); | ||
|
||
if (isAtExtension()) | ||
winchMotor.set(0); | ||
else | ||
winchMotor.set(desiredExtension > extensionEncoder.getPosition() | ||
? MAX_WINCH_POWER : -MAX_WINCH_POWER); | ||
|
||
} | ||
|
||
public void goToExtension(double desiredHeight) { | ||
desiredExtension = MathUtil.clamp(desiredHeight, 0, EXTENSION_LIMIT_METERS); | ||
} | ||
|
||
public boolean isAtExtension() { | ||
return Math.abs(extensionEncoder.getPosition() - desiredExtension) < EXTENSION_TOLERANCE_METERS; | ||
} | ||
|
||
private void resetEncoder() { | ||
extensionEncoder.setPosition(0); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/main/java/frc/robot/subsystems/climb/ClimbSubsystem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package frc.robot.subsystems.climb; | ||
|
||
import static frc.robot.Constants.ClimbConstants.*; | ||
|
||
import edu.wpi.first.wpilibj2.command.SubsystemBase; | ||
|
||
public class ClimbSubsystem extends SubsystemBase{ | ||
private final ClimbArm leftClimbArm; | ||
private final ClimbArm rightClimbArm; | ||
|
||
public ClimbSubsystem() { | ||
leftClimbArm = new ClimbArm(LEFT_WINCH_MOTOR_ID, LEFT_ZERO_LIMIT_ID); | ||
rightClimbArm = new ClimbArm(RIGHT_WINCH_MOTOR_ID, RIGHT_ZERO_LIMIT_ID); | ||
} | ||
|
||
@Override | ||
public void periodic() { | ||
leftClimbArm.update(); | ||
rightClimbArm.update(); | ||
} | ||
|
||
public void goToExtension(double height) { | ||
leftClimbArm.goToExtension(height); | ||
rightClimbArm.goToExtension(height); | ||
} | ||
|
||
public boolean isAtExtension() { | ||
return leftClimbArm.isAtExtension() && rightClimbArm.isAtExtension(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters