2
2
3
3
import com .pathplanner .lib .util .DriveFeedforwards ;
4
4
import com .pathplanner .lib .util .swerve .SwerveSetpoint ;
5
- import com .pathplanner .lib .util .swerve .SwerveSetpointGenerator ;
6
5
import edu .wpi .first .math .geometry .Pose2d ;
7
6
import edu .wpi .first .math .geometry .Rotation2d ;
8
7
import edu .wpi .first .math .geometry .Translation3d ;
19
18
import frc .trigon .robot .subsystems .MotorSubsystem ;
20
19
import frc .trigon .robot .subsystems .swerve .swervemodule .SwerveModule ;
21
20
import frc .trigon .robot .subsystems .swerve .swervemodule .SwerveModuleConstants ;
22
- import lib .hardware .RobotHardwareStats ;
23
21
import lib .hardware .phoenix6 .Phoenix6SignalThread ;
24
22
import lib .hardware .phoenix6 .pigeon2 .Pigeon2Gyro ;
25
23
import lib .hardware .phoenix6 .pigeon2 .Pigeon2Signal ;
@@ -33,10 +31,8 @@ public class Swerve extends MotorSubsystem {
33
31
private final Pigeon2Gyro gyro = SwerveConstants .GYRO ;
34
32
private final SwerveModule [] swerveModules = SwerveConstants .SWERVE_MODULES ;
35
33
private final Phoenix6SignalThread phoenix6SignalThread = Phoenix6SignalThread .getInstance ();
36
- private final SwerveSetpointGenerator setpointGenerator = new SwerveSetpointGenerator (AutonomousConstants .ROBOT_CONFIG , SwerveModuleConstants .MAXIMUM_MODULE_ROTATIONAL_SPEED_RADIANS_PER_SECOND );
37
34
public Pose2d targetPathPlannerPose = new Pose2d ();
38
35
public boolean isPathPlannerDriving = false ;
39
- private SwerveSetpoint previousSetpoint = new SwerveSetpoint (getSelfRelativeVelocity (), getModuleStates (), DriveFeedforwards .zeros (AutonomousConstants .ROBOT_CONFIG .numModules ));
40
36
41
37
public Swerve () {
42
38
setName ("Swerve" );
@@ -53,7 +49,7 @@ public void setBrake(boolean brake) {
53
49
public void sysIDDrive (double targetCurrent ) {
54
50
SwerveModuleState [] a = SwerveConstants .KINEMATICS .toSwerveModuleStates (new ChassisSpeeds (0 , 0 , 2 ));
55
51
for (int i = 0 ; i < 4 ; i ++) {
56
- swerveModules [i ].setDriveMotorTargetCurrent (targetCurrent );
52
+ swerveModules [i ].setDriveMotorTargetVoltage (targetCurrent );
57
53
swerveModules [i ].setTargetAngle (a [i ].angle );
58
54
}
59
55
}
@@ -176,33 +172,22 @@ public void drivePathPlanner(ChassisSpeeds targetPathPlannerFeedforwardSpeeds, b
176
172
* Used for PathPlanner because it generates setpoints automatically.
177
173
*
178
174
* @param targetSpeeds the pre generated robot relative target speeds
179
- * @param feedforwards the feedforwards to use
180
175
*/
181
- public void selfRelativeDriveWithoutSetpointGeneration (ChassisSpeeds targetSpeeds , DriveFeedforwards feedforwards ) {
176
+ public void selfRelativeDriveWithoutSetpointGeneration (ChassisSpeeds targetSpeeds ) {
182
177
// if (isStill(targetSpeeds)) {
183
178
// stop();
184
179
// return;
185
180
// }
186
181
187
182
final SwerveModuleState [] swerveModuleStates = SwerveConstants .KINEMATICS .toSwerveModuleStates (targetSpeeds );
188
- final double [] targetForcesNm ;
189
- if (feedforwards == null )
190
- targetForcesNm = new double []{0 , 0 , 0 , 0 };
191
- else
192
- targetForcesNm = feedforwards .linearForcesNewtons ();
193
-
194
- setTargetModuleStates (swerveModuleStates , targetForcesNm );
183
+ setTargetModuleStates (swerveModuleStates );
195
184
}
196
185
197
186
public Rotation2d getDriveRelativeAngle () {
198
187
final Rotation2d currentAngle = RobotContainer .ROBOT_POSE_ESTIMATOR .getEstimatedRobotPose ().getRotation ();
199
188
return Flippable .isRedAlliance () ? currentAngle .rotateBy (Rotation2d .fromDegrees (180 )) : currentAngle ;
200
189
}
201
190
202
- public void resetSetpoint () {
203
- previousSetpoint = new SwerveSetpoint (getSelfRelativeVelocity (), getModuleStates (), DriveFeedforwards .zeros (AutonomousConstants .ROBOT_CONFIG .numModules ));
204
- }
205
-
206
191
public void initializeDrive (boolean shouldUseClosedLoop ) {
207
192
setClosedLoop (shouldUseClosedLoop );
208
193
resetRotationController ();
@@ -279,23 +264,18 @@ void selfRelativeDrive(double xPower, double yPower, FlippableRotation2d targetA
279
264
* @param targetSpeeds the desired robot-relative targetSpeeds
280
265
*/
281
266
public void selfRelativeDrive (ChassisSpeeds targetSpeeds ) {
282
- previousSetpoint = setpointGenerator .generateSetpoint (
283
- previousSetpoint ,
284
- targetSpeeds ,
285
- RobotHardwareStats .getPeriodicTimeSeconds ()
286
- );
287
-
288
- // if (isStill(previousSetpoint.robotRelativeSpeeds())) {
267
+ // if (isStill(targetSpeeds) {
289
268
// stop();
290
269
// return;
291
270
// }
292
271
293
- setTargetModuleStates (previousSetpoint .moduleStates (), previousSetpoint .feedforwards ().linearForcesNewtons ());
272
+ final SwerveModuleState [] swerveModuleStates = SwerveConstants .KINEMATICS .toSwerveModuleStates (targetSpeeds );
273
+ setTargetModuleStates (swerveModuleStates );
294
274
}
295
275
296
- private void setTargetModuleStates (SwerveModuleState [] swerveModuleStates , double [] targetForcesNm ) {
276
+ private void setTargetModuleStates (SwerveModuleState [] swerveModuleStates ) {
297
277
for (int i = 0 ; i < swerveModules .length ; i ++)
298
- swerveModules [i ].setTargetState (swerveModuleStates [i ], targetForcesNm [ i ] );
278
+ swerveModules [i ].setTargetState (swerveModuleStates [i ]);
299
279
}
300
280
301
281
private void setClosedLoop (boolean shouldUseClosedLoop ) {
0 commit comments