System.out.println("Getting Autonomous Command");
var waypoints = new ArrayList<Translation2d>();
TrajectoryConfig config = new TrajectoryConfig(.4, .4);
Trajectory trajectory = TrajectoryGenerator.generateTrajectory(
new Pose2d(),
waypoints,
new Pose2d(new Translation2d(1, 2), Rotation2d.fromDegrees(0)),
config
);
drivetrain.resetOdometry(trajectory.getInitialPose());
return new RamseteCommand(
trajectory,
drivetrain::getPose,
new RamseteController(2, .7),
drivetrain.getFeedForward(),
drivetrain.getKinematics(),
drivetrain::getWheelSpeeds,
drivetrain.getLeftController(),
drivetrain.getRightController(),
(leftVolts, rightVolts) -> {
System.out.println("Left volts: " + leftVolts + " | Right volts: " + rightVolts);
drivetrain.tankDriveVolts(leftVolts, rightVolts);
},
drivetrain
).andThen(() -> drivetrain.tankDriveVolts(0, 0));
The program prints:
Getting Autonomous Command
Left volts: 0.0| Right volts: 0.0
Command Scheduler loop overrun
…
Left volts: NaN | Right volts: NaN
Left volts: NaN | Right volts: NaN
Left volts: NaN | Right volts: NaN
…
We have had this same issue before using a PID loop for moving to an angle and tracking. Any help would be appreciated!
I was actually having this same issue. Are you doing this in sim using WPILib encoder objects? I found that their positions jumped to something like -430315 ticks and wouldn’t move.
I reported this bug a while ago, it was fixed in 2021.1.1-beta-3. It was caused by a division by dt (the time difference) between initialize() and execute() which was 0 when sim time was stopped. It was fixed. What WPILib version are you using?
Copied the command, seems like the NaN values are coming from the PID Command. After removing them, the robot seems to move, but not accurately (expected). We had this same problem when testing vision tracking.
Is this with simulation-stepped timing, or on a real robot? And when you say that the NaNs are coming from the PIDCommand, do you mean from the new command-based PIDCommand or the PIDControllers inside the RamseteCommand?
After upgrading, does the RamseteCommand still output NaNs?
How are leftVolts and rightVolts defined here? I suspect that these variables are local scope to your scheduling code, and have gone out of scope by the time the trajectory is running.
leftVolts and rightVolts are both parameters for the inline output function, and I’m pretty sure they are not out of scope; the only time they are defined and used is within that function.
This code is the only bit that relates to Ramsete Control (or our entire autonomous at this point), unless you’re talking about drivetrain config
My bad, I said PID Command instead of PID controller. The NaN is coming from the PID controllers, which were causing problems in both the Ramsete and PID commands.
NaNs, Infinity, and -Infinity occur when dividing by zero with doubles. I’ve gone over the PIDController code, it seems that the only div-by-0 possible is if period = 0. Make sure that you aren’t passing 0 as the fourth parameter to the PIDController constructor.