Help with PathWeaver Implementation

Hi,
Currently our team is trying to get Pathweaver to work, and we have implemented RobotContainer code basically identical to that in the RamseteCommand github but with the trajectory made in Pathweaver instead of a manual trajectory. The relevant code is below. However, when we run Autonomous in the driver station the robot does not move, and we are not sure what the problem here is.

public RamseteCommand getAutonomousCommand() {

    

    DriverStation.reportError("stuf happens", true);

    String trajectoryJSON = "Users\\ttaw2\\OneDrive\\Desktop\\FRC\\Software\\FRC test\\FRC 2020\\FRC 2020 code\\vendordeps\\Pathweaver\\Paths\\Start-Trench.wpilib.json";

    try {

      Path trajectoryPath = Filesystem.getDeployDirectory().toPath().resolve(trajectoryJSON);

      trajectory = TrajectoryUtil.fromPathweaverJson(trajectoryPath);

    } catch (IOException ex) {

      DriverStation.reportError("Unable to open trajectory: " + trajectoryJSON, ex.getStackTrace());

    }

    RamseteCommand ramseteCommand = new RamseteCommand(

      trajectory,

      m_robotDrive::getPose,

      new RamseteController(AutoConstants.kRamseteB, AutoConstants.kRamseteZeta),

      new SimpleMotorFeedforward(DriveConstants.ksVolts,

                                 DriveConstants.kvVoltSecondsPerMeter,

                                 DriveConstants.kaVoltSecondsSquaredPerMeter),

      DriveConstants.kDriveKinematics,

      m_robotDrive::getWheelSpeeds,

      new PIDController(DriveConstants.kPDriveVel, 0, 0),

      new PIDController(DriveConstants.kPDriveVel, 0, 0),

      // RamseteCommand passes volts to the callback

      m_robotDrive::tankDriveVolts,

      m_robotDrive

  );

  return ramseteCommand;

    }

}

Could you post your Robot.java? I assume that is where you schedule the command, if not then could you post your code for where you schedule the command to be run? It’s hard to see what the problem is from only the getAutonomousCommand() method

I agree with Jack, seeing more (like where the command is grabbed and scheduled) would help. However one thing that pops out to me on first glance is the trajectoryJSON string being a file path to the JSON on the DS/developer laptop, when it should be the file path to the JSON on the RoboRIO, as the code is executing on the RoboRIO, not on the laptop. There should be a deploy/ folder under src/ (with perhaps an example.txt already in there). This is where any “extra” files should go that your robot code uses (like Start-Trench.wpilib.json for example). Info on retrieving trajectory JSON files from Pathweaver from the deploy folder can be found here, among a lot of other helpful stuffs

Actually, I just noticed an output folder in deploy, so would I just set the paths to be /home/lvuser/deploy/output/Start-Trench.wplilib.json? Is there anything in the path that needs to be changed?
All of the Autonomous stuff is here

public  void autonomousInit() {

    m_autoSelected = m_chooser.getSelected();

    m_autoSelected = SmartDashboard.getString("Auto Selector", kDefaultAuto);

    System.out.println("Auto selected: " + m_autoSelected);

  }

  /**

   * This function is called periodically during autonomous.

   */

  @Override

  public void autonomousPeriodic() {

    rc.getAutonomousCommand();


  }

Calling rc.getAutonomousCommand() only creates the command, it does not run it. To run your command you have to schedule it like this:

public void autonomousInit() {
    ...
    rc.getAutonomousCommand().schedule();
}

This tells command scheduler to run the auto command. You don’t need anything in autonomousPeriodic.

When trying to run autonomous, it gives me this message also, probably related to problems

Unhandled exception: java.lang.NullPointerException: Parameter trajectory in method RamseteCommand was null when it should not have been! Check the stacktrace to find the responsible line of code - usually, it is the first line of user-written code indicated in the stacktrace. Make sure all objects passed to the method in question were properly initialized - note that this may not be obvious if it is being called under dynamically-changing conditions! Please do not seek additional technical assistance without doing this first!

In your catch (IOException ex) block, you didn’t set the trajectory to anything, which results in it being null when there is an error with loading it from disk.

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