|
4 | 4 | import static edu.wpi.first.units.Units.Degrees;
|
5 | 5 | import static edu.wpi.first.units.Units.Inches;
|
6 | 6 | import static edu.wpi.first.units.Units.Meters;
|
| 7 | +import static edu.wpi.first.units.Units.Millimeters; |
7 | 8 | import static edu.wpi.first.units.Units.Radians;
|
8 | 9 | import static edu.wpi.first.units.Units.Rotations;
|
9 |
| -import static edu.wpi.first.units.Units.Millimeters; |
| 10 | +import static edu.wpi.first.units.Units.Volts; |
| 11 | + |
| 12 | +import java.util.function.Consumer; |
10 | 13 |
|
11 | 14 | import org.lasarobotics.fsm.StateMachine;
|
12 | 15 | import org.lasarobotics.fsm.SystemState;
|
13 | 16 | import org.lasarobotics.hardware.ctre.TalonFX;
|
14 | 17 | import org.lasarobotics.hardware.generic.LimitSwitch;
|
15 | 18 | import org.lasarobotics.hardware.generic.LimitSwitch.SwitchPolarity;
|
16 | 19 |
|
| 20 | +import com.ctre.phoenix6.SignalLogger; |
17 | 21 | import com.ctre.phoenix6.configs.TalonFXConfiguration;
|
18 | 22 | import com.ctre.phoenix6.controls.DutyCycleOut;
|
19 | 23 | import com.ctre.phoenix6.controls.MotionMagicVoltage;
|
| 24 | +import com.ctre.phoenix6.controls.VoltageOut; |
20 | 25 | import com.ctre.phoenix6.signals.FeedbackSensorSourceValue;
|
21 | 26 | import com.ctre.phoenix6.signals.GravityTypeValue;
|
22 | 27 | import com.ctre.phoenix6.signals.InvertedValue;
|
23 | 28 | import com.ctre.phoenix6.signals.NeutralModeValue;
|
24 | 29 |
|
25 | 30 | import edu.wpi.first.units.measure.Angle;
|
26 | 31 | import edu.wpi.first.units.measure.Distance;
|
| 32 | +import edu.wpi.first.wpilibj.sysid.SysIdRoutineLog; |
| 33 | +import edu.wpi.first.wpilibj.sysid.SysIdRoutineLog.State; |
| 34 | +import edu.wpi.first.wpilibj2.command.sysid.SysIdRoutine; |
27 | 35 | import frc.robot.Constants;
|
28 | 36 |
|
29 | 37 | public class LiftSubsystem extends StateMachine implements AutoCloseable {
|
@@ -734,6 +742,11 @@ public SystemState nextState() {
|
734 | 742 | private final MotionMagicVoltage m_pivotPositionSetter;
|
735 | 743 | private final MotionMagicVoltage m_elevatorPositionSetter;
|
736 | 744 | private final LimitSwitch m_elevatorHomingBeamBreak;
|
| 745 | + private final Consumer<SysIdRoutineLog.State> m_elevatorSysIDLogConsumer; |
| 746 | + private final Consumer<SysIdRoutineLog.State> m_pivotSysIDLogConsumer; |
| 747 | + private static final String ELEVATOR_MOTOR_SYSID_STATE_LOG_ENTRY = "/ElevatorMotorSysIDTestState"; |
| 748 | + private static final String PIVOT_MOTOR_SYSID_STATE_LOG_ENTRY = "/PivotMotorSysIDTestState"; |
| 749 | + |
737 | 750 |
|
738 | 751 | /** Creates a new LiftSubsystem */
|
739 | 752 | private LiftSubsystem(Hardware liftHardware) {
|
@@ -809,6 +822,9 @@ private LiftSubsystem(Hardware liftHardware) {
|
809 | 822 | pivotConfig.Slot0.kS = 0;
|
810 | 823 | pivotConfig.Slot0.GravityType = GravityTypeValue.Arm_Cosine;
|
811 | 824 |
|
| 825 | + m_elevatorSysIDLogConsumer = state -> SignalLogger.writeString(getName() + ELEVATOR_MOTOR_SYSID_STATE_LOG_ENTRY, state.toString()); |
| 826 | + m_pivotSysIDLogConsumer = state -> SignalLogger.writeString(getName() + PIVOT_MOTOR_SYSID_STATE_LOG_ENTRY, state.toString()); |
| 827 | + |
812 | 828 | // Apply configs for TalonFX motors
|
813 | 829 | m_elevatorMotor.applyConfigs(elevatorConfig);
|
814 | 830 | m_pivotMotor.applyConfigs(pivotConfig);
|
@@ -919,6 +935,43 @@ public boolean armAt(Angle targetAngle) {
|
919 | 935 | return (currentAngle.isNear(targetAngle, ARM_TOLERANCE));
|
920 | 936 | }
|
921 | 937 |
|
| 938 | + /** |
| 939 | + * Gets the SysID routine for the elevator |
| 940 | + */ |
| 941 | + public SysIdRoutine getElevatorSysIDRoutine() { |
| 942 | + return new SysIdRoutine( |
| 943 | + new SysIdRoutine.Config( |
| 944 | + null, |
| 945 | + Volts.of(4), |
| 946 | + null, |
| 947 | + m_elevatorSysIDLogConsumer |
| 948 | + ), |
| 949 | + new SysIdRoutine.Mechanism( |
| 950 | + voltage -> m_elevatorMotor.setControl(new VoltageOut(voltage)), |
| 951 | + null, s_liftinstance) |
| 952 | + ); |
| 953 | + } |
| 954 | + |
| 955 | + |
| 956 | + /** |
| 957 | + * |
| 958 | + * @return |
| 959 | + */ |
| 960 | + public SysIdRoutine getPivotSysIDRoutine() { |
| 961 | + return new SysIdRoutine( |
| 962 | + new SysIdRoutine.Config( |
| 963 | + null, |
| 964 | + Volts.of(4), |
| 965 | + null, |
| 966 | + m_pivotSysIDLogConsumer |
| 967 | + ), |
| 968 | + new SysIdRoutine.Mechanism( |
| 969 | + voltage -> m_pivotMotor.setControl(new VoltageOut(voltage)), |
| 970 | + null, s_liftinstance) |
| 971 | + ); |
| 972 | + } |
| 973 | + |
| 974 | + |
922 | 975 | /**
|
923 | 976 | * Stop the elevator motor
|
924 | 977 | */
|
|
0 commit comments