Skip to content

Commit 6bd149b

Browse files
pluh
1 parent 14ea516 commit 6bd149b

File tree

6 files changed

+99
-52
lines changed

6 files changed

+99
-52
lines changed

src/main/java/frc/robot/Autos.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@
1010
import com.pathplanner.lib.util.ReplanningConfig;
1111
import edu.wpi.first.math.geometry.Pose2d;
1212
import edu.wpi.first.math.geometry.Rotation2d;
13+
import edu.wpi.first.math.util.Units;
1314
import edu.wpi.first.wpilibj.DriverStation.Alliance;
1415
import edu.wpi.first.wpilibj.smartdashboard.SendableChooser;
1516
import edu.wpi.first.wpilibj2.command.Command;
1617
import edu.wpi.first.wpilibj2.command.Commands;
18+
import edu.wpi.first.wpilibj2.command.sysid.SysIdRoutine.Direction;
1719
import frc.robot.Constants.AutoConstants;
1820
import frc.robot.Constants.MiscConstants;
1921
import frc.robot.Constants.SwerveConstants;
@@ -90,7 +92,19 @@ public Autos(
9092
PathPlannerLogging.setLogTargetPoseCallback(desiredPoseTelemetryEntry::append);
9193

9294
autoChooser = AutoBuilder.buildAutoChooser("JustProbe");
95+
autoChooser.addOption("elevator 4 in", elevatorSubsystem.setElevatorPositionCommand(Units.inchesToMeters(4)));
9396
autoChooser.addOption("slowFeed", intakeSubsystem.setIntakeVoltageCommand(1));
97+
autoChooser.addOption("transport voltage", transportSubsystem.setVoltageCommand(4));
98+
// autoChooser.addOption("elevator", elevatorSubsystem.setFollowerMotor(3));
99+
autoChooser.addOption("elevater qf", elevatorSubsystem.sysIdQuasistatic(Direction.kForward));
100+
autoChooser.addOption("elevator qr", elevatorSubsystem.sysIdQuasistatic(Direction.kReverse));
101+
autoChooser.addOption("elevator df", elevatorSubsystem.sysIdDynamic(Direction.kForward));
102+
autoChooser.addOption("elevator dr", elevatorSubsystem.sysIdDynamic(Direction.kReverse));
103+
autoChooser.addOption("elevator fol", elevatorSubsystem.setFollowerCommand(3));
104+
autoChooser.addOption("drive qf", driveSubsystem.driveQuasistaticSysIDCommand(Direction.kForward));
105+
autoChooser.addOption("drive qr", driveSubsystem.driveQuasistaticSysIDCommand(Direction.kReverse));
106+
autoChooser.addOption("drive df", driveSubsystem.driveDynamicSysIDCommand(Direction.kForward));
107+
autoChooser.addOption("drive dr", driveSubsystem.driveDynamicSysIDCommand(Direction.kReverse));
94108
}
95109

