generated from StuyPulse/Phil
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2bcdc7d
commit ddb8b1a
Showing
5 changed files
with
145 additions
and
1 deletion.
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
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
49 changes: 49 additions & 0 deletions
49
src/main/java/com/stuypulse/robot/subsystems/climber/AbstractClimber.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,49 @@ | ||
/* | ||
* climbs chain in endgame | ||
* - 2 motors (12:1 gear ratio) | ||
* - 2 encoders | ||
* - 4 limit switches (bottom and top, two on each side) | ||
* - hard stop at bottom of the lift | ||
* | ||
* functions: | ||
* - get current height of climber | ||
* - go to specific heights | ||
* - work with the gravity of the robot (has kG) | ||
*/ | ||
|
||
package com.stuypulse.robot.subsystems.climber; | ||
|
||
import com.stuypulse.stuylib.network.SmartNumber; | ||
|
||
import edu.wpi.first.wpilibj2.command.SubsystemBase; | ||
|
||
public abstract class AbstractClimber extends SubsystemBase { | ||
public static final AbstractClimber instance; | ||
|
||
private SmartNumber targetHeight; | ||
|
||
static { | ||
instance = new Climber(); | ||
} | ||
|
||
public static AbstractClimber getInstance() { | ||
return instance; | ||
} | ||
|
||
public void setTargetHeight(double height) { | ||
targetHeight.set(height); | ||
} | ||
|
||
public double getTargetHeight() { | ||
return targetHeight.get(); | ||
} | ||
|
||
public abstract double getHeight(); | ||
|
||
public abstract double getVelocity(); | ||
|
||
public abstract boolean atTop(); | ||
public abstract boolean atBottom(); | ||
|
||
public abstract void periodic(); | ||
} |
71 changes: 71 additions & 0 deletions
71
src/main/java/com/stuypulse/robot/subsystems/climber/Climber.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,71 @@ | ||
package com.stuypulse.robot.subsystems.climber; | ||
|
||
import com.revrobotics.CANSparkMax; | ||
import com.revrobotics.CANSparkLowLevel.MotorType; | ||
import com.revrobotics.RelativeEncoder; | ||
import com.stuypulse.robot.constants.Motors; | ||
|
||
import edu.wpi.first.wpilibj.DigitalInput; | ||
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; | ||
|
||
import static com.stuypulse.robot.constants.Settings.Climber.Encoder.*; | ||
import static com.stuypulse.robot.constants.Ports.Climber.*; | ||
|
||
public class Climber extends AbstractClimber { | ||
|
||
private final CANSparkMax rightMotor; | ||
private final CANSparkMax leftMotor; | ||
|
||
private final RelativeEncoder rightEncoder; | ||
private final RelativeEncoder leftEncoder; | ||
|
||
private final DigitalInput topRightLimit; | ||
private final DigitalInput topLeftLimit; | ||
private final DigitalInput bottomRightLimit; | ||
private final DigitalInput bottomLeftLimit; | ||
|
||
protected Climber() { | ||
rightMotor = new CANSparkMax(RIGHT_MOTOR, MotorType.kBrushless); | ||
leftMotor = new CANSparkMax(LEFT_MOTOR, MotorType.kBrushless); | ||
|
||
rightEncoder = rightMotor.getEncoder(); | ||
leftEncoder = leftMotor.getEncoder(); | ||
|
||
rightEncoder.setPositionConversionFactor(ENCODER_MULTIPLIER); | ||
leftEncoder.setPositionConversionFactor(ENCODER_MULTIPLIER); | ||
|
||
topRightLimit = new DigitalInput(TOP_RIGHT_LIMIT); | ||
topLeftLimit = new DigitalInput(TOP_LEFT_LIMIT); | ||
bottomRightLimit = new DigitalInput(BOTTOM_RIGHT_LIMIT); | ||
bottomLeftLimit = new DigitalInput(BOTTOM_LEFT_LIMIT); | ||
|
||
Motors.Climber.LEFT_MOTOR.configure(leftMotor); | ||
Motors.Climber.RIGHT_MOTOR.configure(rightMotor); | ||
} | ||
|
||
@Override | ||
public double getHeight() { | ||
return (leftEncoder.getPosition() + rightEncoder.getPosition()) / 2 * ENCODER_MULTIPLIER; | ||
} | ||
|
||
@Override | ||
public double getVelocity() { | ||
return (leftEncoder.getVelocity() + rightEncoder.getVelocity()) / 2 * ENCODER_MULTIPLIER; | ||
} | ||
|
||
@Override | ||
public boolean atTop() { | ||
return (!topRightLimit.get()) && (!topLeftLimit.get()); | ||
} | ||
|
||
@Override | ||
public boolean atBottom() { | ||
return (!bottomRightLimit.get()) && (!bottomLeftLimit.get()); | ||
} | ||
|
||
@Override | ||
public void periodic() { | ||
SmartDashboard.putNumber("Climber/Target Height", getTargetHeight()); | ||
SmartDashboard.putNumber("Climber/Height", getHeight()); | ||
} | ||
} |