Here is the function we are using to generate trajectories:
public final static Trajectory generateTrajectory(Pose2d start, List<Translation2d> waypoints, Pose2d end, boolean reversed, double maxVelocity, double maxAccel, double startVelocity, double endVelocity, double maxVoltage) {
DifferentialDriveVoltageConstraint autoVoltageConstraint = new DifferentialDriveVoltageConstraint(new SimpleMotorFeedforward(Constants.ks, Constants.kv, Constants.ka), Constants.kDriveKinematics, maxVoltage);
TrajectoryConfig config = new TrajectoryConfig(maxVelocity, maxAccel).setKinematics(Constants.kDriveKinematics).addConstraint(autoVoltageConstraint);
config.setStartVelocity(startVelocity);
config.setEndVelocity(endVelocity);
config.setReversed(reversed);
return TrajectoryGenerator.generateTrajectory(start, waypoints, end, config);
}
This Trajectory works well:
generateTrajectory(
new Pose2d(0,0, new Rotation2d(0)),
List.of(new Translation2d(1,0.1), new Translation2d(2,1)),
new Pose2d(3,0, new Rotation2d(0)),
false, 2, 1, 0, 0, 5
))
However, when we try to make a trajectory for the robot to drive backward, it fails.
TrajectoryHelper.generateTrajectory(new Pose2d(3,0, new Rotation2d(0)),
List.of(new Translation2d(2,1), new Translation2d(1,1)),
new Pose2d(0,1, new Rotation2d(0)),
true, 2, 1, 0, 0, 5))
The error we get is “The trajectory’s minimum velocity was greater than its maximum velocity.”
How do we follow trajectories backward? What are we doing wrong?