Giter VIP home page Giter VIP logo

flight-gear-simulator's Introduction

Flight simulator

FlightGear-Interpreter

link to github - https://github.com/RoeeZider/updatedSim

An Interpreter project for a FlightGear flight simulator. The program connects to the simulator and flys the aircraft based on the user's commands , that will show withe attached file.

Prerequisites

Linux environment to run the code

Installing

Download and install the simulator on your computer -https://www.flightgear.org/download/

Add the generic_small.xml file to the /data/Protocol directory where you installed the simulator Config the following settings in the 'Settings' tab in the simulator:

--telnet=socket,in,10,127.0.0.1,5402,tcp

--generic=socket,out,10,127.0.0.1,5400,tcp,generic_small

This will open two communication sockets - 'in' where you send commands to the simulator, and 'out' where you receive data from it.

Running

a. Exceute the code using the terminal or any c++ work environment. The program will wait for a connection from the simulator.

b. Click the 'Fly!' icon in the simulator in the bottom left corner (see above picture), and wait for the simulator to load. It will connect to the interpreter in the meantime.

The code is designed to read lines of commands entered in a terminal from the user once the program has started running. The commands can be entered one at a time or by using a pre-made script (make sure each command starts in a new line).

First, enter the following commands to open a local communication server to the simulator and connect to it: openDataServer(5400) connectControlClient("127.0.0.1",5402)

Initialize your variables:

openDataServer(5400) connectControlClient("127.0.0.1",5402) var warp-> sim("/sim/time/warp") var magnetos->sim("/controls/switches/magnetos") var throttle-> sim("/controls/engines/current-engine/throttle") var mixture ->sim("/controls/engines/current-engine/mixture") var masterbat -> sim("/controls/switches/master-bat") var masterlat -> sim("/controls/switches/master-alt") var masteravionics -> sim("/controls/switches/master-avionics") var brakeparking -> sim("/sim/model/c172p/brake-parking") var primer -> sim("/controls/engines/engine/primer") var starter -> sim("/controls/switches/starter") var autostart -> sim("/engines/active-engine/auto-start") var breaks -> sim("/controls/flight/speedbrake") var heading<- sim("/instrumentation/heading-indicator/offset-deg") var airspeed <-sim("/instrumentation/airspeed-indicator/indicated-speed-kt") var roll <- sim("/instrumentation/attitude-indicator/indicated-roll-deg") var pitch <- sim("/instrumentation/attitude-indicator/internal-pitch-deg") var rudder -> sim("/controls/flight/rudder") var aileron -> sim("/controls/flight/aileron") var elevator -> sim("/controls/flight/elevator") var alt <- sim("/instrumentation/altimeter/indicated-altitude-ft") var rpm <- sim("/engines/engine/rpm") var blc -> sim("/controls/gear/brake-right") Print ("waiting 2 minutes for gui") Sleep(50000) Print("let's start") warp = 32000 Sleep(1000) magnetos= 3 throttle =0.2 mixture = 0.949 masterbat = 1 masterlat = 1 masteravionics = 1 brakeparking = 0 primer = 3 starter = 1 autostart = 1 Print("engine is warming...") Print(rpm) while rpm <= 750 { Print(rpm) } Sleep(5000) Print("let's fly") Sleep(1000) var h0=heading breaks = 0 throttle = 1 while alt < 1000 { rudder = (h0 - heading)/80 aileron = -roll / 70 elevator = pitch / 50 blc=1 Sleep(19) blc=0 Sleep(250) } Print("done")

The program reads the code, parses it and sends the commands to the simulator, changing the behavior of the aircraft accordingly. In this example, the interpreter enters the loop, adjusts variables, prints the current altitude of the aircraft and halts the reading for 250 miliseconds.
When the altitude is over 1000, the loop will terminate and the next lines will be parsed.

When the program finish to read the fly.txt, it will stop sending commands to the simulator, terminating the communication with it and ending the program. In our fly.txt - it will print "done" at the console.

flight-gear-simulator's People

Contributors

harel-feldman avatar roeezider avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.