Integrating PathWeaver with WPILib's Ramsete Command and Trajectory Following

Hello!
I was looking for some answers on PathWeaver and it’s integration in WPILib.

I have read the PathWeaver documentaion here: https://docs.wpilib.org/en/latest/docs/software/wpilib-tools/pathweaver/index.html

And the Trajectory Tutorial here: https://docs.wpilib.org/en/latest/docs/software/examples-tutorials/trajectory-tutorial/index.html

But it seems no one mentions how can I use the trajectories I created in PathWeaver in the WPILib Ramsete Command and Tajectory Following framework.
The problem for me is the use of Rotation2d objects in WPILib (I just don’t know how to find the x, y and angle values of the path I wish to create, looking on answers on that, too!). I was thinking to simply insert the x, y and tangent x, tangent y values of the PathWeaver trajectories, but the angle is made of two values, which I really don’t know how to integrate into the Rotation2d objects.

If anyone knows how to use those two and explain to me, as it seems i’m not so proficient in this topic, please write me.
Thanks!

I’m not sure if that was your question, but this article from the docs shoes how to extract a Trajectory from a PathWeaver JSON file.

Yes, that was it, thank you :slight_smile:

1 Like

You want to move the .wpilib.json into SRX/main/deploy, not the .path file. And note the docs for that article just got updated (by me). It’s fromPathweaverJson not fromPathweaverJSON.

We just tried the same thing for our code, and it doesn’t seem to work.
With this screenshot, can you help us with what mistake we made?


(We put this under the getAutonomousCommand() in the RobotContainer)

Your trajectory variable is declared inside of the try catch statement, meaning it’s scope is contained within the statement. Try declaring the trajectory variable outside of the try catch. Trajectory trajectory;
try {

trajectory = TrajectoryUtil.fromPathWeaverJson…

You need to set trajectory to something in the catch so either way it exists. Honestly though I would just hardcore the trajectories. Pathweaver is a pain to work with imo.

A couple more questions:

  1. How should I set up the trajectory in the catch?
  2. How is doing hardcore trajectories a better option?

Either way, THANK YOU greatly for this help!!!

@maccopacco has a more correct solution for this use case. Just make sure that the variable exists outside the try, and assign it inside of it.

Can we get a link to maccopacco’s solution?

Yep, missed that part. The trajectory needs to be created outside the try catch but initialized in both parts. In the try it is from a file, in the catch you set it to go from it’s current pose to its current pose.

I meant hardcode not hardcore. Basically initialize them all in a class and use as needed.

What do you mean “The trajectory needs to be created outside the try catch”

What maccopacco said.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.