I need help finding my path through pathfinder

So this year, our team has chosen to use Pathfinder to do our auto motion profiling. I get everything until generating the trajectory. But i am not sure how to get the robot to follow the path. Any help is always appreciate.

1 Like

I also have this question…

I think you can use it like this

for (int i = 0; i < trajectory.length(); i++) {
Trajectory.Segment seg = trajectory.get(i);
setMotorVel(seg.velocity);
}

Seg has these parameters-seg.dt, seg.x, seg.y, seg.position, seg.velocity,
seg.acceleration, seg.jerk, seg.heading

You can use PathWeaver to generate the trajectory. https://wpilib.screenstepslive.com/s/currentCS/m/84338/c/276447

1 Like

What if I am creating a spline where my heading is constantly changing?

What kind of drive system are you using? You will need to setup a PID for turning your robot that gets feedback from a IMU. Once this is done you just give the PIDController the angle set point right after the
setMotorDrive(seg.Velocity);
PIDController.setAngle(seg.heading);

We are using a cheesy drive. So how will that set the robot to drive for a certain distance in a certain heading when given the trajectory. Is it just
for (int i = 0; i < trajectory.length(); i++) {
Trajectory.Segment seg = trajectory.get(i);
setMotorVel(seg.velocity);
PIDController.setAngle(seg.heading);
}
I am honestly blank.

See the PathFinder wiki for some getting started instructions: https://github.com/jacisnonsense/pathfinder/wiki

Is the code i showed in my previous text correct?

This code. So I use path weaver to generate a trajectory and save it into a file. Then access the file. Use the above code to control the robot’s heading and direction. Is this right?

No, unless what you’re giving is psuedocode. You need to run it with a time step; your code will try to set everything instantly.

How do I do that?

Each iteration of the loop needs to be in a separate iteration of the main robot loop (assuming you are using TimedRobot, each iteration of teleopPeriodic for example).

So can I create a command, then update method with the above code with a counter but without a for loop. That way everything is constantly updated, once every 20ms. Right?

Correct. You may want to start with something easier than a PID on the gyro. Try using the EncoderFollower first as the wiki suggests. That may work for your purposes. Then work up to the complexity of using a PID.

1 Like

If you want to play around with pathfinder without a real robot, a fully functional working pathfinder demo is available in the RobotPy examples repo. The code is mostly the same as you’d find in Java/C++.

1 Like

hi I am Alice from team 6191. I would like to ask if you know how to tune the pid of encoderFollower?