Motion Profile Generator + Jaci's Pathfinding

Hey! So I have been working with vannaka’s motion profile generator as well as Jaci’s Pathfinder to make a test auton program. I don’t know too much about either but they are documented well and so I’ve managed to put something together. I haven’t yet found the time to calculate the maximum velocity, acceleration, or jerk, but besides that everything should be correct. I wanted to post the code (because we’re in a state where I probably won’t be able to test much before the off-season comp) and see if anyone can spot any major problems with how I’ve done it…I already don’t think the velocity should look like the image here. If you could quickly look through the Robot.java I would appreciate it! Thanks in advance!

EDIT: I realized that the change in velocities is when the robot is technically supposed to be going backward…is that possible with the Pathfinder or would that require turning around/inverting the driving system?

Hi, so there are a few comments that I want to make. Firstly, I see that you put your following code in autonomous periodic. The problem with that is looking through your csv file I see that the dt is 0.05. This means that each of the points is 0.05 seconds apart, so every 0.05 seconds you want to switch to the next point in your path. Every time you call the calculate function Pathfinder goes to the next point, and since your calling calculate in autonomous periodic the timing may not line up. I’m not too sure about the rate at which auto periodic runs, but I do know that execute runs at a rate of ~0.02 seconds, so it might be like that. Anyway, you should use a notifier which is like an execute that can run at a specified rate, to make sure it doesn’t cause problems. Notifier documentation:
http://first.wpi.edu/FRC/roborio/release/docs/java/
This next issue is just me assuming, so correct me if I’m wrong. I see that your velocity gain is set to 1/ max velocity, but the max velocity value that you gave it is the max velocity of the trajectory. It should actually be the max velocity that your robot is possible of achieving. This makes sense because if you think about it the target velocity will be multiplied by 1 / max velocity giving you target velocity / max velocity of the robot. This is sort of like a proportion telling you how much power you need to put to get that velocity. While the max velocity of the trajectory is the highest velocity the robot will ever be going. Now I don’t know if your max velocity is actually 5.7 ft/sec, but that does seem kind of low to me, but please do correct me if I’m wrong. This paper goes more into depth:
https://www.chiefdelphi.com/media/papers/3402

I didn’t even think about the timing of the points…I will definitely look into using a notifier. As for the max velocity, a friend and I sat down and did some testing last night to see the max velocity we could hit with the robot, so now I believe it is set to about 9.3 ft/s. I also regenerated the CSV with that as well as our theoretical max acceleration (our data was a bit shaky so we may have to do some more testing) and max jerk. Thank you for the suggestions I really appreciate it, especially thanks for letting me know about the notifier.

EDIT: I’ve just implemented the notifier (I think) so it will work. I’m hoping to test tonight, but I’ve updated the links above so all values, etc should be mostly correct.

I would not recommend using the max velocity or the max acceleration of the robot as constraints for the trajectory. In the version of Pathfinder that you are using, these constraints are enforced only for the center trajectory. When you split this up into trajectories for the left and right sides of the drivetrain, the velocity and acceleration commands for a set of wheels will be higher than the max specified constraints around curves in the trajectory.

In fact, you can see this in the CSV files that you have in your repository. (The velocity column has values over 10 f/s even though you stated that the max velocity that your robot was capable of was only about 9.3 f/s).

Okay gotcha…So I tested the code and it completely failed. I call the readFromCSV method in the robotInit when I’m creating the trajectories, but it pops up with this:

# A fatal error has been detected by the Java Runtime Environment:
#
# SIGSEGV (0xb) at pc=0xb6dddaf4, pid=3588, tid=0xb52f4470
#
# JRE version: OpenJDK Runtime Environment (8.0_131-b57) (build 1.8.0_131-b57)
# Java VM: OpenJDK Client VM (25.131-b57 mixed mode, Evaluation linux-aarch32 )
# Problematic frame:
# C [libc.so.6+0x5aaf4] fgets+0x24
#
# Core dump written. Default location: //core or core.3588 (max size 2048 kB). To ensure a full core dump, try "ulimit -c unlimited" before starting Java again
#
# An error report file with more information is saved as:
# /tmp/hs_err_pid3588.log
#
# If you would like to submit a bug report, please visit:
# http://www.azulsystems.com/support/
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.

(you can see the code I have at the repository above). I don’t have another chance to test until next Wednesday so any quick help would be much appreciated. I’ve narrowed it down to the specific line of code where I create the trajectories from the csv files.

Add this to your gradle.build under deploy -> artifacts

       fileCollectionArtifact('motionProfiles') {
            targets << 'roborio'
            files = fileTree(dir: '/resources/paths')//, include: "**/*.csv"? //pc directory
            directory = "/home/lvuser/paths" //roborio directory
        }

The filetree should be where the csv files are on the pc within the project folder. The roborio directory is where you are pulling the csv file.

For instance, I am pulling the files using this command, where path is the name of the path.

rightTrajectory = Pathfinder.readFromCSV(new File("/home/lvuser/paths/" + path + "_right_Jaci.csv"));
leftTrajectory = Pathfinder.readFromCSV(new File("/home/lvuser/paths/" + path + "_left_Jaci.csv"));

That makes so much sense, but I never would have gotten there myself. I’m sort of new to the whole gradle thing but I sort of understand dependencies. I guess I still have a ton more to learn about it! I might sneak into the workspace and try to test this later today, I’m really excited to get this working. Thank you to all who replied, I’ll update this thread with any more questions.