Add limit switches to code

Encoder position will zero out whenever the arm hits the bottom limit switch. The Digital Output ids still need to be configured.
This commit is contained in:
Keenan D. Buckley
2019-03-08 19:29:57 -07:00
parent f74093ca12
commit 99a9f76d16
@@ -21,6 +21,7 @@ import com.ctre.phoenix.motorcontrol.NeutralMode;
import com.ctre.phoenix.motorcontrol.SensorCollection;
import com.ctre.phoenix.motorcontrol.can.WPI_TalonSRX;
import edu.wpi.first.wpilibj.DigitalInput;
import edu.wpi.first.wpilibj.Solenoid;
import edu.wpi.first.wpilibj.command.Subsystem;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
@@ -93,6 +94,9 @@ public class Arm extends Subsystem implements ControlLoopable
private PIDParams armPIDParams = new PIDParams(P_Value, I_Value, D_Value, KF_DOWN); // KF gets updated later
public static final double PID_ERROR_INCHES = 5.0;
LimitSwitchSource limitSwitchSource;
DigitalInput forwardLimitSwitch = new DigitalInput(1);
DigitalInput reverseLimitSwitch = new DigitalInput(2);
// Pneumatics
private Solenoid speedShift;
@@ -270,6 +274,10 @@ public class Arm extends Subsystem implements ControlLoopable
}
lastControlLoopUpdateTimestamp = currentTimestamp;
if (reverseLimitSwitch.get()){
motor1.setPosition(0);
}
// Do the update
if (armControlMode == ArmControlMode.JOYSTICK_MANUAL) {
controlManualWithJoystick();