96110
public SendableChooser<Command> getAutoChooser() {

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

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public static class SlapdownConstants {
5555
public static final double ROTATION_UP_ANGLE = -0.0648 - Units.degreesToRadians(90);
5656
public static final double ROTATION_DOWN_ANGLE = 0.75;
5757

58-
public static final int ROTATION_LIMIT_SWITCH_ID = 1;
58+
public static final int ROTATION_LIMIT_SWITCH_ID = 5;
5959

6060
public static final double FEEDER_VOLTAGE = (7);
6161

@@ -75,8 +75,8 @@ public static class SlapdownConstants {
7575
}
7676

7777
public static class ElevatorConstants {
78-
public static final boolean MAIN_INVERTED = true;
79-
public static final boolean FOLLOWER_INVERTED = true;
78+
public static final boolean MAIN_INVERTED = false;
79+
public static final boolean FOLLOWER_INVERTED = false;
8080

8181
public static final double ELEVATOR_MAX_HEIGHT = Units.inchesToMeters(10.5);
8282
public static final double ELEVATOR_MIN_HEIGHT = Units.inchesToMeters(0.0);
@@ -88,15 +88,15 @@ public static class ElevatorConstants {
8888
public static final int ELEVATOR_MOTOR_ID = 4;
8989
public static final int ELEVATOR_FOLLOWER_MOTOR_ID = 22;
9090

91-
public static final int ELEVATOR_LIMIT_SWITCH = 0;
91+
public static final int ELEVATOR_LIMIT_SWITCH = 6;
9292

9393
public static final double ELEVATOR_GEAR_RATIO = 5.0 * 4.0;
9494
public static final double METERS_PER_REV =
9595
Units.inchesToMeters((Math.PI * 1.75) / (ELEVATOR_GEAR_RATIO));
9696

9797
// TODO: Do These PID GAINS
9898
public static final TunablePIDGains PID_GAINS =
99-
new TunablePIDGains("gains/elevator", 20.0, 0, 0, MiscConstants.TUNING_MODE);
99+
new TunablePIDGains("gains/elevator", 62, 0, 0, MiscConstants.TUNING_MODE);
100100
public static final TunableTrapezoidalProfileGains TRAPEZOIDAL_PROFILE_GAINS =
101101
new TunableTrapezoidalProfileGains(
102102
"/gains/extension",
@@ -107,7 +107,7 @@ public static class ElevatorConstants {
107107
// TODO: TUNE FF GAINS
108108
public static final TunableArmElevatorFFGains FF_GAINS =
109109
new TunableArmElevatorFFGains(
110-
"gains/elevator", 0.22339, 0.041616, 13.1, 1.2556, MiscConstants.TUNING_MODE);
110+
"gains/elevator", 0.11277, 0.055066, 18.193, 2.8124, MiscConstants.TUNING_MODE);
111111
}
112112

113113
public static class SwerveConstants {
@@ -126,23 +126,23 @@ private SwerveConstants() {}
126126

127127
// 0.47
128128
public static final TunablePIDGains DRIVE_VELOCITY_PID_GAINS =
129-
new TunablePIDGains("/gains/drive", 0.0, 0.0, 0.0, MiscConstants.TUNING_MODE);
129+
new TunablePIDGains("/gains/drive", 0.1581, 0.0, 0.0, MiscConstants.TUNING_MODE);
130130
public static final TunableFFGains DRIVE_VELOCITY_FF_GAINS =
131131
new TunableFFGains(
132132
"/gains/drive",
133-
0.0,
134-
0.0,
135-
0.0,
133+
0.12798,
134+
0.12061,
135+
0.0018667,
136136
MiscConstants.TUNING_MODE);
137137

138138
public static final TunablePIDGains STEER_POSITION_PID_GAINS =
139-
new TunablePIDGains("/gains/steer", 0.0, 0.0, 0.0, MiscConstants.TUNING_MODE);
139+
new TunablePIDGains("/gains/steer", 40, 0.0, 0, MiscConstants.TUNING_MODE);
140140
public static final TunableFFGains STEER_VELOCITY_FF_GAINS =
141141
new TunableFFGains(
142142
"/gains/steer",
143-
0.0,
144-
0.0,
145-
0.0,
143+
0.25096,
144+
2.4255,
145+
0.029622,
146146
MiscConstants.TUNING_MODE);
147147

148148
// Left right distance between center of wheels
@@ -186,18 +186,18 @@ private SwerveConstants() {}
186186

187187
public static final SwerveModuleConfiguration FRONT_LEFT_MODULE_CONFIGURATION =
188188
new SwerveModuleConfiguration(
189-
12, 8, 17, true, true, 0.0, false, SHARED_SWERVE_MODULE_CONFIGURATION);
189+
12, 8, 17, true, false, 2.43, true, SHARED_SWERVE_MODULE_CONFIGURATION);
190190
public static final SwerveModuleConfiguration FRONT_RIGHT_MODULE_CONFIGURATION =
191191
new SwerveModuleConfiguration(
192-
13, 5, 18, true, true, 0.0, false, SHARED_SWERVE_MODULE_CONFIGURATION);
192+
13, 5, 18, true, false, 0.34, true, SHARED_SWERVE_MODULE_CONFIGURATION);
193193

194194
public static final SwerveModuleConfiguration BACK_LEFT_MODULE_CONFIGURATION =
195195
new SwerveModuleConfiguration(
196-
14, 10, 19, true, true, 0.0, false, SHARED_SWERVE_MODULE_CONFIGURATION);
196+
14, 10, 19, true, false, 0.54, true, SHARED_SWERVE_MODULE_CONFIGURATION);
197197

198198
public static final SwerveModuleConfiguration BACK_RIGHT_MODULE_CONFIGURATION =
199199
new SwerveModuleConfiguration(
200-
15, 3, 20, true, true, 0.0, false, SHARED_SWERVE_MODULE_CONFIGURATION);
200+
15, 3, 20, true, false, 0.73, true, SHARED_SWERVE_MODULE_CONFIGURATION);
201201
}
202202

