GithubHelp home page GithubHelp logo

adderbyte / gym_xplane_ml Goto Github PK

View Code? Open in Web Editor NEW
65.0 12.0 19.0 39.71 MB

GYM Environment for XPlane. Reinforcement Learning and Autonomous Piloting.

License: GNU General Public License v3.0

Python 91.70% Lua 5.26% Shell 0.17% Dockerfile 1.13% HTML 1.75%
xplane rl-algorithm simulation agent algorithm

gym_xplane_ml's Introduction


XPlane_ML_Reinforcement_Learning_Autopilot

This project documents set up of Reinforcement learning environment for flight control. This will enable each user/learner/student/flight enthusiast to come with their own RL algorithm that can interact with and control in real time an aircraft in a simulation environment. The simulator used is X-Plane (the flight environment). This gives a realistic environment to work with together with parameters to help keep the simulation as close to reality as possible.

Update: Use the leaderboard wiki Page--> (Leaderboard) to add details of your own scenario or (reinforcement learning) algorithm.


  GYM-XPLANE ENVIRONMENT INSTALLATION

To install the gym x-palne environment go through the read me file of the folder : Gym-Xplane-final version This is the latest version of the actual gym-xplane environment.

The other folders contain additional modules for additional functionalities. The names of such folders would give an idea as to what each of such modules does.

Read the Wiki to get a general idea of the environment and training procedure (Gym-Xplane Wiki).


Requirements


General setup

  • GYM XPLANE ENVIRONMENT
  • MULTI AGENT ENVIRONMENT SET UP (Work in progress)

Agent-Environment Interaction Flow


alt-text


Example Training Episode


alt-text


Action Space Parameters


The possible action parameters are given below. The choice of parameters would depend on the task. For example one might decide that the last three parameters are not important for the keep heading task (Gym Xplane Wiki) .

Action Space Parameter Action type Action Value Range
Latitudinal Stick Box [-1,1]
Longitudinal Stick Box [-1,1]
Rudder Pedals Box [-1,1]
Throttle Box [-1/4,1]
Gear Discrete 0,1
Flaps Box [0,1]
Speedbrakes Box [-0.5,1.5]

State Space Parameters


The state space parameters are well documented in XPlane Data Ref. The number and configuration of state space parameters would also depend on the task. It is possible to use a derived state spade parameters.

Note that, usually a UDP connection (XPlaneConnect) is required to read any parameter parameter from XPlane. An example of how to read parameter from UDP connection is shown below:

client = xpc.XPlaneConnect() # UDP connector
client.getDREF("sim/flightmodel/position/P")[0][0] # moment P
client.getPOSI() # get the lat, long,altitude, pitch, roll, heading, gear

A typical state space parameter configuration is shown below:

State Space Parameter State type State Value Range
velocity_x Box [0,120]
velocity_y Box [0,120]
delta_heading Box [-300,300]

The range of each parameter value would also depend on the configuration or simulation task.

client (UDP connector) already has a function getPOSI that helps read the latitude, longitude, altitude, pitch, roll, heading. Other parameters could be added by using the client getDREF function. Note that the string "sim/flightmodel/position/P" is gotten from the Xplane Dataref referenced earlier (XPlane Data Ref)


Flight Dashboard


To learn more about this go to : FlightDataVizDashBoard alt-text


TO DO

  • Use XVFB for fake display.
  • Docker support (under test)
  • Algorithm implementations (high priority) / GPU support to be included
  • Real Time flight and data visualization interface.
  • Investigate Federated Learning / Thompson Sampling / policy-space response oracles (psro)

gym_xplane_ml's People

Contributors

adderbyte avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gym_xplane_ml's Issues

Headless mode issue with Xvfb

Hi,

I tried running X-plane in headless mode with a command from the bash file (xvfb-run --server-args=':1 -screen 0, 1024x768x16' ./X-Plane-x86_64 > /dev/null &) and I am getting Exit 1 or it just exits out if I run it with sudo.
I suspect it's some setup issue on my system. Have you had any similar errors when you first tried to run X-plane with xvfb?

Thanks a lot

X-Plane in headless mode saving GPU power?

Hello adderbyte,
very interesting work! I'm really curious to try out your GYM environment as I'm about to code something very similar.

I just wonder, whether using X-Plane in headless mode really saves any GPU resources. As far as I understood, X-Plane still renders the entire scene, but instead of displaying it, it just dumps the graphics to /dev/null. Is that understanding correct?
Thanks a lot,
Felix

