Pathweaver Setup

I have looked through the docs and have still not figured out how to use the trajectory created by pathweaver in a Ramsete command.

I have set up a basic program that is essentually the WPIlib Ramsete example. The trajectory that is in the examples with the manually entered points works correctly, but when I try to set up the pathweaver trajectory I have errors before compiling.

I believe this is set up the same as the example on the following link.

What am I missing. The link to my entire code is below.

You can leave the testTrajectory variable uninitialized or set to null.

Knowing what compilation errors you are getting would make it easier to help you.

If I leave it uninitialized I get the following error:

> Executing task: gradlew build   -Dorg.gradle.java.home="C:\Users\Public\wpilib\2020\jdk" <

Task :compileJava
C:\Users\Robertson\Documents\FRC 2020\Steamworks-Ramsete\src\main\java\frc\robot\RobotContainer.java:140: error: variable testTrajectory might not have been initialized
testTrajectory,
^
1 error

Task :compileJava FAILED
Compilation Error!
GradleRIO detected this build failed due to a Compile Error (compileJava).
Check that all your files are saved, then scroll up in this log for more information.

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ā€˜:compileJavaā€™.

Compilation failed; see the compiler error output for details.

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

  • Get more help at https://help.gradle.org

BUILD FAILED in 3s
1 actionable task: 1 executed
The terminal process terminated with exit code: 1

Terminal will be reused by tasks, press any key to close it.

If I try to initialize it I get the following error.

Task :compileJava FAILED
C:\Users\Robertson\Documents\FRC 2020\Steamworks-Ramsete\src\main\java\frc\robot\RobotContainer.java:131: error: constructor Trajectory in class Trajectory cannot be applied
to given types;
Trajectory testTrajectory = new Trajectory();
^
required: List
found: no arguments
reason: actual and formal argument lists differ in length
1 error
Compilation Error!
GradleRIO detected this build failed due to a Compile Error (compileJava).
Check that all your files are saved, then scroll up in this log for more information.

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ā€˜:compileJavaā€™.

Compilation failed; see the compiler error output for details.

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

  • Get more help at https://help.gradle.org

BUILD FAILED in 2s
1 actionable task: 1 executed
The terminal process terminated with exit code: 1

Terminal will be reused by tasks, press any key to close it.

As Starlight220 mentioned, you are not initializing your testTrajectory in all code paths. If the exception is generated on line 133 then you will never get to line 134 where you assign a value.

Changing line 131 to say:

Trajectory testTrajectory = null;

ā€¦will make your code compile and run. It doesnā€™t necessarily prevent it from throwing an exception if your path doesnā€™t load from the JSON.

The other error you were getting is because you canā€™t construct a place-holder trajectory object without passing any parameters to the constructor.

Isnā€™t it better to just do testTrajectory = new Trajectory(); in the catch? If you set it as null and arenā€™t checking for null wonā€™t it error?

2 Likes

You are correct. Initializing the variable to null makes the compiler happy, but doesnā€™t prevent the code from throwing exceptions if the JSON doesnā€™t load and a valid Trajectory isnā€™t constructed.

Still, saying ā€˜new Trajectory()ā€™ without parameters will not work, as evidenced by the second compiler error.

If this were my code, I would probably initialize the trajectory object with a valid default path, perhaps one that simply moves the robot forward a short distance. It wouldnā€™t crash, but it still wonā€™t do what you want it to unless the JSON path can load.

I believe it will work fine inside the catch. See our code. Here is the API for an empty trajectory.

1 Like

Interesting. When I try that in chadr03ā€™s code, I get the same error about not being able to call the constructor without arguments.

  String trajectoryJSON = "paths/TestPath.wpilib.json";
  Trajectory testTrajectory;
  try {
    Path trajectoryPath = Filesystem.getDeployDirectory().toPath().resolve(trajectoryJSON);
    testTrajectory = TrajectoryUtil.fromPathweaverJson(trajectoryPath);
  } catch (IOException ex) {
    DriverStation.reportError("Unable to open trajectory: " + trajectoryJSON, ex.getStackTrace());
    testTrajectory = new Trajectory();
  }

ā€¦producesā€¦

/PathWeaverTest-master/src/main/java/frc/robot/RobotContainer.java:139: error: constructor Trajectory in class Trajectory cannot be applied to given types;
    testTrajectory = new Trajectory();
                     ^
  required: List<State>
  found: no arguments
  reason: actual and formal argument lists differ in length
1 error
Compilation Error!

I think the empty trajectory was new this year it looks like this is a old project. Update the project to the latest version and it should work.

Edit: Yep " Added zero-arg constructor to the Trajectory class in Java that creates an empty trajectory." from here

2 Likes

I didnā€™t think about that, but I do believe this test robot has not be updated to the 2021 build. I will try to update it and move the code to the 2021 WPILib when I get access again this evening.

2 Likes

So I updated to the 2021 WPI and Rio image.

New github repo:

