View Single Post
  #14   Spotlight this post!  
Unread 28-09-2011, 22:36
apalrd's Avatar
apalrd apalrd is offline
More Torque!
AKA: Andrew Palardy (Most people call me Palardy)
VRC #3333
Team Role: College Student
 
Join Date: Mar 2009
Rookie Year: 2009
Location: Auburn Hills, MI
Posts: 1,347
apalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond repute
Re: Parameters file for quick code updates

I:

-Have a single array of clusters which stores all of my data. Since I was not loading the data via script (but setting the constants in the array directly, via the front panel), I had a cluster which contained:
-String name
-Dbl comp
-Dbl practice

When I needed a constant in code, I called the get constant VI which:
-Got the array (it was a global variable)
-Got the robot (it was also a global variable)
-Ran a FOR loop on the array, which:
>-Unbundled the cluster (all of it)
>-Selected which constant it liked (what robot we are on) and output it (it ended up as an array of floats)
>-Compared the name string to the desired variable string
>-Output an array of booleans of the comparisons
-Searched the 1d boolean array for a True
-Case on the result
>Default: Index output float array for desired value, output
>-1 (not found) - Output NaN. This causes all math to fail and is bad, so it tells you VERY quickly that you made a mistake.

In LV, if you pass an array into a FOR loop without an i count, it will run the for loop as a FOREACH loop. When you pass a variable out of a for loop, it defaults to create an array of the values at each iteration (you can disable this by rt-clicking on the output and selecting "Disable Indexing" - this also works for inputs)

I only used this system for elevator calibration excluding elevator/wrist setpoints (those were stored in a separate array and indexed by the state), plus a set of modifiers which were indexed by modifier (both state and modifier were enumerated). So, things like analog limits (and their "sane number" counterparts), gains, anti-death boundaries, and such were stored in this (about 20 variables in all).

This seemed to me as the most sane way to handle large amounts of data in LV.

Edit: Added example. If you were to import the data from a file of some sort, I would just populate the array. If you spell something wrong in the file, then the code that requests the variable will get NaN.

Edit 2: Added another example which loads the data from your CSV into the array. I copypasta'd the CSV loading code from your gloal_read.vi
Attached Files
File Type: vi StorageExample.vi (7.0 KB, 8 views)
File Type: vi StorageExample_ReadFile.vi (10.8 KB, 7 views)
__________________
Kettering University - Computer Engineering
Kettering Motorsports
Williams International - Commercial Engines - Controls and Accessories
FRC 33 - The Killer Bees - 2009-2012 Student, 2013-2014 Advisor
VEX IQ 3333 - The Bumble Bees - 2014+ Mentor

"Sometimes, the elegant implementation is a function. Not a method. Not a class. Not a framework. Just a function." ~ John Carmack

Last edited by apalrd : 28-09-2011 at 22:52. Reason: Added example (again)
Reply With Quote