Skip to content

Commit a7082e7

Browse files
authored
Merge pull request #7 from strykeforce/elevator
Initial Elevator
2 parents 74d24ac + c5669e6 commit a7082e7

File tree

10 files changed

+425
-8
lines changed

10 files changed

+425
-8
lines changed

src/main/java/frc/robot/RobotContainer.java

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,43 +4,60 @@
44

55
package frc.robot;
66

7+
import static edu.wpi.first.units.Units.Rotations;
8+
9+
import edu.wpi.first.units.measure.Angle;
710
import edu.wpi.first.wpilibj.Joystick;
811
import edu.wpi.first.wpilibj.XboxController;
912
import edu.wpi.first.wpilibj2.command.Command;
1013
import edu.wpi.first.wpilibj2.command.Commands;
1114
import edu.wpi.first.wpilibj2.command.button.JoystickButton;
15+
import edu.wpi.first.wpilibj2.command.button.Trigger;
1216
import frc.robot.commands.coral.EnableEjectBeamCommand;
1317
import frc.robot.commands.coral.OpenLoopCoralCommand;
1418
import frc.robot.commands.drive.DriveTeleopCommand;
19+
import frc.robot.commands.elevator.JogElevatorCommand;
20+
import frc.robot.commands.elevator.ZeroElevatorCommand;
21+
import frc.robot.constants.ElevatorConstants;
22+
import frc.robot.constants.RobotConstants;
1523
import frc.robot.controllers.FlyskyJoystick;
1624
import frc.robot.subsystems.coral.CoralIO;
1725
import frc.robot.subsystems.coral.CoralIOFX;
1826
import frc.robot.subsystems.coral.CoralSubsystem;
1927
import frc.robot.subsystems.drive.DriveSubsystem;
2028
import frc.robot.subsystems.drive.Swerve;
29+
import frc.robot.subsystems.elevator.ElevatorIO;
30+
import frc.robot.subsystems.elevator.ElevatorIOFX;
31+
import frc.robot.subsystems.elevator.ElevatorSubsystem;
2132
import org.strykeforce.telemetry.TelemetryController;
2233
import org.strykeforce.telemetry.TelemetryService;
2334