203203
public static class AutoConstants {
@@ -237,7 +237,7 @@ public static class WristConstants {
237237
public static final Rotation2d WRIST_MIN = Rotation2d.fromRadians(-0.027);
238238

239239
public static final double WRIST_OFFSET = -0.288 + Units.degreesToRadians(90.0);
240-
public static final int WRIST_ENCODER_PORT = 2;
240+
public static final int WRIST_ENCODER_PORT = 7;
241241

242242
public static final int WRIST_MOTOR_ID = 2;
243243
public static final boolean INVERTED = true;
@@ -268,7 +268,7 @@ public static class TransportConstants {
268268
public static final boolean INVERTED = true;
269269
public static final int STALL_MOTOR_CURRENT = 45;
270270
public static final int FREE_MOTOR_CURRENT = 25;
271-
public static final double TRANSPORT_LOAD_VOLTAGE = 3.0;
271+
public static final double TRANSPORT_LOAD_VOLTAGE = 2.0;
272272

273273
public static final double TRANSPORT_CLOSE_SPEAKER_VOLTAGE = 12;
274274
public static final int SHOOTER_SENSOR_ID = 8;

src/main/java/frc/robot/Robot.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package frc.robot;
22

3+
import org.littletonrobotics.urcl.URCL;
4+
35
import edu.wpi.first.networktables.NetworkTableInstance;
46
import edu.wpi.first.util.datalog.DataLog;
57
import edu.wpi.first.wpilibj.DataLogManager;
@@ -52,8 +54,8 @@ public void robotInit() {
5254

5355
DataLog dataLog = DataLogManager.getLog();
5456
if (MiscConstants.TUNING_MODE) {
55-
// URCL.start();
56-
// NetworkTableInstance.getDefault().startEntryDataLog(dataLog, "/URCL/", "URCL/");
57+
URCL.start();
58+
NetworkTableInstance.getDefault().startEntryDataLog(dataLog, "/URCL/", "URCL/");
5759
}
5860
// Log connections and FMSInfo
5961
NetworkTableInstance.getDefault().startConnectionDataLog(dataLog, "NTConnection");

src/main/java/frc/robot/subsystems/elevator/ElevatorSubsystem.java

Lines changed: 58 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public class ElevatorSubsystem extends SubsystemBase {
4040

4141
private final TelemetryCANSparkMax elevatorMotor =
4242
new TelemetryCANSparkMax(ELEVATOR_MOTOR_ID, MotorType.kBrushless, "/elevator/motor", true);
43-
private final TelemetryCANSparkMax elevatorMotorFollower = new TelemetryCANSparkMax(ELEVATOR_FOLLOWER_MOTOR_ID, MotorType.kBrushless, "/elevator/followerMotor", false);
43+
private final TelemetryCANSparkMax elevatorMotorFollower = new TelemetryCANSparkMax(ELEVATOR_FOLLOWER_MOTOR_ID, MotorType.kBrushless, "/elevator/followerMotor", true);
4444

4545

4646
private final TunableTelemetryProfiledPIDController controller =
@@ -50,10 +50,12 @@ public class ElevatorSubsystem extends SubsystemBase {
5050
private ElevatorFeedforward feedforward = FF_GAINS.createElevatorFeedforward();
5151

5252
private final RelativeEncoder elevatorEncoder = elevatorMotor.getEncoder();
53+
private final RelativeEncoder elevatorFollowerEncoder = elevatorMotorFollower.getEncoder();
5354
private final DigitalInput bottomLimit = new DigitalInput(ELEVATOR_LIMIT_SWITCH);
5455

5556
private final DoubleTelemetryEntry voltageReq =
5657
new DoubleTelemetryEntry("/elevator/voltageReq", MiscConstants.TUNING_MODE);
58+
5759

5860
private final BooleanTelemetryEntry isHomedEntry =
5961
new BooleanTelemetryEntry("/elevator/isHomed", true);
@@ -62,13 +64,15 @@ public class ElevatorSubsystem extends SubsystemBase {
6264
private final EventTelemetryEntry elevatorEventEntry =
6365
new EventTelemetryEntry("/elevator/main/events");
6466
private final EventTelemetryEntry elevatorFollowerEventEntry = new EventTelemetryEntry("elevator/follower/events");
67+
private final DoubleTelemetryEntry followerVoltageReq = new DoubleTelemetryEntry("/elevator/followerReq", true);
6568

6669
private boolean isHomed = false;
6770

6871
public ElevatorSubsystem() {
6972
configMotors();
7073
controller.setTolerance(Units.inchesToMeters(0.5));
7174
setDefaultCommand(setVoltageCommand(0.0));
75+
// elevatorMotorFollower.follow(elevatorMotor);
7276
}
7377

7478
private void configMotors() {
@@ -130,38 +134,55 @@ private void configMotors() {
130134

131135

132136
ConfigurationUtils.applyCheckRecordRev(
133-
() -> elevatorMotorFollower.setCANTimeout(250),
134-
() -> true,
135-
followerFaultRecorder.run("CAN timeout"),
136-
MiscConstants.CONFIGURATION_ATTEMPTS);
137+
() -> elevatorMotorFollower.setCANTimeout(250),
138+
() -> true,
139+
faultRecorder.run("CAN timeout"),
140+
MiscConstants.CONFIGURATION_ATTEMPTS);
137141
ConfigurationUtils.applyCheckRecordRev(
138-
elevatorMotorFollower::restoreFactoryDefaults,
139-
() -> true,
140-
followerFaultRecorder.run("Factory default"),
141-
MiscConstants.CONFIGURATION_ATTEMPTS);
142+
elevatorMotorFollower::restoreFactoryDefaults,
143+
() -> true,
144+
faultRecorder.run("Factory default"),
145+
MiscConstants.CONFIGURATION_ATTEMPTS);
142146
ConfigurationUtils.applyCheckRecord(
143-
() -> elevatorMotorFollower.setInverted(FOLLOWER_INVERTED),
144-
() -> elevatorMotorFollower.getInverted() == FOLLOWER_INVERTED,
145-
() -> elevatorFollowerEventEntry.append("Motor invert"),
146-
MiscConstants.CONFIGURATION_ATTEMPTS);
147+
() -> elevatorMotorFollower.setInverted(MAIN_INVERTED),
148+
() -> elevatorMotorFollower.getInverted() == MAIN_INVERTED,
149+
() -> elevatorEventEntry.append("Motor invert"),
150+
MiscConstants.CONFIGURATION_ATTEMPTS);
151+
ConfigurationUtils.applyCheckRecordRev(
152+
() -> elevatorMotorFollower.setSmartCurrentLimit(STALL_MOTOR_CURRENT, FREE_MOTOR_CURRENT),
153+
() -> true,
154+
faultRecorder.run("Current limit"),
155+
MiscConstants.CONFIGURATION_ATTEMPTS);
156+
ConfigurationUtils.applyCheckRecordRev(
157+
() -> elevatorMotorFollower.setIdleMode(IdleMode.kBrake),
158+
() -> true,
159+
faultRecorder.run("Idle mode"),
160+
MiscConstants.CONFIGURATION_ATTEMPTS);
147161
ConfigurationUtils.applyCheckRecordRev(
148-
() -> elevatorMotorFollower.setSmartCurrentLimit(STALL_MOTOR_CURRENT, FREE_MOTOR_CURRENT),
149-
() -> true,
150-
followerFaultRecorder.run("Current limit"),
151-
MiscConstants.CONFIGURATION_ATTEMPTS);
162+
() -> elevatorFollowerEncoder.setPositionConversionFactor(METERS_PER_REV),
163+
() ->
164+
ConfigurationUtils.fpEqual(
165+
elevatorFollowerEncoder.getPositionConversionFactor(), METERS_PER_REV),
166+
faultRecorder.run("Position conversion factor"),
167+
MiscConstants.CONFIGURATION_ATTEMPTS);
152168
ConfigurationUtils.applyCheckRecordRev(
153-
() -> elevatorMotorFollower.setIdleMode(IdleMode.kBrake),
154-
() -> true,
155-
followerFaultRecorder.run("Idle mode"),
156-
MiscConstants.CONFIGURATION_ATTEMPTS);
169+
() -> elevatorFollowerEncoder.setVelocityConversionFactor(METERS_PER_REV / 60),
170+
() ->
171+
ConfigurationUtils.fpEqual(
172+
elevatorFollowerEncoder.getVelocityConversionFactor(), METERS_PER_REV / 60),
173+
faultRecorder.run("Velocity conversion factor"),
174+
MiscConstants.CONFIGURATION_ATTEMPTS);
157175
ConfigurationUtils.applyCheckRecordRev(
158-
elevatorMotorFollower::burnFlashWithDelay,
159-
() -> true,
160-
followerFaultRecorder.run("Burn flash"),
161-
MiscConstants.CONFIGURATION_ATTEMPTS);
176+
elevatorMotorFollower::burnFlashWithDelay,
177+
() -> true,
178+
faultRecorder.run("Burn flash"),
179+
MiscConstants.CONFIGURATION_ATTEMPTS);
180+
181+
162182

163183

164-
elevatorMotorFollower.follow(elevatorMotor, FOLLOWER_INVERTED);
184+
185+
// elevatorMotorFollower.follow(elevatorMotor, FOLLOWER_INVERTED);
165186
ConfigurationUtils.postDeviceConfig(
166187
followerFaultRecorder.hasFault(),
167188
elevatorEventEntry::append,
@@ -178,13 +199,20 @@ public boolean atBottomLimit() {
178199
public boolean atGoal() {
179200
return controller.atGoal();
180201
}
202+
public Command setFollowerCommand(double voltage){
203+
return this.run(() -> elevatorMotorFollower.setVoltage(voltage));
204+
}
181205

182206
public void setEncoderPosition(double position) {
183207
elevatorEncoder.setPosition(position);
208+
elevatorFollowerEncoder.setPosition(position);
209+
184210
}
185211

186212
public void setVoltage(double voltage) {
187213
elevatorMotor.setVoltage(voltage);
214+
elevatorMotorFollower.setVoltage(voltage);
215+
followerVoltageReq.append(voltage);
188216
voltageReq.append(voltage);
189217
}
190218

@@ -194,12 +222,15 @@ public double getPosition() {
194222

195223
public void stopMove() {
196224
elevatorMotor.setVoltage(0);
225+
elevatorMotorFollower.setVoltage(0);
197226
}
198227

199228
public boolean isHomed() {
200229
return isHomed;
201230
}
202231

232+
233+
203234
public Command setElevatorPositionCommand(double position) {
204235
double positionClamped = MathUtil.clamp(position, ELEVATOR_MIN_HEIGHT, ELEVATOR_MAX_HEIGHT);
205236
return RaiderCommands.ifCondition(this::isHomed)
@@ -220,7 +251,7 @@ public Command setElevatorPositionCommand(double position) {
220251
}
221252

222253
public Command probeHomeCommand() {
223-
return setVoltageCommand(-0.5).unless(this::isHomed).until(this::isHomed);
254+
return setVoltageCommand(-0.75).unless(this::isHomed).until(this::isHomed);
224255
}
225256

226257
public Command setVoltageCommand(double voltage) {

src/main/java/frc/robot/subsystems/swerve/SwerveModule.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,7 @@ private void configSteerMotor(SwerveModuleConfiguration config) {
214214
motorConfiguration.Feedback.FeedbackRemoteSensorID = config.steerEncoderID();
215215
motorConfiguration.Feedback.FeedbackSensorSource = FeedbackSensorSourceValue.RemoteCANcoder;
216216
motorConfiguration.Feedback.RotorToSensorRatio = config.sharedConfiguration().steerGearRatio();
217-
motorConfiguration.Feedback.SensorToMechanismRatio = config.sharedConfiguration().steerGearRatio();
218-
motorConfiguration.ClosedLoopGeneral.ContinuousWrap = true;
217+
motorConfiguration.ClosedLoopGeneral.ContinuousWrap = true;
219218

220219
config.sharedConfiguration().steerPositionPIDGains().setSlot(motorConfiguration.Slot0);
221220
config.sharedConfiguration().steerVelocityFFGains().setSlot(motorConfiguration.Slot0);
@@ -423,7 +422,7 @@ public void setRawVoltage(double driveVolts, double steerVolts) {
423422
}
424423

425424
private final MotionMagicExpoVoltage steerMotionMagicExpoVoltage =
426-
new MotionMagicExpoVoltage(0.0).withUpdateFreqHz(0.0);
425+
new MotionMagicExpoVoltage(0.0).withUpdateFreqHz(0);
427426

428427
private void setSteerReference(double targetAngleRadians, boolean activeSteer) {
429428
activeSteerEntry.append(activeSteer);

src/main/java/frc/robot/subsystems/transport/TransportSubsystem.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public void runShooterTransportVoltage(double voltage) {
4646
public TransportSubsystem() {
4747
configMotor();
4848
setDefaultCommand(setVoltageCommand(0.0));
49+
4950
}
5051

5152
public void configMotor() {

0 commit comments

Comments
 (0)