new limit switch

This commit is contained in:
mimigamin
2026-04-06 22:44:17 -06:00
parent 9564554c07
commit 1636a054ed
5 changed files with 21 additions and 16 deletions
+2 -2
View File
@@ -84,6 +84,7 @@ public class RobotMap {
// // Configure LiDAR
// reefLidar = new LidarReal(LiDARConstants.REEF_LIDAR_DIO_CHANNEL);
// reverseLidar = new LidarReal(LiDARConstants.REVERSE_LIDAR_DIO_CHANNEL);
DigitalInput armLimitSwitch = new DigitalInput(IntakeConstants.ARM_LIMIT_SWITCH_CHANNEL);
// Configure swerve drive train
SwerveDrivetrain<TalonFX, TalonFX, CANcoder> swerveDrivetrainReal = new SwerveDrivetrain<TalonFX, TalonFX, CANcoder> (TalonFX::new, TalonFX::new, CANcoder::new,
@@ -110,8 +111,7 @@ public class RobotMap {
shooterIO = new ShooterReal(shooter1, shooter2, indexer);
JankCoder armEncoder = new JankCoder(0, IntakeConstants.ARM_ENCODER_OFFSET);
intakeIO = new IntakeReal(arm, roller, armEncoder);
intakeIO = new IntakeReal(armLimitSwitch, arm, roller, armEncoder);
// Fault
FaultPidgeon2.addDevice(swerveDrivetrainReal.getPigeon2(), "Gyro");
@@ -7,12 +7,12 @@ public final class BuildConstants {
public static final String MAVEN_GROUP = "";
public static final String MAVEN_NAME = "2026KPopRobotHunters";
public static final String VERSION = "unspecified";
public static final int GIT_REVISION = 219;
public static final String GIT_SHA = "f9b9a7dd30b53213e360f67c5b7bcd4567fa30f3";
public static final String GIT_DATE = "2026-04-04 20:41:00 MDT";
public static final int GIT_REVISION = 220;
public static final String GIT_SHA = "9564554c0708fd0b761f959685258d9c1a90d11e";
public static final String GIT_DATE = "2026-04-06 19:50:34 MDT";
public static final String GIT_BRANCH = "New-Intake";
public static final String BUILD_DATE = "2026-04-06 19:43:24 MDT";
public static final long BUILD_UNIX_TIME = 1775526204113L;
public static final String BUILD_DATE = "2026-04-06 22:42:14 MDT";
public static final long BUILD_UNIX_TIME = 1775536934067L;
public static final int DIRTY = 1;
private BuildConstants(){}
@@ -23,7 +23,7 @@ public class IntakeConstants {
public static final double ROLLER_MOTOR_GEAR_RATIO = 3;
public static final ConfigurableDouble ARM_ENCODER_OFFSET = new ConfigurableDouble("Arm Encoder Offset", 0);
public static final int ARM_LIMIT_SWITCH_CHANNEL = 9;
public static final ConfigurableDouble INTAKE_BOUNCE_HALF_PERIOD = new ConfigurableDouble("Bounce Half Period", 5.);
public static final ConfigurableDouble INTAKE_BOUNCE_OUTPUT = new ConfigurableDouble("Bounce Output", 0.1);
@@ -60,6 +60,7 @@ public class IntakeConstants {
public static final ConfigurableDouble ARM_EXTEND_PERCENT_OUTPUT = new ConfigurableDouble("Arm extend % output", 0.4);
public static final ConfigurableDouble ARM_RETRACT_PERCENT_OUTPUT = new ConfigurableDouble("Arm retract % output", -0.2);
public static final ConfigurableDouble ARM_REVERSE_ROLLER_RANGE = new ConfigurableDouble("Arm reverse roller range", 1.17);
public static final ConfigurableDouble ROLLER_PERCENT_OUTPUT = new ConfigurableDouble("Roller Percent Output", .50);
@@ -12,17 +12,20 @@ import com.revrobotics.spark.SparkLimitSwitch;
import com.revrobotics.spark.SparkMax;
import edu.wpi.first.units.measure.Angle;
import edu.wpi.first.wpilibj.DigitalInput;
import frc4388.utility.compute.JankCoder;
public class IntakeReal implements IntakeIO {
SparkMax m_armMotor;
RelativeEncoder arm_encoder;
SparkLimitSwitch reverse_limit;
// SparkLimitSwitch reverse_limit;
TalonFX m_rollerMotor;
JankCoder m_encoder;
DigitalInput m_armLimitSwitch;
public IntakeReal(
DigitalInput armLimitSwitch,
SparkMax armMotor,
TalonFX rollerMotor,
JankCoder jankCoder
@@ -31,7 +34,7 @@ public class IntakeReal implements IntakeIO {
// m_pitchMotor = pitchMotor;
m_armMotor = armMotor;
arm_encoder = m_armMotor.getEncoder();
reverse_limit = m_armMotor.getReverseLimitSwitch();
m_armLimitSwitch = armLimitSwitch;
m_rollerMotor = rollerMotor;
m_encoder = jankCoder;
@@ -75,9 +78,9 @@ public class IntakeReal implements IntakeIO {
// m_rollerMotor.set(0);
}
private boolean retractedLimit() {
return m_encoder.get() <= IntakeConstants.ARM_LIMIT_RETRACTED.get();
}
// private boolean retractedLimit() {
// return m_encoder.get() <= IntakeConstants.ARM_LIMIT_RETRACTED.get();
// }
private boolean extendedLimit() {
return m_encoder.get() >= IntakeConstants.ARM_LIMIT_EXTENDED.get();
}
@@ -94,6 +97,7 @@ public class IntakeReal implements IntakeIO {
}
m_armMotor.set(percentOutput);
// System.out.println(percentOutput);
}
@@ -110,13 +114,13 @@ public class IntakeReal implements IntakeIO {
state.rollerOutput = m_rollerMotor.get();
state.rollerMotorCurrent = m_rollerMotor.getStatorCurrent().getValue();
state.retractedSoftLimit = retractedLimit();
// state.retractedSoftLimit = retractedLimit();
state.extendedSoftLimit = extendedLimit();
state.intakeEncoder = m_encoder.getRotations();
state.encoderConnected = m_encoder.isConnected();
state.retractedLimitSwitch = reverse_limit.isPressed();
state.retractedLimitSwitch = m_armLimitSwitch.get();
if(state.retractedLimitSwitch) {
m_encoder.resetRotations();