README.md 3.02 KB
Newer Older
1
## Interpreter ##
Samsara Pappu Durvasula's avatar
Samsara Pappu Durvasula committed
2
3
4
5
6
Contains
- Data_processor.cc: Main process for reading from engine output, spawning
76 processes, and transferring data into the main simulator process. 

- simLib.c: The symbolic library containing C bindings for the engine's 
Samsara Pappu Durvasula's avatar
Samsara Pappu Durvasula committed
7
8
9
10
11
python API. 

- api.py: A local version of the python API for use in binding incoming 
python commands to their simLib versions. 

12
13
14
15
16
17
18
19
20
To compile data_processor: g++ data_processor.cc -I/usr/include/python3.6 -lpython3.6m -o data_processor   
To install simLib on your local machine: python3 setup.py install  
To restart interpreter for fractal flyer type the idx of the FF and hit enter while running ./data_processor  
To shutdown entire interpreter type in -1 and hit enter

Data_processor.cc:  
This file contains the main code of the simulator which creates all 76 flyer emulations, runs the interpreters, and runs the server side implementation.  From here the process is able to send signals to shutdown or restart any interpreter and manage the entire simulation.  It creates the server followed by the flyer emulations.  Each emulation creates a FIFO.  All the FIFO are stored at /tmp/fractal_flyers/flyeri where i is the index of the fractal flyer.  If directory /tmp/fractal_flyers does not exist, it is created.  Both of these file structures are destroyed when the process is closed or crashes.  After creating the FIFOS the process then runs on an interpreter on a new process which reads from the FIFO and runs the commands.  Before this is done, a set of initalization python commands are run which connect to the server and communicate information about the fractal flyer.  The commands later sent on that flyer therefore have context that they are sent by a specific fractal flyer.  If the fractal flyer is in a while loop, the interpreter is closed and reopened.  The entire python environment and objects are destroyed and the interpreter is reopened, reconnects, and is then able again to read commands from the FIFO. While the interpreters are running, the main process is waiting on user input.  If the user types in -1 or ctrl-C a signal is sent to kill all of the processes, close the file structures, and cleanly close the program.  If the user types in any positive number, that flyer index is restarted.  This is intended to resolve any issues with inifinite while loops which can stall an interpreter indefinetly.  


21
simlib.c:  
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
Simlib defines the following python functions:

simlib.init(FF)
- creates socket and informs server of the FF associated with the socket

simlib.body_leds(FF,r,g,b)
- defines the body colors of the fractal flyer
- r,g,b are ints between 0 and 255

simlib.wing_leds(FF,direction,(r1,g1,b1),(r2,g2,b2),(r3,g3,b3))
- defines the three colors of the wing specific by direction of the FF specifiied by FF
- Left = 1; Right = 0;
- r,g,b are ints between 0 and 255

simlib.wing_angle(FF,direction,angle)
- defines the angle of the wing specific by direction of the FF specifiied by FF
- Left = 1; Right = 0;
- angle is a floating point number

41
api.py:  
42
Not used currently.  No longer neccessary