The compiler is called 'rl' it takes a number of flags:
rl [-m] [-s n] [-S n] [-l[cdwirt] n] file.r -m produnce a link map -S n the number of bytes to reserve for stack space (default 512) -s n load options (not supported on all flight computer) this tags the output .x file with a command for the loader 0 do nothing 1 load an run 2 load and save to eeprom -l[cdwirt] n set launch detection optionsBy convention input files always end in '.r' the compiler will generate an output file with the '.r' replaced with a '.x' - this is an executable file - by the simulator and maybe your flight computer - or maybe your flight computer will require further processing before it can be run (check out the release notes for your flight computer).
The compiler only ever reads a single source file - there is NO linker - everything in the program has to be in the one file. There is also no preprocessor - if you want one grab a copy of the GNU one (cccp) it's free and will do the job well.
'-lr 0' sais that launch detection is done when the value on the specified sensor channel is '-ld N' less than the quiesent value discovered when the system was turned on. (This is intended for pressure sensor - when the pressure goes down by N it detects the launch).
'-lr 1' sais that launch detection occurs when the value on the specified sensor channel is '-ld N' less or greater than the quiesent value discovered when the system was turned on for more than '-lw N' milliseconds. (This is intended for detection using an accelerometer - you should try out some values on the ground first - pick up the rocket and shake it about to make sure your numbers are OK - don't set the -lw number too short if you have a really short burn motor.
'-li N' sais how long to wait at the beginning of the program (in milliseconds) before arming the launch detector - this gives you some time for everything to get nice and stable on the pad before it gets armed.
'-lt N' in milliseconds gives the poll rate at which the launch checking code will check the sensors (do this too fast and your own code will get slowed down) the launch detection code is integerated with the logging code - if the log is turned on this parameter is ignored and the launch detection is done at the rate specified by log_ctl(6, *).
'-lc N' gives the channel number (see get() for what these correspond to) that is sampled by the launch detection code.
rsim [-d] [-D] [-s file] file.x -d -D debugging flags - cause the simulator to output an instruction (byte_code) trace -s file reads a stimulus file to provide sensor data on the flyThe '-s file' flag allows you to create a simulation stimulus file, it contains records that look like:
timescale 10 0: channel 0 = 6 channel 1 = 5000 1000: channel 0 = 60 channel 1 -> 10000 +2000: channel 0 = 90 channel 1 -> 40000The first timescale directive controlls how slowly time occurs in the simulation (don't set this too large - it's a balance between the simulation running quickly and you missing time).
The rest of the lines describe the progression of the sensors over time - the number to the left of the colon is an absolute time or a time relative to the previous line's time (indicated by a '+'). The first time must be 0 and the following times must always increase. The 'channel N = val' commands set the value for a channel at a particular time (or rather at the first time past the specified time that the flight computer samples the data. The 'channel N -> val' means that the value will vary from the value the channel had on the previous line will change linearly to the new value specified between the 2 times.
So in the previous example:
channel 0 will start at 6, and the at 1sec it will suddenly jump to 60, at 3 secs it will then jump to 90 channel 1 will start at 5000 and gradually change so that at 1sec it has the value 10000, it will then gradually change back down to 4000 at 3 secs
state start: pstr("hello world\n");Now enter:
rl a.rThis should have created a.x. Now simulate it:
rsim a.x
state start: log_ctl(6, 100); // log ever 100 milliseconds (10 times a sec) log_ctl(7, 0); // log channel 0 log_ctl(7, 1); // log channel 1 log_ctl(0, 1); // turn on the logger on launch: log_ctl(1, 2000);next xx; state xx: on timeout 3000: log_ctl(5,0);halt;And compile it with 'rl -lc 0 -lw 200 -lt 200 -lr 1 b.r' setting the launch detect up for a accelerometer style detection, now make the stimulus file e.stim:
0 : channel 0 = 15000 3000 : channel 0 = 15000 3200 : channel 0 -> 18000 5200 : channel 0 = 18000 5400 : channel 0 -> 15000Now run 'rsim -s stim b.x'. You should get the log printed out, as shown below - the first number is the time in milliseconds, the second the number of numbers (plus 3), the third is the log entry type (in this case '1' means 'sensor data') and finally the last 2 numbers are the sensor channel 0 and 1 data.
Notice how the channel 0 data starts at 15000, and at 3 secs suddenly ramps to 18000, then at 5.2 seconds ramps back down to 15000 (a roughly 2 sec boost) approx 3 seconds past the launch detect the program stopped and printed out the log.
BTW: the really usefull thing to do here is to fly rockets, collect the sensor logs, mutate them back into stimulus files and play them back to your flight software on the ground so you can test it.
78 2 1 15000 0 187 2 1 15000 0 296 2 1 15000 0 405 2 1 15000 0 514 2 1 15000 0 623 2 1 15000 0 732 2 1 15000 0 841 2 1 15000 0 950 2 1 15000 0 1059 2 1 15000 0 1168 2 1 15000 0 1283 2 1 15000 0 1399 2 1 15000 0 1514 2 1 15000 0 1630 2 1 15000 0 1745 2 1 15000 0 1861 2 1 15000 0 1976 2 1 15000 0 2092 2 1 15000 0 2207 2 1 15000 0 2323 2 1 15000 0 2438 2 1 15000 0 2554 2 1 15000 0 2669 2 1 15000 0 2785 2 1 15000 0 2900 2 1 15000 0 3016 2 1 15300 0 3130 2 1 17010 0 3260 2 1 18000 0 3364 2 1 18000 0 3467 2 1 18000 0 3571 2 1 18000 0 3674 2 1 18000 0 3778 2 1 18000 0 3881 2 1 18000 0 3985 2 1 18000 0 4088 2 1 18000 0 4192 2 1 18000 0 4295 2 1 18000 0 4399 2 1 18000 0 4502 2 1 18000 0 4606 2 1 18000 0 4709 2 1 18000 0 4813 2 1 18000 0 4916 2 1 18000 0 5020 2 1 18000 0 5123 2 1 18000 0 5227 2 1 17535 0 5330 2 1 15990 0 5434 2 1 15000 0 5537 2 1 15000 0 5641 2 1 15000 0 5744 2 1 15000 0 5848 2 1 15000 0 5951 2 1 15000 0 6055 2 1 15000 0 6158 2 1 15000 0