generated from Greater-Rochester-Robotics/GRRBase
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
4 changed files
with
147 additions
and
82 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
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,57 @@ | ||
package org.team340.robot.subsystems; | ||
|
||
import org.team340.lib.GRRSubsystem; | ||
import org.team340.robot.Constants.PivotConstants; | ||
import org.team340.robot.Constants.RobotMap; | ||
|
||
import com.revrobotics.CANSparkLowLevel.MotorType; | ||
|
||
import edu.wpi.first.wpilibj.DigitalInput; | ||
import edu.wpi.first.wpilibj2.command.Command; | ||
|
||
import com.revrobotics.CANSparkMax; | ||
import com.revrobotics.SparkPIDController; | ||
import com.revrobotics.CANSparkBase.ControlType; | ||
|
||
public class Pivot extends GRRSubsystem { | ||
private final CANSparkMax pivotMotor = createSparkMax("Pivot Motor", RobotMap.SHOOTER_PIVOT_MOTOR, MotorType.kBrushless); | ||
private final SparkPIDController pivotPID = pivotMotor.getPIDController(); | ||
private final DigitalInput lowerLimit = new DigitalInput(RobotMap.PIVOT_LOWER_LIMIT); | ||
|
||
private boolean hasBeenHomed; | ||
|
||
public Pivot() { | ||
super("Pivot"); | ||
|
||
PivotConstants.PIVOT_MOTOR_CONFIG.apply(pivotMotor); | ||
|
||
PivotConstants.PIVOT_PID_CONFIG.apply(pivotMotor, pivotPID); | ||
pivotPID.setSmartMotionMaxVelocity(PivotConstants.MAX_VEL, 0); | ||
pivotPID.setSmartMotionMaxVelocity(PivotConstants.MAX_VEL, 0); | ||
pivotPID.setSmartMotionMinOutputVelocity(PivotConstants.MAX_VEL, 0); | ||
pivotPID.setSmartMotionMaxAccel(PivotConstants.MAX_ACCEL, 0); | ||
pivotPID.setSmartMotionAllowedClosedLoopError(PivotConstants.CLOSED_LOOP_ERR, 0); | ||
|
||
hasBeenHomed = false; | ||
} | ||
|
||
/** | ||
* Homes the pivot by driving slowly down until reaching limit. | ||
* @param withOverride If true will ignore {@code hasBeenHomed}. | ||
*/ | ||
public Command home(boolean withOverride) { | ||
return commandBuilder("pivot.home()") | ||
.onExecute(() -> { | ||
if(!hasBeenHomed || withOverride) { | ||
pivotMotor.set(PivotConstants.HOMING_SPEED); | ||
} else { | ||
pivotMotor.stopMotor(); | ||
} | ||
}) | ||
.isFinished(() -> lowerLimit.get() || (hasBeenHomed && !withOverride)) | ||
.onEnd((interrupted) -> { | ||
pivotMotor.stopMotor(); | ||
hasBeenHomed = !interrupted; | ||
}); | ||
} | ||
} |
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