JaciBrunning / Pathfinder

Cross-Platform, Multi-Use Motion Profiling and Trajectory Generation
MIT License
255 stars 78 forks source link

Formula for checked_max_v appears incorrect #43

Open jwhite66 opened 6 years ago

jwhite66 commented 6 years ago

We've been making use of Pathfinder (thanks!), and believe we have found an error in a computation.

The symptoms it causes if that if you ask for a long move with a max velocity of, say, 140, sometimes the resulting trajectory will have a computed max velocity lower than you would expect (e.g. 131).

As an example, these waypoints: Waypoint points[] = {{0,0,0},{160, 0, 0}};

with a maxv of 140, maxa of 600, and maxj of 600 result in a trajectory that has a top velocity of 131.

The code in question is here: https://github.com/JacisNonsense/Pathfinder/blob/master/Pathfinder-Core/src/trajectory.c#L28 That appears to be using this formula: https://physics.stackexchange.com/questions/34077/maximum-velocity-allowed-for-motion-profile-with-constant-jerk

That code also exactly mirrors the original 254 code, so this computation appears to have originated with the poofs.

However, if you solve the quadratic equation and do the math, it appears as though there should be a ' 8' term, not a ' 4' term. And switching in an 8 for the 4 does seem to improve matters; you get a trajectory with the 140, not the 131.

JaciBrunning commented 6 years ago

It would seem you're correct here. I'm currently working on the next rendition of the Pathfinder project that fixes this issue, but it isn't available out to the public yet.

Given that Pathfinder is already out there for this season, I won't bother putting this change in just yet, but it's certainly on my checklist for the next release.

Thanks, ~Jaci

Leo428 commented 6 years ago

Thank you very much for improving this project Jaci! I have been using and loving this library and I am working on using this in the Vex competition this summer. Thank you again for the amazing work you have done.