How to use exported PathWeaver JSON?

I keep getting an IOException, no idea whats going on and there’s no documentation on FRC Docs. Thanks.

Also something that might help me is what to put in the deploy file, i just have the actual json and no other folders: deploy>paths>json

Can you post the relevant code where you’re accessing the json file? An IOException in this case most likely indicates that there is a problem reading the file data. You’re json can simply be placed in your src/main/deploy folder, no additional folders needed.

I tried that and it didn’t work. It’s the same as the code on the docs but YourPath is now the name of the json, or SimpleAuto

The frc-docs code assumes the json file is in the deploy directory. If your json file is in the deploy/paths directory, then you need to make sure you modify the example accordingly.

Post your code for better assistance.

Is the IOException when you’re creating a trajectory?

Trajectory trajectory = TrajectoryUtil.fromPathweaverJson(Paths.get("/home/lvuser/deploy/YourPath.wpilib.json"));

You will need a try…catch wrapped around this due to the disk read.

yes we threw it to the get instance in auto init. we caught it with the message there was an error. how would we catch and print the actual error?

I did

catch(IoException e){
System.out.println(“error occurred while reading from file: “ + e.getStackTrace());
}

Hello. PathWeaver maintainer here. Can I have a photo of your deploy folder and the code you are using? You may have a minor spelling error somewhere, which is usually the source of all this confusion.

I will but for rn it says “deploy” then in there I have the generated json named “SimplePath”. i copy and pasted that name in the where it says " YourPath" and got the error

Also keep in mind that I can’t build either and I haven’t deployed to the Rio. I don’t know if that matters.

1 Like

You can’t build or deploy? When/where are you getting the IOException? We’re trying to help but need a more complete description of the issue you’re seeing. Walk us through the steps and show us the exact output you’re getting (e.g. screenshots).

I think I found it. The file is a .path… checking back I put the json in and I still get the problem

Ok. The issue is that line of code can throw IOException and you need to write code to catch it and do something about it. The docs currently don’t show this, but should soon (here’s the PR).

So can we not use PathWeaver? Where would I write the try-catch, also.

You just need to write the line like this:

try {
    Trajectory trajectory = TrajectoryUtil.fromPathweaverJson(pathToFile);
} catch (IOException e) {
    // Add code to do something when the robot fails to get the path
}

If you highlight the line with the error and press the lightbulb icon on the left, it should give you the option to surround the line with a try/catch, which will insert the try/catch for you.

So even though its says the error is that it cant read the file I still need to catch the error? This doesn’t make sense to me so sorry for asking so many questions.

So normally when code encounters an error, it will crash out. Using a try/catch is a way for programmers to say “Hey I know this can cause issues, but here is what I want you to do if you encounter an error” without having the code crash. Use it sparingly though, because if you surround entire blocks of code with try/catches, it can make it extremely hard to find an error in your code when debugging.