I do not get the compile errors, but it acts like it cannot find my path.

  • Loop time of 0.02s overrun

  • Warning at edu.wpi.first.wpilibj.IterativeRobotBase.printLoopOverrunMessage(IterativeRobotBase.java:301): Loop time of 0.02s overrun

  • DifferentialDriveā€¦ Output not updated often enough.

  • Error at edu.wpi.first.wpilibj.MotorSafety.check(MotorSafety.java:96): DifferentialDriveā€¦ Output not updated often enough.

  • DifferentialDriveā€¦ Output not updated often enough.

  • Error at edu.wpi.first.wpilibj.MotorSafety.check(MotorSafety.java:96): DifferentialDriveā€¦ Output not updated often enough.

  • DifferentialDriveā€¦ Output not updated often enough.

  • Error at edu.wpi.first.wpilibj.MotorSafety.check(MotorSafety.java:96): DifferentialDriveā€¦ Output not updated often enough.

  • DifferentialDriveā€¦ Output not updated often enough.

  • Error at edu.wpi.first.wpilibj.MotorSafety.check(MotorSafety.java:96): DifferentialDriveā€¦ Output not updated often enough.

  • Unable to open trajectory: Paths/Test.wpilib.json

  • Error at java.base/sun.nio.fs.UnixException.translateToIOException(Unknown Source): Unable to open trajectory: Paths/Test.wpilib.json

  • at java.base/sun.nio.fs.UnixException.translateToIOException(Unknown Source)

  • at java.base/sun.nio.fs.UnixException.rethrowAsIOException(Unknown Source)

  • at java.base/sun.nio.fs.UnixException.rethrowAsIOException(Unknown Source)

  • at java.base/sun.nio.fs.UnixFileSystemProvider.newByteChannel(Unknown Source)

  • at java.base/java.nio.file.Files.newByteChannel(Unknown Source)

  • at java.base/java.nio.file.Files.newByteChannel(Unknown Source)

  • at java.base/java.nio.file.spi.FileSystemProvider.newInputStream(Unknown Source)

  • at java.base/java.nio.file.Files.newInputStream(Unknown Source)

  • at java.base/java.nio.file.Files.newBufferedReader(Unknown Source)

  • at java.base/java.nio.file.Files.newBufferedReader(Unknown Source)

  • at edu.wpi.first.wpilibj.trajectory.TrajectoryUtil.fromPathweaverJson(TrajectoryUtil.java:34)

  • at frc.robot.RobotContainer.getAutonomousCommand(RobotContainer.java:125)

  • at frc.robot.Robot.autonomousInit(Robot.java:59)

  • at edu.wpi.first.wpilibj.IterativeRobotBase.loopFunc(IterativeRobotBase.java:232)

  • at edu.wpi.first.wpilibj.TimedRobot.startCompetition(TimedRobot.java:117)

  • at edu.wpi.first.wpilibj.RobotBase.runRobot(RobotBase.java:335)

  • at edu.wpi.first.wpilibj.RobotBase.startRobot(RobotBase.java:407)

  • at frc.robot.Main.main(Main.java:23)

  • Unhandled exception: java.lang.IndexOutOfBoundsException: Index 0 out of bounds for length 0

  • Error at java.base/jdk.internal.util.Preconditions.outOfBounds(Unknown Source): Unhandled exception: java.lang.IndexOutOfBoundsException: Index 0 out of bounds for length 0

  • at java.base/jdk.internal.util.Preconditions.outOfBounds(Unknown Source)

  • at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Unknown Source)

  • Robots should not quit, but yours did!

  • at java.base/jdk.internal.util.Preconditions.checkIndex(Unknown Source)

  • at java.base/java.util.Objects.checkIndex(Unknown Source)

  • at java.base/java.util.ArrayList.get(Unknown Source)

  • The startCompetition() method (or methods called by it) should have handled the exception above.

  • at edu.wpi.first.wpilibj.trajectory.Trajectory.sample(Trajectory.java:99)

  • at edu.wpi.first.wpilibj2.command.RamseteCommand.initialize(RamseteCommand.java:137)

  • at edu.wpi.first.wpilibj2.command.SequentialCommandGroup.initialize(SequentialCommandGroup.java:53)

  • at edu.wpi.first.wpilibj2.command.CommandScheduler.initCommand(CommandScheduler.java:140)

  • at edu.wpi.first.wpilibj2.command.CommandScheduler.schedule(CommandScheduler.java:199)

  • at edu.wpi.first.wpilibj2.command.CommandScheduler.schedule(CommandScheduler.java:214)

  • at edu.wpi.first.wpilibj2.command.Command.schedule(Command.java:242)

  • at edu.wpi.first.wpilibj2.command.Command.schedule(Command.java:247)

  • at frc.robot.Robot.autonomousInit(Robot.java:70)

  • at edu.wpi.first.wpilibj.IterativeRobotBase.loopFunc(IterativeRobotBase.java:232)

  • at edu.wpi.first.wpilibj.TimedRobot.startCompetition(TimedRobot.java:117)

  • at edu.wpi.first.wpilibj.RobotBase.runRobot(RobotBase.java:335)

  • at edu.wpi.first.wpilibj.RobotBase.startRobot(RobotBase.java:407)

  • at frc.robot.Main.main(Main.java:23)

  • Warning at edu.wpi.first.wpilibj.RobotBase.runRobot(RobotBase.java:350): Robots should not quit, but yours did!

  • Error at edu.wpi.first.wpilibj.RobotBase.runRobot(RobotBase.java:352): The startCompetition() method (or methods called by it) should have handled the exception above.

  • ********** Robot program starting **********

Do you have a src/main/deploy/Paths/Test.wpilib.json file on your local machine? Because thereā€™s not one on GitHub. This is the file location that will be copied to the robot.

No it appears it is in the Project Folder/PathWeaver/output

I will have to try to get it in the right location tomorrow. Thanks for the guidance.

Moving the path directory seemed to fix my problems. Iā€™m not where I can see if the path went where I hoped, but I can put it up on block and the wheels spin and the robot code does not crash anymore. So I will call that a win. Thanks