Skip to content

Commit e3535e7

Browse files
committed
servo code for climber
1 parent 810c4a3 commit e3535e7

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

src/main/java/frc/robot/Constants.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,8 @@ public static class ClimbHardware {
165165
public static final Spark.ID ENCODER_ID = new Spark.ID("climbHardware/Encoder", 51);
166166
public static final TalonFX.ID CLIMB_MOTOR_ID =
167167
new TalonFX.ID("climbHardware/Motor", PhoenixCANBus.RIO, 59);
168+
public static final int SERVO_ID = 5;
169+
168170
}
169171

170172
public static class EndEffectorHardware {

src/main/java/frc/robot/subsystems/climb/ClimbSubsystem.java

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import org.lasarobotics.hardware.revrobotics.Spark.MotorKind;
1414
import org.lasarobotics.hardware.revrobotics.Spark.SparkInputs;
1515
import org.littletonrobotics.junction.Logger;
16-
16+
import edu.wpi.first.wpilibj.Servo;
1717
import edu.wpi.first.wpilibj2.command.Command;
1818
import frc.robot.Constants;
1919
import frc.robot.LoopTimer;
@@ -25,11 +25,12 @@ public class ClimbSubsystem extends StateMachine implements AutoCloseable {
2525
static final double MOUNT_ANGLE = 0.357;
2626
static final double CLIMB_ANGLE = 0.12;
2727
static final double STOW_ANGLE = 0.08;
28+
static final double SERVO_ANGLE = 120.0;
2829

2930
public static record Hardware (
3031
Spark climbEncoder,
31-
TalonFX climbMotor
32-
32+
TalonFX climbMotor,
33+
Servo servo
3334

3435
) {}
3536

@@ -79,6 +80,7 @@ public ClimbStates nextState() {
7980
@Override
8081
public void initialize() {
8182
s_climbInstance.climb();
83+
s_climbInstance.extendServo();
8284
s_climbInstance.setIsMounted(false);
8385

8486
}
@@ -102,8 +104,10 @@ public ClimbStates nextState() {
102104
private static ClimbSubsystem s_climbInstance;
103105
private final Spark m_climbEncoder;
104106
private final TalonFX m_climbMotor;
107+
private final Servo m_servo;
105108
private ClimbStates nextState;
106109
private boolean m_mounted;
110+
private boolean m_servoExtended = false;
107111

108112

109113
/** Creates a new ClimbSubsystem. */
@@ -113,6 +117,7 @@ private ClimbSubsystem(Hardware ClimbHardware) {
113117

114118
this.m_climbEncoder = ClimbHardware.climbEncoder;
115119
this.m_climbMotor = ClimbHardware.climbMotor;
120+
this.m_servo = ClimbHardware.servo;
116121

117122
this.m_mounted = false;
118123

@@ -143,6 +148,13 @@ private void mount() {
143148
m_climbMotor.set(-CLIMB_SPEED);
144149
}
145150

151+
private void extendServo() {
152+
if(!m_servoExtended) {
153+
m_servo.setAngle(SERVO_ANGLE);
154+
m_servoExtended = true;
155+
}
156+
}
157+
146158
/**
147159
* Runs climber
148160
* @return Command to run the climber motors
@@ -166,7 +178,8 @@ public Command lowerClimberCommand() {
166178
public static Hardware initializeHardware() {
167179
Hardware climbHardware = new Hardware(
168180
new Spark(Constants.ClimbHardware.ENCODER_ID, MotorKind.NEO),
169-
new TalonFX(Constants.ClimbHardware.CLIMB_MOTOR_ID.deviceID, Constants.ClimbHardware.CLIMB_MOTOR_ID.bus.name)
181+
new TalonFX(Constants.ClimbHardware.CLIMB_MOTOR_ID.deviceID, Constants.ClimbHardware.CLIMB_MOTOR_ID.bus.name),
182+
new Servo(Constants.ClimbHardware.SERVO_ID)
170183
);
171184

172185

0 commit comments

Comments
 (0)