Skip to content

israelElad/AP1-FlightSimulator-Interpreter

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

76 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AP1-FlightSimulator-Interpreter

Second year first semester- "Advanced programming 1" course, first milestone- Interpreter: C++

Implementation of an interpreter for the FlightGear simulator (for more details about the FlightGear simulator click here).
The program gets a script file that contains various commands. By using a lexer, the program splits the script into strings that can be interpreted, and then interprets them by using an interpreter, with the help of the Command design pattern.

Example:

Interpreting the following commands and sending them to the FlightGear's server will make the plane lift-off and fly as shown in the photos above:

The project contains the following elements:

  • Use of design patterns (such as Command and Object Adapter patterns) and architecture.
  • Communication and Client-Server Architecture.
  • Use of data structures and database.
  • Data Streaming (files & communication).
  • Parallel programming using threads.

Running the code (in Linux environment):

First, you need to download the FlightGear simulator.
Add the generic_small.xml file to the /data/Protocol directory where you installed the simulator.
Open the FlightGear simulator and add the following settings in the "Settings" tab:

--telnet=socket,in,10,127.0.0.1,5402,tcp --httpd=8080
--generic=socket,out,10,127.0.0.1,5400,tcp,generic_small

--telnet=socket,in,10,127.0.0.1,5402,tcp tells the simulator to open in the background a server that any telnet client can connect to it. The server is established on a socket with the IP 127.0.0.1 (i.e. local host - on the same computer), and the port 5402, and it will read the data at a rate of 10 times per second, over TCP/IP protocol. --httpd=8080 will open a web server on port 8080.

--generic=socket,out,10,127.0.0.1,5400,tcp,generic_small tells the simulator to connect as a client to the server through a socket with the IP 127.0.0.1 and the port 5400, and it will send data at a rate of 10 times per second by the format of generic_small.xml file. We will need to open our server before opening the simulator, so that it can connect to it as a client.
The simulator will send at a rate of 10 times per second the sampled values, separated by a comma just like in CSV (and in the order defined in generic_small.xml).

To compile the code, open a terminal, route to the directory where you downloaded the code and run the following command:

g++ -std=c++11 *.cpp -Wall -Wextra -Wshadow -Wnon-virtual-dtor -pedantic -o a.out -pthread

To run the code, run the following command:

./a.out Script.txt 

Then, the program will wait for the FlightGear simulator to connect to the data server.

Click on the 'Fly!' button in the FlightGear simulator and wait for the simulator to connect and the GUI to load.
When the interpreter will start to interpret the script, the plane will take off and fly.

About

An interpreter for the FlightGear simulator, enabling remote control on an aircraft by analyzing and executing commands from a given script. The program gets a script file that contains various commands, splits it into strings by using a lexer, and then interprets them by using an interpreter. The project contains design patterns, communication,…

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • C++ 98.8%
  • CMake 1.2%