how to use the program

could you please tell me the detail about how to use the program?
thank you very much!

An operation was attempted on something that is not a socket

Hi,

I downloaded the whole GYM_XPLANE_ML and ran the keepHeading.py in the jupyter notebook shell by: !python keepHeading.py
But it doesn't work:
XPPlane Host: 127.0.0.1
checking Client Port: 1
checking Destination Addr (XPlane): ('127.0.0.1', 49009)
checking Client Addr: ('0.0.0.0', 1)
Press enter to end: ...

Traceback (most recent call last):
File "keepHeading.py", line 138, in
main() # run main
File "keepHeading.py", line 123, in main
if sys.stdin in select.select([sys.stdin], [], [], 0)[0]:
OSError: [WinError 10038] An operation was attempted on something that is not a socket

Do you know what may be the problem? Thanks!!

License of the repository

First of all, thank you for this nice repository.
What is the license of the code? I haven't found any license file in the code.

Regards,
Szilard

pip list ?

Hello adderbyte, could you elaborate on the python modules version you used to run it ? a "pip list" is just enough....
thank you
Moyo

gpu support in headless mode

Hi,

Is there any way to use GPU when running the XPlane headless?
The xvfb renders on the CPU and we need to maintain some minimal FPS for the physics calculations that the CPU can't handle.

Thanks in advance.

ModuleNotFoundError: No module named 'gym_xplane'

Hi,

Can you please help me with this error I am facing: ModuleNotFoundError: No module named 'gym_xplane'

I installed X-Plane, gym_xplane according to the Readme file in gym_xplane_finalversion. Somehow, it doesn't seem to detect gym_xplane, even though I had installed it via command like according to instructions.

Thank you
Lakshmi

Resetting the simulation

How should I reset an X-plane session back to its initial state?

So far I have tried sending a set of DataRefs (position, elevation, heading, etc) to X-Plane, like so:

        self.client.sendDREF("sim/flightmodel/position/local_vx", 0)
        self.client.sendDREF("sim/flightmodel/position/local_vy", 0)
        self.client.sendDREF("sim/flightmodel/position/local_vz", 0)

        self.client.sendDREF("sim/flightmodel/position/theta", 0)
        self.client.sendDREF("sim/flightmodel/position/phi", 0)
        self.client.sendDREF("sim/flightmodel/position/psi", 0)

        self.client.sendDREF("sim/flightmodel/position/local_ax", 0)
        self.client.sendDREF("sim/flightmodel/position/local_ay", 0)
        self.client.sendDREF("sim/flightmodel/position/local_az", 0)

        self.client.sendDREF("sim/flightmodel/position/P", 0)
        self.client.sendDREF("sim/flightmodel/position/Q", 0)
        self.client.sendDREF("sim/flightmodel/position/R", 0)

        self.client.sendDREF("sim/flightmodel/position/true_theta", 0)
        self.client.sendDREF("sim/flightmodel/position/true_phi", 0)
        self.client.sendDREF("sim/flightmodel/position/true_psi", 0) 

But this does not always result in a perfect reset, occasionally there are subtle changes between resets.

Is it possible to reset by reloading an X-Plane situation file?

Additionally, could someone clarify how the reloadScript.lua is called? This does not appear to be documented beyond simply placing it in the X-Plane scripts folder.

Inconsistency between state and self.ControlParameters.state14

While trying to understand the workings of the code and writing an agent myself, I noticed certain inconsistencies in the parameters defined in parameters.py file and value assignment to those variables in xplane_envBase.py file.
In Line 14 of parameters.py file state14 is defined as:
"state14" :{"roll_rate" :0 ,"pitch_rate" :0, "altitude": 0 ,"Pitch" :0 ,"Roll" :0, "velocity_x": 0, "velocity_y" :0 ,"velocity_z" :0 ,"delta_altitude" :0, "delta_heading" :0 ,"yaw_rate" :0},

then on Line 139 of xplane_envBase.py the variable state is assigned:

state = self.ControlParameters.stateAircraftPosition + self.ControlParameters.stateVariableValue

stateAircraftPosition is retrieved from XPlane Connect's getPOSI() function which returns these values : [Lat, Lon, Alt, Pitch, Roll, Yaw, Gear]

and stateVariableValue containes values for these drefs:

"stateVariable" : ["sim/flightmodel/position/local_vx" ,"sim/flightmodel/position/local_vy", "sim/flightmodel/position/local_vz"],

