A problem when using trajectory in a swerve drive

l use PathWeaver to draw a path and build it in the src/main/deploy . Then l use code to get it , code is below:

    try {
      Path trajectoryPath = Filesystem.getDeployDirectory().toPath().resolve(trajectoryJSON);
      trajectory = TrajectoryUtil.fromPathweaverJson(trajectoryPath);
   } catch (IOException ex) {
      DriverStation.reportError("Unable to open trajectory: " + trajectoryJSON, ex.getStackTrace());

Then l use the code to generate it

    SwerveControllerCommand swerveControllerCommand =
        new SwerveControllerCommand(
            m_swerve::getPose, // Functional interface to feed supplier

            // Position controllers
            new PIDController(AutoConstants.kPXController, 0, 0),
            new PIDController(AutoConstants.kPYController, 0, 0),

    // Reset odometry to the starting pose of the trajectory.

Above is part of my autonomous code , but when l simulate the whole code , it just quit . The error is below:

My whole code is here:
2021Swerve.zip (22.7 MB)

Can anybody help me with it?

This was fixed in [wpimath] Fix IOException path in WPIMath JNI by lhvy · Pull Request #3485 · wpilibsuite/allwpilib · GitHub. Unfortunately, we haven’t made a new release since v2021.3.1 containing the fix. I’m not sure there’s a workaround either since the bug is in native code. Maybe downgrade?

Where should l change , it seems that l have already use the java.io.IOException.

It’s not a bug in your code. It’s a bug in WPILib that’s unavoidable for what you’re trying to do (calling TrajectoryUtil.fromPathweaverJson()).

1 Like

So , is there any method to use Pathweaver’s path in an autonomous period?

No, it’s completely broken until we do a release or you downgrade.

So, now , we can only use Translation2d to make some points and use this to complete the auto line?

1 Like

Yeah, making the trajectory in code instead is an option.

Will downgrade solve this bug? Why?

Is there any other solution? l think this is too difficult and complicated for a good auto code

Yes. The bug was introduced in [wpimath] Use JNI for trajectory serialization by prateekma · Pull Request #3257 · wpilibsuite/allwpilib · GitHub, which was merged after v2021.2.2. Downgrading to v2021.2.2 will fix the crash. It’ll just take longer to load the JSONs.

If l downgrade , will the extension be cleared?

What extension?

vscode’s extension

Or can l install an older WPILIB’s extension from vscode?

The old installer will provide a VS Code installation with the old extension installed already. Another option is manually editing the version string in build.gradle since that’s pretty much all you have to do to downgrade the robot project itself.

Will the latter option has a bad effect?

You won’t have local copies of the maven dependencies, so the first time you build your code after changing the version, it’ll take a while downloading all of them from maven.

l just need to download the 2021.2.2 version and install it(let it cover the 2021.3.1 automatically)?

Yes, then change the version in your robot project. I guess you’ll have to download a bunch of stuff either way, so you might as well just make the one-line change in build.gradle and not bother with the installer.