Skip to content

Commit 4039ff5

Browse files
committed
Major changes
1 parent f356523 commit 4039ff5

18 files changed

Lines changed: 134 additions & 81 deletions

src/main/java/frc/robot/BuildConstants.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ public final class BuildConstants {
55
public static final String MAVEN_GROUP = "";
66
public static final String MAVEN_NAME = "spike-rewrite";
77
public static final String VERSION = "unspecified";
8-
public static final int GIT_REVISION = 12;
9-
public static final String GIT_SHA = "daba3e29189bf5cfe92c48d83e22c333499d7057";
10-
public static final String GIT_DATE = "2025-08-06 23:05:38 EDT";
8+
public static final int GIT_REVISION = 14;
9+
public static final String GIT_SHA = "f356523e7c158ffe83ee8625cebc234a3cc908b5";
10+
public static final String GIT_DATE = "2025-08-07 23:17:27 EDT";
1111
public static final String GIT_BRANCH = "main";
12-
public static final String BUILD_DATE = "2025-08-07 23:10:24 EDT";
13-
public static final long BUILD_UNIX_TIME = 1754622624086L;
12+
public static final String BUILD_DATE = "2025-08-11 21:53:21 EDT";
13+
public static final long BUILD_UNIX_TIME = 1754963601492L;
1414
public static final int DIRTY = 1;
1515

1616
private BuildConstants() {}

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

Lines changed: 44 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,14 @@ public static final class DriveConstants {
131131
public static final LoggedTunableNumber kMeshDrivePriority =
132132
new LoggedTunableNumber("Meshed Drive Priority", 0.3);
133133

134+
public static final LoggedTunableNumber kDriveP = new LoggedTunableNumber("Drive P", 0.0);
135+
public static final LoggedTunableNumber kDriveI = new LoggedTunableNumber("Drive I", 0.0);
136+
public static final LoggedTunableNumber kDriveD = new LoggedTunableNumber("Drive D", 0.0);
137+
138+
public static final LoggedTunableNumber kTurnP = new LoggedTunableNumber("Drive Turn P", 3.0);
139+
public static final LoggedTunableNumber kTurnI = new LoggedTunableNumber("Drive Turn I", 0.0);
140+
public static final LoggedTunableNumber kTurnD = new LoggedTunableNumber("Drive Turn D", 0.0);
141+
134142
public static final LoggedTunableNumber kAutoscoreDeployDistance =
135143
new LoggedTunableNumber("Autoscore Deploy Distance", 42.0);
136144
public static final LoggedTunableNumber kAutoscoreOuttakeDistance =
@@ -157,37 +165,38 @@ public static final class ShooterConstants {
157165
public static final LoggedTunableNumber kIdleVoltage =
158166
new LoggedTunableNumber("Shooter idleVoltage", 0.0);
159167
public static final LoggedTunableNumber kTopRPS =
160-
new LoggedTunableNumber("Shooter topRPM", 20.0);
168+
new LoggedTunableNumber("Shooter topRPS", 20.0);
161169
public static final LoggedTunableNumber kBottomRPS =
162-
new LoggedTunableNumber("Shooter bottomRPM", 85.0);
170+
new LoggedTunableNumber("Shooter bottomRPS", 85.0);
163171
public static final LoggedTunableNumber kRejectingVoltage =
164-
new LoggedTunableNumber("Shooter rejectingVoltage", 7.0);
172+
new LoggedTunableNumber("Shooter rejectingVoltage", 4.0);
165173
public static final LoggedTunableNumber kTopAmpVelocity =
166174
new LoggedTunableNumber("Shooter topAmpVelocity", -3.5);
167175
public static final LoggedTunableNumber kBottomAmpVelocity =
168176
new LoggedTunableNumber("Shooter bottomAmpVelocity", 58.0);
169177

170178
public static final LoggedTunableNumber kTopShooterP =
171-
new LoggedTunableNumber("Shooter TopP", 0.0);
179+
new LoggedTunableNumber("Shooter TopP", 0.005);
172180
public static final LoggedTunableNumber kTopShooterI =
173181
new LoggedTunableNumber("Shooter TopI", 0.0);
174182
public static final LoggedTunableNumber kTopShooterD =
175183
new LoggedTunableNumber("Shooter TopD", 0.0);
176184
public static final LoggedTunableNumber kBottomShooterP =
177-
new LoggedTunableNumber("Shooter BottomP", 0.0);
185+
new LoggedTunableNumber("Shooter BottomP", 0.005);
178186
public static final LoggedTunableNumber kBottomShooterI =
179187
new LoggedTunableNumber("Shooter BottomI", 0.0);
180188
public static final LoggedTunableNumber kBottomShooterD =
181189
new LoggedTunableNumber("Shooter BottomD", 0.0);
182190

183-
public static final LoggedTunableNumber kTopKs = new LoggedTunableNumber("Shooter TopKs", 0.0);
184-
public static final LoggedTunableNumber kTopKv = new LoggedTunableNumber("Shooter TopKv", 0.0);
191+
public static final LoggedTunableNumber kTopKs = new LoggedTunableNumber("Shooter TopKs", 0.14);
192+
public static final LoggedTunableNumber kTopKv =
193+
new LoggedTunableNumber("Shooter TopKv", 0.125);
185194
public static final LoggedTunableNumber kBottomKs =
186-
new LoggedTunableNumber("Shooter BottomKs", 0.0);
195+
new LoggedTunableNumber("Shooter BottomKs", 0.14);
187196
public static final LoggedTunableNumber kBottomKv =
188-
new LoggedTunableNumber("Shooter BottomKv", 0.0);
197+
new LoggedTunableNumber("Shooter BottomKv", 0.125);
189198

190-
public static final double kVelocityTolerance = 0.1; // in RPM
199+
public static final double kVelocityTolerance = 0.1;
191200

192201
// sim
193202
public static final DCMotor kTopDCMotor = DCMotor.getNEO(1);
@@ -223,11 +232,11 @@ public static final class IndexerConstants {
223232
public static final LoggedTunableNumber kIdleVoltage =
224233
new LoggedTunableNumber("Indexer idleVoltage", 0.0);
225234
public static final LoggedTunableNumber kIntakingVoltage =
226-
new LoggedTunableNumber("Indexer intakingVoltage", 12.0);
235+
new LoggedTunableNumber("Indexer intakingVoltage", -6.0);
227236
public static final LoggedTunableNumber kShootingVoltage =
228-
new LoggedTunableNumber("Indexer shootingVoltage", 8.0);
237+
new LoggedTunableNumber("Indexer shootingVoltage", -8.0);
229238
public static final LoggedTunableNumber kVomitVoltage =
230-
new LoggedTunableNumber("Indexer vomitVoltage", -8.0);
239+
new LoggedTunableNumber("Indexer vomitVoltage", 6.0);
231240

232241
// sim
233242
public static final DCMotor kDCMotor = DCMotor.getNEO(1);
@@ -239,9 +248,9 @@ public static final class IntakeConstants {
239248
public static final LoggedTunableNumber kIdleVoltage =
240249
new LoggedTunableNumber("Intake idleVoltage", 0.0);
241250
public static final LoggedTunableNumber kIntakingVoltage =
242-
new LoggedTunableNumber("Intake intakingVoltage", 10.0);
251+
new LoggedTunableNumber("Intake intakingVoltage", -6.0);
243252
public static final LoggedTunableNumber kVomitVoltage =
244-
new LoggedTunableNumber("Intake vomitVoltage", -8.0);
253+
new LoggedTunableNumber("Intake vomitVoltage", 7.0);
245254

246255
// sim
247256
public static final DCMotor kDCMotor = DCMotor.getNEO(1);
@@ -250,32 +259,33 @@ public static final class IntakeConstants {
250259
}
251260

252261
public static final class Ports {
253-
public static final int kFrontLeftDrive = 0;
254-
public static final int kFrontLeftTurn = 1;
255-
public static final int kFrontLeftCancoder = 2;
262+
public static final int kFrontLeftDrive = 1;
263+
public static final int kFrontLeftTurn = 2;
264+
public static final int kFrontLeftCancoder = 3;
256265

257-
public static final int kFrontRightDrive = 3;
258-
public static final int kFrontRightTurn = 4;
259-
public static final int kFrontRightCancoder = 5;
266+
public static final int kFrontRightDrive = 4;
267+
public static final int kFrontRightTurn = 5;
268+
public static final int kFrontRightCancoder = 6;
260269

261-
public static final int kBackLeftDrive = 6;
262-
public static final int kBackLeftTurn = 7;
263-
public static final int kBackLeftCancoder = 8;
270+
public static final int kBackLeftDrive = 7;
271+
public static final int kBackLeftTurn = 8;
272+
public static final int kBackLeftCancoder = 9;
264273

265-
public static final int kBackRightDrive = 9;
266-
public static final int kBackRightTurn = 10;
267-
public static final int kBackRightCancoder = 11;
274+
public static final int kBackRightDrive = 10;
275+
public static final int kBackRightTurn = 11;
276+
public static final int kBackRightCancoder = 12;
268277

269-
public static final int kIndexer = 12;
270-
public static final int kPhotoelectric1 = 13;
271-
public static final int kPhotoelectric2 = 14;
278+
public static final int kPigeon = 22;
272279

273-
public static final int kIntake = 15;
280+
public static final String kCanivoreName = "Drivetrain";
274281

275-
public static final int kTopShooter = 16;
276-
public static final int kBottomShooter = 17;
282+
public static final int kIntakeNeo = 13;
283+
public static final int kIndexerNeo = 14;
284+
public static final int kTopFlywheel = 15;
285+
public static final int kBottomFlywheel = 16;
277286

278-
public static final int kPigeon = 22;
287+
public static final int kPhotoElectricOne = 8;
288+
public static final int kPhotoElectricTwo = 9;
279289

280290
public static final String kDriveCanivoreName = "Drivetrain";
281291

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,12 @@ private void configureSubsystems() {
6262
new ModuleIOSparkMax(3));
6363
m_indexer =
6464
new Indexer(
65-
new IndexerIONeo(Ports.kIndexer, Ports.kPhotoelectric1, Ports.kPhotoelectric2));
66-
m_intake = new Intake(new IntakeIONeo(Ports.kIntake));
65+
new IndexerIONeo(
66+
Ports.kIndexerNeo, Ports.kPhotoElectricOne, Ports.kPhotoElectricTwo));
67+
m_intake = new Intake(new IntakeIONeo(Ports.kIntakeNeo));
6768
m_shooter =
6869
new Shooter(
69-
new ShooterIONeo(Ports.kTopShooter, Ports.kBottomShooter),
70+
new ShooterIONeo(Ports.kTopFlywheel, Ports.kBottomFlywheel),
7071
new PIDController(
7172
ShooterConstants.kTopShooterP.getAsDouble(),
7273
ShooterConstants.kTopShooterI.getAsDouble(),

src/main/java/frc/robot/RobotState.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ private RobotState(Drive drive, Shooter shooter, Indexer indexer, Intake intake)
5555
Map<RobotAction, Runnable> periodicHash = new HashMap<>();
5656

5757
periodicHash.put(RobotAction.kTeleopDefault, () -> {});
58-
periodicHash.put(RobotAction.kIntake, () -> {});
58+
periodicHash.put(RobotAction.kIntake, this::intakingPeriodic);
5959
periodicHash.put(RobotAction.kVomitting, () -> {});
6060
periodicHash.put(RobotAction.kAlignShooting, this::alignShootingPeriodic);
6161
periodicHash.put(RobotAction.kSubwooferShooting, this::revPeriodic);
@@ -123,6 +123,12 @@ public void ampPeriodic() {
123123
m_drive.setDesiredHeading(Rotation2d.fromDegrees(90));
124124
}
125125

126+
public void intakingPeriodic() {
127+
if (m_indexer.indexerHasGamePiece()) {
128+
m_intake.updateState(IntakeState.kIdle);
129+
}
130+
}
131+
126132
public void updateAction(RobotAction action) {
127133
DriveProfiles newDriveProfile = DriveProfiles.kDefault;
128134
IndexerState newIndexerState = IndexerState.kIdle;

src/main/java/frc/robot/subsystems/drive/Module.java

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import edu.wpi.first.math.kinematics.SwerveModulePosition;
66
import edu.wpi.first.math.kinematics.SwerveModuleState;
77
import edu.wpi.first.wpilibj.RobotBase;
8+
import frc.lib.littletonUtils.LoggedTunableNumber;
89
import frc.robot.Constants.DriveConstants;
910
import org.littletonrobotics.junction.Logger;
1011

@@ -24,9 +25,11 @@ public Module(ModuleIO io, int index) {
2425
// Switch constants based on mode (the physics simulator is treated as a
2526
// separate robot with different tuning)
2627
if (RobotBase.isReal()) {
27-
m_driveFeedforward = new SimpleMotorFeedforward(0.22810, 0.13319);
28-
m_io.setDrivePID(2.0, 0.0, 0.0);
29-
m_io.setTurnPID(300.0, 0.0, 0.0);
28+
m_driveFeedforward = new SimpleMotorFeedforward(0.22810, 0.23319);
29+
m_io.setDrivePID(
30+
DriveConstants.kDriveP.get(), DriveConstants.kDriveI.get(), DriveConstants.kDriveI.get());
31+
m_io.setTurnPID(
32+
DriveConstants.kTurnP.get(), DriveConstants.kTurnI.get(), DriveConstants.kTurnD.get());
3033
} else {
3134
m_driveFeedforward = new SimpleMotorFeedforward(0.0, 0.13);
3235
m_io.setDrivePID(0.1, 0.0, 0.0);
@@ -59,6 +62,30 @@ public void periodic() {
5962
Rotation2d angle = m_inputs.odometryTurnPositions[i];
6063
m_odometryPositions[i] = new SwerveModulePosition(positionMeters, angle);
6164
}
65+
66+
LoggedTunableNumber.ifChanged(
67+
hashCode(),
68+
() -> {
69+
m_io.setDrivePID(
70+
DriveConstants.kDriveP.get(),
71+
DriveConstants.kDriveI.get(),
72+
DriveConstants.kDriveD.get());
73+
},
74+
DriveConstants.kDriveP,
75+
DriveConstants.kDriveI,
76+
DriveConstants.kDriveD);
77+
78+
LoggedTunableNumber.ifChanged(
79+
hashCode(),
80+
() -> {
81+
m_io.setTurnPID(
82+
DriveConstants.kTurnP.get(),
83+
DriveConstants.kTurnI.get(),
84+
DriveConstants.kTurnD.get());
85+
},
86+
DriveConstants.kTurnP,
87+
DriveConstants.kTurnI,
88+
DriveConstants.kTurnD);
6289
}
6390

6491
/** Runs the module with the specified setpoint state. */
@@ -102,7 +129,7 @@ public void setDriveBrakeMode(boolean enabled) {
102129

103130
/** Returns the current turn angle of the module. */
104131
public Rotation2d getAngle() {
105-
return m_inputs.turnPosition;
132+
return m_inputs.turnAbsolutePosition;
106133
}
107134

108135
/** Returns the current drive position of the module in meters. */

src/main/java/frc/robot/subsystems/drive/ModuleIOSparkMax.java

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
package frc.robot.subsystems.drive;
1515

16+
import static edu.wpi.first.units.Units.Degrees;
17+
import static edu.wpi.first.units.Units.Radians;
1618
import static edu.wpi.first.units.Units.Revolutions;
1719

1820
import com.ctre.phoenix6.BaseStatusSignal;
@@ -33,13 +35,15 @@
3335
import com.revrobotics.spark.config.SparkBaseConfig;
3436
import com.revrobotics.spark.config.SparkBaseConfig.IdleMode;
3537
import com.revrobotics.spark.config.SparkMaxConfig;
38+
import edu.wpi.first.math.controller.PIDController;
3639
import edu.wpi.first.math.geometry.Rotation2d;
3740
import edu.wpi.first.math.util.Units;
3841
import edu.wpi.first.units.measure.Angle;
3942
import frc.robot.Constants.DriveConstants;
4043
import frc.robot.Constants.Ports;
4144
import java.util.OptionalDouble;
4245
import java.util.Queue;
46+
import org.littletonrobotics.junction.Logger;
4347

4448
/**
4549
* Module IO implementation for SparkMax drive motor controller, SparkMax turn motor controller (NEO
@@ -65,14 +69,20 @@ public class ModuleIOSparkMax implements ModuleIO {
6569
private final Queue<Double> m_drivePositionQueue;
6670
private final Queue<Double> m_turnPositionQueue;
6771

68-
private StatusSignal<Angle> m_turnAbsolutePosition;
72+
private final StatusSignal<Angle> m_turnAbsolutePosition;
6973

7074
private final boolean m_isTurnMotorInverted = true;
7175
private final Rotation2d m_absoluteEncoderOffset;
7276

7377
private final SparkBaseConfig m_driveConfig;
7478
private final SparkBaseConfig m_turnConfig;
7579

80+
private final PIDController m_turnController = new PIDController(0, 0, 0);
81+
82+
{
83+
m_turnController.enableContinuousInput(-Math.PI, Math.PI);
84+
}
85+
7686
public ModuleIOSparkMax(int index) {
7787
switch (index) {
7888
case 0:
@@ -230,9 +240,11 @@ public void setDriveVelocity(double velocityRadPerSec, double feedforward) {
230240

231241
@Override
232242
public void setTurnPosition(Rotation2d position) {
233-
m_turnSparkMax
234-
.getClosedLoopController()
235-
.setReference(position.getMeasure().in(Revolutions), ControlType.kPosition);
243+
Logger.recordOutput("Setpoint/positionTurn", position.getDegrees());
244+
Logger.recordOutput("Setpoint/CancoderAngle", m_turnAbsolutePosition.getValue().in(Degrees));
245+
m_turnSparkMax.setVoltage(
246+
m_turnController.calculate(
247+
m_turnAbsolutePosition.getValue().in(Radians), position.getRadians()));
236248
}
237249

238250
@Override
@@ -270,9 +282,7 @@ public void setDrivePID(double kP, double kI, double kD) {
270282

271283
@Override
272284
public void setTurnPID(double kP, double kI, double kD) {
273-
m_turnConfig.closedLoop.pid(kP, kI, kD);
274-
m_turnSparkMax.configure(
275-
m_turnConfig, ResetMode.kNoResetSafeParameters, PersistMode.kNoPersistParameters);
285+
m_turnController.setPID(kP, kI, kD);
276286
}
277287

278288
@Override

src/main/java/frc/robot/subsystems/indexer/Indexer.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,8 @@ public void updateState(IndexerState state) {
6767
public IndexerState getIndexerState() {
6868
return m_profiles.getCurrentProfile();
6969
}
70+
71+
public boolean indexerHasGamePiece() {
72+
return m_inputs.hasPiece;
73+
}
7074
}

src/main/java/frc/robot/subsystems/indexer/IndexerIO.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@
33
import org.littletonrobotics.junction.AutoLog;
44

55
public interface IndexerIO {
6-
// TODO: make sim better
76
@AutoLog
87
public class IndexerInputs {
98
double voltage;
10-
double velocityRPM;
9+
double velocityRPS;
1110
boolean hasPiece;
1211
boolean photoelectric1Raw;
1312
boolean photoelectric2Raw;

src/main/java/frc/robot/subsystems/indexer/IndexerIONeo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public IndexerIONeo(int motorPort, int sensorPort1, int sensorPort2) {
2828
@Override
2929
public void updateInputs(IndexerInputs inputs) {
3030
inputs.voltage = m_motor.getBusVoltage() * m_motor.getAppliedOutput();
31-
inputs.velocityRPM = m_encoder.getVelocity() / 60;
31+
inputs.velocityRPS = m_encoder.getVelocity() / 60;
3232
inputs.hasPiece = !m_sensor1.get() || !m_sensor2.get();
3333
inputs.current = m_motor.getOutputCurrent();
3434
inputs.photoelectric1Raw = m_sensor1.get();

src/main/java/frc/robot/subsystems/indexer/IndexerIOSim.java

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

33
import edu.wpi.first.math.system.plant.LinearSystemId;
4-
import edu.wpi.first.math.util.Units;
54
import edu.wpi.first.wpilibj.DigitalInput;
65
import edu.wpi.first.wpilibj.simulation.DCMotorSim;
76
import frc.robot.Constants.IndexerConstants;
@@ -20,8 +19,8 @@ public IndexerIOSim() {
2019
IndexerConstants.kDCMotor, IndexerConstants.kSimMOI, IndexerConstants.kSimGearing),
2120
IndexerConstants.kDCMotor);
2221
m_voltage = 0.0;
23-
m_sensor1 = new DigitalInput(Ports.kPhotoelectric1);
24-
m_sensor2 = new DigitalInput(Ports.kPhotoelectric2);
22+
m_sensor1 = new DigitalInput(Ports.kPhotoElectricOne);
23+
m_sensor2 = new DigitalInput(Ports.kPhotoElectricTwo);
2524
}
2625

2726
public void updateInputs(IndexerInputs inputs) {
@@ -30,7 +29,7 @@ public void updateInputs(IndexerInputs inputs) {
3029

3130
inputs.hasPiece = !m_sensor1.get() || !m_sensor2.get();
3231
inputs.voltage = m_voltage;
33-
inputs.velocityRPM = Units.radiansPerSecondToRotationsPerMinute(m_sim.getAngularVelocityRadPerSec()) / 60;
32+
inputs.velocityRPS = m_sim.getAngularVelocityRPM() / 60;
3433
}
3534

3635
@Override

0 commit comments

Comments
 (0)