Quote:
Originally Posted by tr6scott
So can you send me a link or info on beescript, or how you do state machine stuff, and avoid the LV download.
|
1. You guys are awesome too.
2. Beescript. I wrote it myself (and named it after Bees, of course). Basically, I read a text file on the cRio (which I upload via FTP), and separate it into an array of lines, and then do this:
If the line starts with a #, skip it (it's a comment)
If the line has <3 characters, skip it (it's probably a space or blank).
Else, tokenize by spaces into an array of words, lookup the first word in an array to find the index, then look through another array of commands to find the command ref. Call it by ref, with the rest of the array as the argument (you have to use strict-type VI refs to do this).
Each command has the argument array input, and then looks through the arguments to find the ones it wants(usually by assuming the first argument is X, the second is Y, etc.), and uses those to run what it runs. Upon entering auto, it populates the array, with each command having the command name and the ref in an array (look at the WPI refnum registries for an example of how to do this).
3. State-machines. I have an array of cal points, each of which has an elevator height and arm position. I also have an enumerated type which defines the state. I double-buffer the state to handle going over backwards and forwards, since those use collision avoidance. I take the resulting state and lookup the position in the array (since enumerated variables can be used as unsigned int's) and also have a few special states which I further process (especially the score positions, which have score sequencing). I have a single get-set VI which handles state storage, double-buffering, and initialization. If it is disabled, it will uninitialized, and a command must be sent to re-initialize. The motors will be set to 0 if it is not initialized, this is a safety feature.
Simple: I use an enum and an array of positions, then lookup the position in the array. I also have a large case structure for special cases.
3a. I also have a few VI's that run after the state-machine, one which actually does P control to determine motors speeds, another which prevents the window motors from stalling (we have a few states which hit mechanical limits, so we drive the setpoint past the mechanical stop then kill it after it stalls to prevent PTC-tripping), and a third handles manual override.
3b. Since we have two robots (competition and practice), I translate all of the sensor inputs into inches and degrees, so I can use a single set of calibration data on both robots.