2435
public class RobotContainer {
2536
private Swerve swerve;
2637
private DriveSubsystem driveSubsystem;
2738

39+
private ElevatorIO elevatorIO;
40+
private ElevatorSubsystem elevatorSubsystem;
41+
42+
private final CoralIO coralIO;
43+
private final CoralSubsystem coralSubsystem;
44+
2845
private final XboxController xboxController = new XboxController(1);
2946
private final Joystick driveJoystick = new Joystick(0);
3047

3148
private final FlyskyJoystick flysky = new FlyskyJoystick(driveJoystick);
3249
private final TelemetryService telemetryService = new TelemetryService(TelemetryController::new);
3350

34-
private final CoralSubsystem coralSubsystem;
35-
private final CoralIO coralIO;
36-
3751
public RobotContainer() {
3852
swerve = new Swerve();
3953
driveSubsystem = new DriveSubsystem(swerve);
4054

4155
coralIO = new CoralIOFX();
4256
coralSubsystem = new CoralSubsystem(coralIO);
4357

58+
elevatorIO = new ElevatorIOFX();
59+
elevatorSubsystem = new ElevatorSubsystem(elevatorIO);
60+
4461
configureTelemetry();
4562
configureDriverBindings();
4663
configureOperatorBindings();
@@ -72,6 +89,20 @@ private void configureOperatorBindings() {
7289
new JoystickButton(xboxController, XboxController.Button.kA.value)
7390
.onTrue(new OpenLoopCoralCommand(coralSubsystem, -0.5))
7491
.onTrue(new EnableEjectBeamCommand(true, coralSubsystem));
92+
93+
// Move Elevator
94+
new Trigger((() -> xboxController.getRightY() > RobotConstants.kJoystickDeadband))
95+
.onTrue(
96+
new JogElevatorCommand(
97+
elevatorSubsystem, Angle.ofBaseUnits(ElevatorConstants.kJogAmount, Rotations)));
98+
new Trigger((() -> xboxController.getRightY() < -RobotConstants.kJoystickDeadband))
99+
.onTrue(
100+
new JogElevatorCommand(
101+
elevatorSubsystem, Angle.ofBaseUnits(-ElevatorConstants.kJogAmount, Rotations)));
102+
103+
// Zero Elevator
104+
new JoystickButton(xboxController, XboxController.Button.kX.value)
105+
.onTrue(new ZeroElevatorCommand(elevatorSubsystem));
75106
}
76107

77108
public Command getAutonomousCommand() {
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package frc.robot.commands.elevator;
2+
3+
import edu.wpi.first.units.measure.Angle;
4+
import edu.wpi.first.wpilibj2.command.Command;
5+
import frc.robot.subsystems.elevator.ElevatorSubsystem;
6+
7+
public class JogElevatorCommand extends Command {
8+
9+
private ElevatorSubsystem elevatorSubsystem;
10+
private Angle positionChange;
11+
12+
public JogElevatorCommand(ElevatorSubsystem elevatorSubsystem, Angle positionChange) {
13+
this.elevatorSubsystem = elevatorSubsystem;
14+
this.positionChange = positionChange;
15+
}
16+
17+
@Override
18+
public void initialize() {
19+
elevatorSubsystem.setPosition(elevatorSubsystem.getPosition().plus(positionChange));
20+
}
21+
22+
@Override
23+
public boolean isFinished() {
24+
return elevatorSubsystem.isFinished();
25+
}
26+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package frc.robot.commands.elevator;
2+
3+
import edu.wpi.first.units.measure.Angle;
4+
import edu.wpi.first.wpilibj2.command.Command;
5+
import frc.robot.subsystems.elevator.ElevatorSubsystem;
6+
7+
public class SetElevatorPositionCommand extends Command {
8+
9+
private ElevatorSubsystem elevatorSubsystem;
10+
private Angle position;
11+
12+
public SetElevatorPositionCommand(ElevatorSubsystem elevatorSubsystem, Angle position) {
13+
this.elevatorSubsystem = elevatorSubsystem;
14+
this.position = position;
15+
}
16+
17+
@Override
18+
public void initialize() {
19+
elevatorSubsystem.setPosition(position);
20+
}
21+
22+
@Override
23+
public boolean isFinished() {
24+
return elevatorSubsystem.isFinished();
25+
}
26+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package frc.robot.commands.elevator;
2+
3+
import edu.wpi.first.wpilibj2.command.Command;
4+
import frc.robot.subsystems.elevator.ElevatorSubsystem;
5+
6+
public class ZeroElevatorCommand extends Command {
7+
8+
private ElevatorSubsystem elevatorSubsystem;
9+
10+
public ZeroElevatorCommand(ElevatorSubsystem elevatorSubsystem) {
11+
this.elevatorSubsystem = elevatorSubsystem;
12+
}
13+
14+
@Override
15+
public void initialize() {
16+
elevatorSubsystem.zero();
17+
}
18+
}
Lines changed: 108 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,110 @@
11
package frc.robot.constants;
22

3-
public class ElevatorConstants {}
3+
import com.ctre.phoenix6.configs.CurrentLimitsConfigs;
4+
import com.ctre.phoenix6.configs.HardwareLimitSwitchConfigs;
5+
import com.ctre.phoenix6.configs.MotionMagicConfigs;
6+
import com.ctre.phoenix6.configs.MotorOutputConfigs;
7+
import com.ctre.phoenix6.configs.Slot0Configs;
8+
import com.ctre.phoenix6.configs.SoftwareLimitSwitchConfigs;
9+
import com.ctre.phoenix6.configs.TalonFXConfiguration;
10+
import com.ctre.phoenix6.signals.ForwardLimitSourceValue;
11+
import com.ctre.phoenix6.signals.ForwardLimitTypeValue;
12+
import com.ctre.phoenix6.signals.GravityTypeValue;
13+
import com.ctre.phoenix6.signals.InvertedValue;
14+
import com.ctre.phoenix6.signals.NeutralModeValue;
15+
import com.ctre.phoenix6.signals.ReverseLimitSourceValue;
16+
import com.ctre.phoenix6.signals.ReverseLimitTypeValue;
17+
18+
public class ElevatorConstants {
19+
20+
public static final double kCloseEnoughRotations = 0.0083;
21+
public static final double kMaxFwd = 0; // TODO all of these fields need to be filled out
22+
public static final double kMaxRev = 0;
23+
public static final int kZeroMultiple =
24+
0; // some constant to multiply, add by to turn the analog input into a position
25+
public static final double kZeroSpeed = -.05;
26+
public static final int kZeroCounter = 3;
27+
public static final double kZeroedThreshhold = .0001;
28+
29+
public static final int heightAnalogID = 0;
30+
public static final int kFxIDMain = 20;
31+
public static final int kFxIDFollow = 21;
32+
33+
public static final double kJogAmount = 0.1;
34+
35+
public static TalonFXConfiguration getBothFXConfig() {
36+
TalonFXConfiguration fxConfig = new TalonFXConfiguration();
37+
38+
CurrentLimitsConfigs current =
39+
new CurrentLimitsConfigs()
40+
.withStatorCurrentLimitEnable(false)
41+
.withStatorCurrentLimit(20)
42+
.withSupplyCurrentLimit(10)
43+
.withSupplyCurrentLowerLimit(8)
44+
.withSupplyCurrentLowerTime(0.02)
45+
.withSupplyCurrentLimitEnable(true);
46+
fxConfig.CurrentLimits = current;
47+
48+
HardwareLimitSwitchConfigs hwLimit =
49+
new HardwareLimitSwitchConfigs()
50+
.withForwardLimitAutosetPositionEnable(false)
51+
.withForwardLimitEnable(false)
52+
.withForwardLimitType(ForwardLimitTypeValue.NormallyOpen)
53+
.withForwardLimitSource(ForwardLimitSourceValue.LimitSwitchPin)
54+
.withReverseLimitAutosetPositionEnable(false)
55+
.withReverseLimitEnable(false)
56+
.withReverseLimitType(ReverseLimitTypeValue.NormallyOpen)
57+
.withReverseLimitSource(ReverseLimitSourceValue.LimitSwitchPin);
58+
fxConfig.HardwareLimitSwitch = hwLimit;
59+
60+
SoftwareLimitSwitchConfigs swLimit =
61+
new SoftwareLimitSwitchConfigs()
62+
.withForwardSoftLimitEnable(false)
63+
.withForwardSoftLimitThreshold(kMaxFwd)
64+
.withReverseSoftLimitEnable(false)
65+
.withReverseSoftLimitThreshold(kMaxRev);
66+
fxConfig.SoftwareLimitSwitch = swLimit;
67+
68+
Slot0Configs slot0 =
69+
new Slot0Configs()
70+
.withKP(0.4)
71+
.withKI(0.1)
72+
.withKD(0)
73+
.withGravityType(GravityTypeValue.Elevator_Static)
74+
.withKG(0)
75+
.withKS(0)
76+
.withKV(0.12)
77+
.withKA(0);
78+
fxConfig.Slot0 = slot0;
79+
80+
MotionMagicConfigs motionMagic =
81+
new MotionMagicConfigs()
82+
.withMotionMagicAcceleration(130)
83+
.withMotionMagicCruiseVelocity(0)
84+
.withMotionMagicExpo_kA(0)
85+
.withMotionMagicExpo_kV(0)
86+
.withMotionMagicJerk(1000);
87+
fxConfig.MotionMagic = motionMagic;
88+
89+
MotorOutputConfigs motorOut =
90+
new MotorOutputConfigs()
91+
.withDutyCycleNeutralDeadband(0.01)
92+
.withNeutralMode(NeutralModeValue.Coast)
93+
.withInverted(InvertedValue.CounterClockwise_Positive);
94+
fxConfig.MotorOutput = motorOut;
95+
96+
return fxConfig;
97+
}
98+
99+
public static CurrentLimitsConfigs getZeroingCurrentLimitsConfigs() {
100+
CurrentLimitsConfigs current =
101+
new CurrentLimitsConfigs() // TODO actually have correct limits for zeroing
102+
.withStatorCurrentLimitEnable(false)
103+
.withStatorCurrentLimit(20)
104+
.withSupplyCurrentLimit(10)
105+
.withSupplyCurrentLowerLimit(8)
106+
.withSupplyCurrentLowerTime(0.02)
107+
.withSupplyCurrentLimitEnable(true);
108+
return current;
109+
}
110+
}

src/main/java/frc/robot/constants/ExampleConstants.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ public static TalonFXConfiguration getFXConfig() {
3333

3434
CurrentLimitsConfigs current =
3535
new CurrentLimitsConfigs()
36-
.withStatorCurrentLimit(10)
3736
.withStatorCurrentLimitEnable(false)
3837
.withStatorCurrentLimit(20)
3938
.withSupplyCurrentLimit(10)

src/main/java/frc/robot/constants/RobotConstants.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@
22

33
public class RobotConstants {
44
public static final int kTalonConfigTimeout = 10; // ms
5+
6+
public static final double kJoystickDeadband = 0.1;
57
}
Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,33 @@
11
package frc.robot.subsystems.elevator;
22

3-
public interface ElevatorIO {}
3+
import com.ctre.phoenix6.configs.CurrentLimitsConfigs;
4+
import edu.wpi.first.units.measure.Angle;
5+
import org.littletonrobotics.junction.AutoLog;
6+
import org.strykeforce.telemetry.TelemetryService;
7+
8+
public interface ElevatorIO {
9+
10+
@AutoLog
11+
public static class ElevatorIOInputs {
12+
public double position = 0.0;
13+
public double velocity = 0.0;
14+
// something about height and IO layer?
15+
}
16+
17+
public default void updateInputs(ElevatorIOInputs inputs) {}
18+
19+
public default void registerWith(TelemetryService telemetryService) {}
20+
21+
public default void setPosition(Angle position) {}
22+
23+
public default void setVelocityOpenLoop(double dutyCycleOut) {}
24+
25+
public default void setCurrentLimitConfig(CurrentLimitsConfigs config) {}
26+
27+
public default void zero() {}
28+
}
29+
30+
/*
31+
* To-do: resolve all the comments, implement zero, find out if follower actually means every LOC for one motor does the same
32+
* thing to the other?, positionrequest never used in IOFX
33+
*/

0 commit comments

Comments
 (0)