I originally tried the WPILib Swerve example and based it on that, the original problems with that were the offsets and problems with drift in the CANCoders.
so I switched over to the SwerveLib by Sds, I was able to get the robot to drive properly and work to my standers during teleop. Now I’m trying to add in some trajectories and waypoints for auto
I haven’t been able to test the most recent iteration of my code due to hurricane Ian, when I did test with some older code it would zero my modules after a few seconds it would say the command finished.
the current error I can see is in RobotContainer with my test command with the “SwerveControllerCommand” there is an error with my “setModuleStates” & “getPose”
public Command getAutonomousCommand() {
//run in autonomous
TrajectoryConfig trajectoryConfig = new TrajectoryConfig(
Constants.AutoConstants.kMaxSpeedMetersPerSecond,
Constants.AutoConstants.kMaxAccelerationMetersPerSecondSquared)
.setKinematics(Constants.SwerveDrive.m_kinematics);
Trajectory trajectory = TrajectoryGenerator.generateTrajectory(
new Pose2d(0,0,new Rotation2d(0)),
List.of(
new Translation2d(1,0),
new Translation2d(1,-1)
),
new Pose2d(2,-1, Rotation2d.fromDegrees(180)),
trajectoryConfig
);
PIDController xController = new PIDController(Constants.AutoConstants.kPXController, 0, 0);
PIDController yController = new PIDController(Constants.AutoConstants.kPYController, 0, 0);
ProfiledPIDController thetaController = new ProfiledPIDController(
Constants.AutoConstants.kPThetaController, 0, 0, Constants.AutoConstants.kThetaControllerConstraints);
thetaController.enableContinuousInput(-Math.PI, Math.PI);
SwerveControllerCommand swerveControllerCommand = new SwerveControllerCommand(
trajectory,
SwerveDriveTrain::getPose,
Constants.SwerveDrive.m_kinematics,
xController,
yController,
thetaController,
SwerveDriveTrain::setModuleStates,
s_swervedrivetrain
);
return SequentialCommandGroup(
new InstantCommand(() -> s_swervedrivetrain.resetOdometry(trajectory.getInitialPose())),
swerveControllerCommand,
new InstantCommand(() -> s_swervedrivetrain.stopModules())
);
}
errors
[{“resource”: “src/main/java/frc/robot/RobotContainer.java”,
“message”: “Cannot make a static reference to the non-static method getPose() from the type SwerveDriveTrain”,
“LineNumber”: 154,
},
{“resource”: “src/main/java/frc/robot/RobotContainer.java”,
“message”: “Cannot make a static reference to the non-static method setModuleStates(SwerveModuleState[]) from the type SwerveDriveTrain”,
“LineNumber”: 159,
}]