{"id":22831001,"url":"https://github.com/eyalgolan/flightgearproject","last_synced_at":"2025-08-23T06:36:44.795Z","repository":{"id":80018467,"uuid":"228156658","full_name":"eyalgolan/FlightGearProject","owner":"eyalgolan","description":"An interpreter that runs an autopilot for the FlightGear simulator","archived":false,"fork":false,"pushed_at":"2020-01-05T20:47:24.000Z","size":745,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-31T01:42:13.691Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/eyalgolan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-12-15T09:05:10.000Z","updated_at":"2020-01-07T04:56:31.000Z","dependencies_parsed_at":"2023-09-18T19:00:45.151Z","dependency_job_id":null,"html_url":"https://github.com/eyalgolan/FlightGearProject","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/eyalgolan/FlightGearProject","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eyalgolan%2FFlightGearProject","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eyalgolan%2FFlightGearProject/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eyalgolan%2FFlightGearProject/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eyalgolan%2FFlightGearProject/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eyalgolan","download_url":"https://codeload.github.com/eyalgolan/FlightGearProject/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eyalgolan%2FFlightGearProject/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271745679,"owners_count":24813521,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-23T02:00:09.327Z","response_time":69,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-12T20:16:21.741Z","updated_at":"2025-08-23T06:36:44.760Z","avatar_url":"https://github.com/eyalgolan.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# FlightGearProject\n\n## Preview\n\n**LINK TO GITHUB PROJECT:** https://github.com/eyalgolan/FlightGearProject\n \nAn interpreter that runs an autopilot for the **FlightGear** simulator\n (You can learn more about FlightGear [**here**](https://www.flightgear.org/ \"FlightGear Homepage\")).\n\nThe program gets a script as an argument which contains different commands and\ninterprets the commands. \n\nFirst, the program lexes the input file, then it parses \nit and finally it executes the commands.\n\nThis project includes the following elements:\n* Design Patters\n* Client-Server architecture\n* Usage of data structures\n* Working with files\n* Working with threads\n\n## Setup\nFirst, in order to set the FlightGear simulator to connect to our server and \naccept a connection from our client, go to `Settings` -\u003e `Additional Settings` \nand add:\n```\n--generic=socket,out,10,127.0.0.1,5400,tcp,generic_small\n‪--telnet=socket,in,10,127.0.0.1,5402,tcp‬\n```\nNote that:\n \n * `--generic=socket,out,10,127.0.0.1,5400,tcp,generic_small` means that\n the simulator will try to send flight input to IP `127.0.0.1` in port `5400`, \n by the format of `generic_small.xml`.\n * `‪--telnet=socket,in,10,127.0.0.1,5402,tcp‬` means that the simulator will try\n to receive flight instructions in IP `127.0.0.1` and port `5402`.\n \nThen, in order to compile our program, `cd` to the folder to which you downloaded\n the project. Run:\n```\ng++ -std=c++11 *.cpp -Wall -Wextra -Wshadow -Wnon-virtual-dtor -pedantic -o a.out -pthread\n```\nThen, run the program with the script of commands: (for example, if the script\n name is `fly.txt`)\n```\n./a.out fly.txt\n```\n**Note** that the script file needs to reside in the **SAME FOLDER** in which you \ncompiled the project.\n\n## Program explanation:\n### Commands\n\n1. **openDataServer**: Receives a port number and opens a server in another thread,\n which listens in that port. The simulator connects to the server and sends it\n  flight data. \n  \n  \tFor example:\n  \t```\n  \topenDataServer(5400)\n  \t```\n  \tWill open a server thread that will listen for information from the \n  \tsimulator in port `5400`.\n2. **connectControlClient**: Receives the simulator's port number and an IP address, \nand opens a thread that connects to it. The thread gets flight instructions from\n the program and sends them to the simulator.\n \t\n \tFor example:\n \t```\n \tconnectControlClient(\"127.0.0.1\",5402)\n \t```\n \tWill open a client thread that will try to connect to the simulator in IP\n \t `127.0.0.1` and port `5402`.\n3. **Sleep**: Receives a numeric value and pauses the execution of new commands\n from the script for the time received.\n \t\n \tFor example:\n \t```\n \tSleep(5000)\n \t```\n \tWill Pause the program from executing new commands from the script, for \n \t`5000` milliseconds (5 seconds).\n4. **Print**: Receives a numeric, string or var (more about variables in the \n*\"Working with variables\"* section) input and prints it to the \nconsole.\n\n\tFor example:\n\t```\n\tPrint(5000)\n\t```\n\tWill print `5000` to the console.\n\n### Sending and receiving data\nWe receive flight data from the simulator using the thread created by the \n`OpenDataServer`.\n\nWe send data to the simulator using the client thread opened by \n`connectControlClient`, in the following format: `set \u003csimPath\u003e \u003cValue\u003e`, for\nexample:\n```\nset /controls/gear/brake-right 1.000000\n```\n\n### Working with variables\nWe work with variables in the following ways:\n1. Defining a new variable: A new var can be set with:\n\t* A value, for example:\n\t\t```\n\t\tvar rudder = 0\n\t\t```\n\t* A simulator path with a side indicator:\n\t\t```\n\t\tvar heading \u003c- sim(\"/instrumentation/heading-indicator/offset-deg\")\n\t\t```\n\t* Another existing variable:\n\t\t```\n\t\tvar h0 = heading\n\t\t```\n2. Setting an existing variable with a value, by value or by variable:\n\t```\n\tmagnetos = 3\n\t```\n\tOr:\n\t```\n\tmagnetos = rudder\n\t```\n### Conditions and Loops\nThe script we interpret can contain `if` condition and `while` loops:\n* In the case of an `if` condition, the program will execute the commands in the\n `if`'s scope, if it's condition is met.\n* In the case of a `while` loop, the program will loop over the commands in the\n `while`'s scope, while it's condition is met.\n\n### Program architecture\nThe program contains the following classes:\n1. **Lexer**: The lexer gets a filename. The script in the file is written in a new \n          programing language that we need to interpret.\n          The role of the lexer is to seperate the code by commas and build then into a\n          vector.\n2. **Parser**: Runs each command in the input vector and executes it.\n5. **SymbolTable**: A singelton class. The symbol table maintains the current state \nof the plane, the current values of all the variables defined in the program, \nand a mutex used for controlling the threads access to the symbol table.\n3. **Command**: A parent class, containing a virtual `exec` function. \n\n\tEach of the following inheriting classes implement their own version of the\n\t `exec` function:\n\t* OpenServerCommand\n\t* ConnectCommand\n\t* DefineVarCommand\n\t* setVarCommand\n\t* AssignVarCommand\n\t* IfCommand\n\t* LoopCommand\n\t* SleepCommand\n\t* PrintCommand\n4. **ConditionParser**: Used by the `IfCommand` and `LoopCommand` to checks if a \n\tprovided condition is satisfied and updates accordingly.\n5. **ExpressionHandler**: Interprets nested mathematical expressions that include \n\tvariables and evaluate them.\n\t\n## Example of a script the program receives:\n```\nopenDataServer(5400)\nconnectControlClient(\"127.0.0.1\",5402)\nvar warp -\u003e sim(\"/sim/time/warp\")\nvar magnetos -\u003e sim(\"/controls/switches/magnetos\")\nvar throttle -\u003e sim(\"/controls/engines/current-engine/throttle\")\nvar mixture -\u003e sim(\"/controls/engines/current-engine/mixture\")\nvar masterbat -\u003e sim(\"/controls/switches/master-bat\")\nvar masterlat -\u003e sim(\"/controls/switches/master-alt\")\nvar masteravionics -\u003e sim(\"/controls/switches/master-avionics\")\nvar brakeparking -\u003e sim(\"/sim/model/c172p/brake-parking\")\nvar primer -\u003e sim(\"/controls/engines/engine/primer\")\nvar starter -\u003e sim(\"/controls/switches/starter\")\nvar autostart -\u003e sim(\"/engines/active-engine/auto-start\")\nvar breaks -\u003e sim(\"/controls/flight/speedbrake\")\nvar heading \u003c- sim(\"/instrumentation/heading-indicator/offset-deg\")\nvar airspeed \u003c- sim(\"/instrumentation/airspeed-indicator/indicated-speed-kt\")\nvar roll \u003c- sim(\"/instrumentation/attitude-indicator/indicated-roll-deg\")\nvar pitch \u003c- sim(\"/instrumentation/attitude-indicator/internal-pitch-deg\")\nvar rudder -\u003e sim(\"/controls/flight/rudder\")\nvar aileron -\u003e sim(\"/controls/flight/aileron\")\nvar elevator -\u003e sim(\"/controls/flight/elevator\")\nvar alt \u003c- sim(\"/instrumentation/altimeter/indicated-altitude-ft\")\nvar rpm \u003c- sim(\"/engines/engine/rpm\")\nPrint(\"waiting 2 minutes for gui\")\nSleep(120000)\nPrint(\"let's start\")\nwarp = 32000\nSleep(1000)\nmagnetos = 3\nthrottle = 0.2\nmixture = 0.949\nmasterbat = 1\nmasterlat = 1\nmasteravionics = 1\nbrakeparking = 0\nprimer = 3\nstarter = 1\nautostart = 1\nPrint(\"engine is warming...\")\nPrint(rpm)\nwhile rpm \u003c= 750 {\n\tPrint(rpm)\n}\nSleep(5000)\nPrint(\"let's fly\")\nvar h0 = heading\nbreaks = 0\nthrottle = 1\nwhile alt \u003c 1000 {\n\trudder = (h0 - heading)/80\n\taileron = -roll / 70\n\televator = pitch / 50\n\tSleep(250)\n}\nPrint(\"done\")\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feyalgolan%2Fflightgearproject","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feyalgolan%2Fflightgearproject","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feyalgolan%2Fflightgearproject/lists"}