jsimpso81 / WPIlibMathLabVIEW

WPILib LabVIEW Math Library
Other
16 stars 3 forks source link

[enhancement] way to turn csv file to path? #123

Closed Not-AriStienfeld closed 1 year ago

Not-AriStienfeld commented 1 year ago

as far as I'm concerned, there isn't a block that turns csv files into path clusters. I feel like that would be pretty useful for coding pathfollowing code.

Not-AriStienfeld commented 1 year ago

by path clusters I'm referring to what the yellow folder under "3rd party" uses

jsimpso81 commented 1 year ago

Thank you for your interest in the library.

There is a VI in this library that will read CSV or JSON files that are stored on the robot and create Trajectory data structure. This allows Trajectories (Paths) that are created by PathWeaver or the LabVIEW trajectory creation utility to be copied to a robot, read by the robot (probably in the BEGIN.VI) the executed. There is a sample robot that does this --- Sample 2 -- https://github.com/jsimpso81/WPIlibMathLabVIEW_Examples/tree/master/Robot_Sample_2_Diff_File_Traj_ODE

The VIs to read the JSON files are can be found here.
image

image

The JSON read routine isn't as easy to find...

image

image

image

Hope this helps. If I interpretted your question incorrectly, please clarify. If this solves your issue, please indicate that I can close the issue. Thanks.

Not-AriStienfeld commented 1 year ago

Hi, thanks for the quick response. I'm wondering if this works with the holonomic jsons created from the 2023 path planner application (the one on the windows store). I understand the new features won't work, but will the json itself work?

Not-AriStienfeld commented 1 year ago

image and I was mainly asking about how to use this block because I couldn't find a way to get the path as an array of clusters from the csv or json.

I tried doing something like this: image but obviously it is missing a few values and I can't implement the curvature

Not-AriStienfeld commented 1 year ago

image while I'm at it, I also realized that with this odometry, my y is extremely accurate, but the x is all messed up. any time I stop moving in the x direction (the modules reset to their default "0" location) the x displacement goes to 0. I'm not sure why this is.

jsimpso81 commented 1 year ago

A couple of quick comments: 1) The PathFinder routines are for using PathFInder to create trajectories on the robot. They aren't for executing trajectories. PathFinder is old, but still may have value since it has acceleration limiting (jerk -- actual technical term...) that doesnt exist in the native WPILIB (include WPILIB LabVIEW Math) routines.
2) Suggest looking at the sample trajectory following robot examples here. https://github.com/jsimpso81/WPIlibMathLabVIEW_Examples The easiest way to get these is to download a zip file of the complete archive. It can also be cloned. I think the examples may answer a lot of your questions. 3) The WPILIB LabVIEW trajectory cluster can be used with any kind of drive. The only downfall of this cluster data format is that it doesn't separate the direction the robot is traveling from the direction the robot is facing. The trajectory cluster only contains the direction the robot is traveling. This can be executed either by keeping the robot orientation the same or by having the robot follow a different orientation. The samples show either -- although there may still be a bug in the routine that follow the trajectory in reverse (something you may not even care about.) If you have a starting robot orientation and an ending robot orientation then you ramp this over the time period of the trajectory and change the orientation setpoint. 4) Be careful of the units that each VI needs. Internally the VIs use SI units. Your code may be okay, but I couldn't tell with certainty. 5) In your loop you may need to use shift registers for the Odometry data. Maybe the Kinematics data too (I can't remember with certainty about that one.) The Odometry requires its own output data from the previous loop iteration. ( I know, I could have don't this internally, but for now I didn't...) See picture below from sample 8 6) Sample robot 8 is probably the best swerve. (I think if you open "robot main.vi" from the "My computer" target and execute it will run in simulation on your PC.

Sorry I didn't really study your code examples in detail, but hope this helps.

image

Not-AriStienfeld commented 1 year ago

I fed the values back into the loop with a feedback node and it was worse...

Not-AriStienfeld commented 1 year ago

I got it working by negating some values I can't close it from mobile, so you are good to close it