Wheels move at random when trying to follow path

Hello,
I am using a trajectory generator to generate a path and a SwerveControllerCommand to control the modules like the following:

Trajectory exampletrajectory = TrajectoryGenerator,generateTrajectory(new Pose2d(0, 0, new Rotation2d(0)), List.of(), new Pose2d(1, 0, new Rotation2d(0)), config); 
var thetaController = new ProfiledPiDCOntroller(Constants.AutoConstants.kPThetaController, 0, 0, Constants.AutoConstants.kThetaControllerCOnstraints); 

SwerveControllerCommand swerveControllerCOmmand = new SwerveControllerCommand(exampleTrajectory, s_Swerve::getPose, Constants.Swerve.swerveKinematics, new PIDController(Constants.AutoConstants.kPXController, 0, 0), new PIDController(Constants.AutoCOnstants.kPYController, 0, 0), thetaController, s_Swerve::setModuleStates, s_Swerve);
addCommands(swerveControllerCommand);

For some reason, when I run this auton path, the robot’s wheels seem to jitter around in random directions almost, and behave randomly. Sometimes when I run the code, the robot goes forwards, while other times it goes backwards and sometimes it doesn’t even move.

I would start by making an InstantCommand to zero the drive encoders, that way it will likely fix the backward driving issue. Other than that, have you run the sysid tool on your robot?

No, would that be the root of the problem?

That could be. The values given in the tutorial are very robot specific so that could cause the jittering.

It turns out the jittering was just because of a high p value. The issue is probably because I didn’t characterize the drivetrain .

1 Like

One more question: how do I make the robot go backwards using a trajectory generator. When I try to set the final poses x value to a negative number, it gives me could not parameterize spline error

There should be a setting when generating the trajectory to make it revered. setReversed(boolean reversed) should do the trick.

1 Like

Wait, I don’t see that method. if example Trajectory was my trajectory, would this be what your talking about:

exampleTrajectory.setReversed(true);

Oh wait, nevermind I found it