so, essentially the list 'state' contains following variables:
state = [Lat, Lon, Alt, Pitch, Roll, Yaw, Gear, local_vx, local_vy, local_vz]

However, when we look at assignments in Line 175, 176 and 177 of xplane_envBase.py file it can be noted that

  1. state14['velocity_x'] = state[6] whereas state[6] = Gear
  2. state14['velocity_y'] = state[6] whereas state[6] = local_vx
  3. state14['velocity_z'] = state[6] whereas state[6] = local_vy

So, I don't know if I am missing on something or what, but this should have a major impact on training.

deepcopy in python 3.6 giving:: rv = reductor(4) TypeError: 'NoneType' object is not callable

This is happening when using stable_baselines3 A2C to implement actor-critic agent and PPO agent.

Traceback (most recent call last):
File "/snap/pycharm-community/256/plugins/python-ce/helpers/pydev/pydevd.py", line 1483, in _exec
pydev_imports.execfile(file, globals, locals) # execute the script
File "/snap/pycharm-community/256/plugins/python-ce/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "/home/iman/GYM_XPLANE_ML/gym_xplane_final_version/examples/a2c_agent.py", line 76, in
main_a2c(env)
File "/home/iman/GYM_XPLANE_ML/gym_xplane_final_version/examples/a2c_agent.py", line 44, in main_a2c
model.learn(total_timesteps=100, callback=[checkpoint_callback, eval_callback])
File "/home/iman/miniconda3/envs/gym_xplane_final_version_py3.6/lib/python3.6/site-packages/stable_baselines3/a2c/a2c.py", line 201, in learn
reset_num_timesteps=reset_num_timesteps,
File "/home/iman/miniconda3/envs/gym_xplane_final_version_py3.6/lib/python3.6/site-packages/stable_baselines3/common/on_policy_algorithm.py", line 249, in learn
continue_training = self.collect_rollouts(self.env, callback, self.rollout_buffer, n_rollout_steps=self.n_steps)
File "/home/iman/miniconda3/envs/gym_xplane_final_version_py3.6/lib/python3.6/site-packages/stable_baselines3/common/on_policy_algorithm.py", line 179, in collect_rollouts
new_obs, rewards, dones, infos = env.step(clipped_actions)
File "/home/iman/miniconda3/envs/gym_xplane_final_version_py3.6/lib/python3.6/site-packages/stable_baselines3/common/vec_env/base_vec_env.py", line 162, in step
return self.step_wait()
File "/home/iman/miniconda3/envs/gym_xplane_final_version_py3.6/lib/python3.6/site-packages/stable_baselines3/common/vec_env/dummy_vec_env.py", line 51, in step_wait
return (self._obs_from_buf(), np.copy(self.buf_rews), np.copy(self.buf_dones), deepcopy(self.buf_infos))
File "/home/iman/miniconda3/envs/gym_xplane_final_version_py3.6/lib/python3.6/copy.py", line 150, in deepcopy
y = copier(x, memo)
File "/home/iman/miniconda3/envs/gym_xplane_final_version_py3.6/lib/python3.6/copy.py", line 215, in _deepcopy_list
append(deepcopy(a, memo))
File "/home/iman/miniconda3/envs/gym_xplane_final_version_py3.6/lib/python3.6/copy.py", line 150, in deepcopy
y = copier(x, memo)
File "/home/iman/miniconda3/envs/gym_xplane_final_version_py3.6/lib/python3.6/copy.py", line 240, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/home/iman/miniconda3/envs/gym_xplane_final_version_py3.6/lib/python3.6/copy.py", line 169, in deepcopy
rv = reductor(4)
TypeError: 'NoneType' object is not callable

Can't import gym_xplane

Hi,
I can't seem to run random_agents.py because the console said ModuleNotFoundError: No module named 'gym_xplane'

I've followed the instruction, and that's something i got. Can anyone help? Is there any other way to install the gym_xplane package without easy install? I'm using Windows 10 btw.

Another thing I want to ask is I try to pip install in gym_xplane directory but it doesn't have setup.py so i moved the setup.py in the upper directory here. Is it wrong? Thank you.

Connection error when running sarsa.py

Hi I downloaded everything and also installed the gym_xplane package. Then I ran random_agent.py first, there is no error, but the action space and state space are all 0. Then I ran the sarsa.py, then I got an error: connection error. Check your paramters. Do I need to change anything in the connection setting in order to let it work?

I'm looking forward to your reply!

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.