4.10. Custom exporters¶
In the software is it possible to also create your own exporters. You can find that in the menu “Show” and press “Export …”.
In the Export dialog that appears you can change the type to “Script Exporter”.
Note: if you cannot find the item your license probably doesn’t support this feature. Please contact us to adjust your license.
After selecting the output location you can press “Export” and you will be presented with a dialog asking for the script location. We currently only support “JS” files. The details are explained bellow.
4.10.1. Creating a script¶
A minimal script will look like:
1 function executeStep(timestep, droneId, posX, posY, posZ, colorR, colorG, colorB) {
2 print(timestep+', '+droneId+', '+posX+', '+posY+', '+posZ+', '+colorR+', '+colorG+', '+colorB);
3 }
The executeStep function is the only required function that is needed in the script. The function is called for every drone in the show every 250ms (4fps) with it’s position and color.
timestep: the time since the start in ms (integer)
drone_id: the unique number of the drone (integer)
position: the position is given from the middle of the show (in meters).
posX: the left-right position of the drone (double)
posY: the depth, front-back, of the drone. Lower numbers are more to the front (double)
posZ: the height of the drone, inclusive the “above ground”. Zero is ground. (double)
color:
colorR: value between 0-1 indicating the red component (double)
colorG: value between 0-1 indicating the green component (double)
colorB: value between 0-1 indicating the blue component (double)
The print function can be used to print data to the output file. This is de default way to export your data.
4.10.2. Configure the script¶
By providing a configure function you can adjust how the exporter works.
1 function configure() {
2 return {frameRate:10};
3 }
the function should return an object with the wanted configuration.
Frame rate
By default the frame rate is 4 fps. By providing “frameRate” in the configure function you can adjust this. If a frame rate is not supported it is rounded towards the closest supported frame rate. A warning will get shown if that happens.
Supported frame rates are: 1, 2, 4, 5, 8, 10, 20, 25, 31.25, 40, 50, 62.5 and 100
4.10.3. Extra functionality¶
init
The init function will be called after the configure function, but before any “executeStep” calls. This is a good position to initialize variables.
finish
This function is called at the end of the execution. Here you can properly end the execution. Or do some post-processing on the data.
This function is a global function that can be used to print data to the selected output file.
4.10.4. Example scripts¶
CSV
The following script will output the show content as a “Comma Seperated Value” file. A new line will get outputed for every drone every 250ms containing the location and color of the drone at that moment.
1 function init() {
2 print('Time, Drone id, Position X, Position Y, Position Z, Color red, Color green, Color blue');
3 }
4 function executeStep(timestep, drone_id, posX, posY, posZ, colorR, colorG, colorB) {
5 print(timestep+', '+drone_id+', '+posX+', '+posY+', '+posZ+', '+colorR+', '+colorG+', '+colorB);
6 }
JSON
This script create json output containing a dictionary for every drone containing a list with positions and colors.
1 var data = {};
2 function executeStep(timestep, drone_id, posX, posY, posZ, colorR, colorG, colorB) {
3 if (!data[drone_id])
4 data[drone_id]=[];
5
6 data[drone_id][data[drone_id].length] = {
7 pos: [posX, posY, posZ],
8 color: [colorR, colorG, colorB]
9 };
10 }
11 function finish() {
12 print(JSON.stringify(data));
13 }