99
1010import static edu .wpi .first .units .Units .*;
1111
12- // import com.pathplanner.lib.auto.AutoBuilder;
13- // import com.pathplanner.lib.config.ModuleConfig;
14- // import com.pathplanner.lib.config.PIDConstants;
15- // import com.pathplanner.lib.config.RobotConfig;
16- // import com.pathplanner.lib.controllers.PPHolonomicDriveController;
17- // import com.pathplanner.lib.pathfinding.Pathfinding;
18- // import com.pathplanner.lib.util.PathPlannerLogging;
12+ import choreo .trajectory .SwerveSample ;
1913import edu .wpi .first .hal .FRCNetComm .tInstances ;
2014import edu .wpi .first .hal .FRCNetComm .tResourceType ;
2115import edu .wpi .first .hal .HAL ;
3226import edu .wpi .first .math .kinematics .SwerveModuleState ;
3327import edu .wpi .first .math .numbers .N1 ;
3428import edu .wpi .first .math .numbers .N3 ;
35- import edu .wpi .first .math .system .plant .DCMotor ;
3629import edu .wpi .first .wpilibj .Alert ;
3730import edu .wpi .first .wpilibj .Alert .AlertType ;
3831import edu .wpi .first .wpilibj .DriverStation ;
39- import edu .wpi .first .wpilibj .DriverStation .Alliance ;
4032import edu .wpi .first .wpilibj2 .command .Command ;
4133import edu .wpi .first .wpilibj2 .command .SubsystemBase ;
4234import edu .wpi .first .wpilibj2 .command .sysid .SysIdRoutine ;
4335import frc .robot .Constants ;
4436import frc .robot .Constants .Mode ;
4537import frc .robot .generated .TunerConstants ;
46- //import frc.robot.util.LocalADStarAK;
38+ // import frc.robot.util.LocalADStarAK;
4739import java .util .concurrent .locks .Lock ;
4840import java .util .concurrent .locks .ReentrantLock ;
4941import org .littletonrobotics .junction .AutoLogOutput ;
5042import org .littletonrobotics .junction .Logger ;
5143
52- import choreo .auto .AutoFactory ;
53- import choreo .trajectory .SwerveSample ;
54-
5544public class Drive extends SubsystemBase {
5645 private final PIDController xController = new PIDController (10.0 , 0.0 , 0.0 );
5746 private final PIDController yController = new PIDController (10.0 , 0.0 , 0.0 );
5847 private final PIDController headingController = new PIDController (7.5 , 0.0 , 0.0 );
59-
48+
6049 // TunerConstants doesn't include these constants, so they are declared locally
6150 static final double ODOMETRY_FREQUENCY = TunerConstants .kCANBus .isNetworkFD () ? 250.0 : 100.0 ;
6251 public static final double DRIVE_BASE_RADIUS =
@@ -117,7 +106,7 @@ public Drive(
117106 modules [1 ] = new Module (frModuleIO , 1 , TunerConstants .FrontRight );
118107 modules [2 ] = new Module (blModuleIO , 2 , TunerConstants .BackLeft );
119108 modules [3 ] = new Module (brModuleIO , 3 , TunerConstants .BackRight );
120-
109+
121110 headingController .enableContinuousInput (-Math .PI , Math .PI );
122111
123112 // Usage reporting for swerve template
@@ -147,7 +136,6 @@ public Drive(
147136 // Logger.recordOutput("Odometry/TrajectorySetpoint", targetPose);
148137 // });
149138
150-
151139 // Configure SysId
152140 sysId =
153141 new SysIdRoutine (
@@ -160,19 +148,18 @@ public Drive(
160148 (voltage ) -> runCharacterization (voltage .in (Volts )), null , this ));
161149 }
162150
163- public void followTrajectory (SwerveSample sample ) {
164- // Get the current pose of the robot
165- Pose2d pose = getPose ();
151+ public void followTrajectory (SwerveSample sample ) {
152+ // Get the current pose of the robot
153+ Pose2d pose = getPose ();
166154
167- // Generate the next speeds for the robot
168- ChassisSpeeds speeds = new ChassisSpeeds (
155+ // Generate the next speeds for the robot
156+ ChassisSpeeds speeds =
157+ new ChassisSpeeds (
169158 sample .vx + xController .calculate (pose .getX (), sample .x ),
170159 sample .vy + yController .calculate (pose .getY (), sample .y ),
171- sample .omega + headingController .calculate (pose .getRotation ().getRadians (), sample .heading )
172- );
173-
174-
175- }
160+ sample .omega
161+ + headingController .calculate (pose .getRotation ().getRadians (), sample .heading ));
162+ }
176163
177164 @ Override
178165 public void periodic () {
0 commit comments