Skip to main content

A package of reinforcement learning environments for flight control using the JSBSim flight dynamics model.

Project description

JSBGym

Python: 3.7+ PyPI Version PyPI downloads Code style: black

Note: This library will only work with Windows.

JSBGym provides reinforcement learning environments for the control of fixed-wing aircraft using the JSBSim flight dynamics model. The package's environments implement the Farama-Foundation's Gymnasium interface allowing environments to be created and interacted with.

Setup

Firstly, install JSBSim. Make sure that it is installed in C:/JSBSim

If you would like to render the environment with FlightGear, install it from here. Make sure the FlightGear bin directory is in PATH (Usually C:\Program Files\FlightGear 2020.3\bin)and there is a system variable called FG_ROOT with the FG data folder as it's value (Usually C:\Program Files\FlightGear 2020.3\data). 3D visualisation requires installation of the FlightGear simulator. Confirm it is runnable from terminal with:

fgfs --version

Open the console and install jsbgym:

pip install jsbgym

Getting Started

import jsbgym
import gymnasium as gym

env = gym.make(ENV_ID)
env.reset()
observation, reward, terminated, truncated, info = env.step(action)

Environments

Task

JSBGym implements two tasks for controlling the altitude and heading of aircraft:

  • HeadingControlTask: aircraft must fly in a straight line, maintaining its initial altitude and direction of travel (heading)
  • TurnHeadingControlTask: aircraft must turn to face a random target heading while maintaining their initial altitude

Aircraft

The environment can be configured to use one of Six aircraft:

  • Cessna172P Cessna 172P Skyhawk (Default FlightGear Aircraft)
  • PA28 Piper PA-28-161 Warrior II
  • F15 McDonnell Douglas F-15C Eagle (F-15C in FlightGear)
  • F-16 General Dynamics F-16CJ Block 52
  • A320 Airbus A320 (A320 Familiy in Flightgear)
  • B747 Boeing 747-400

Some aircraft will not work until the next update of JSBSim.

All aircraft except the Cessna 172P requires the aircraft to be downloaded via the launcher using the default FlightGear Hangar.

Shaping

The environment can use three different shaping types:

  • Shaping.STANDARD
  • Shaping.EXTRA
  • Shaping.EXTRA_SEQUENTIAL

Environment ID strings are constructed as follows:

f"{aircraft}-{task}-{shaping}-{flightgear}-v0"

For example, to fly a Cessna on the Heading Control task,

env = gym.make("Cessna172P-HeadingControlTask-Shaping.STANDARD-NoFG-v0")

Visualisation

2D

A basic plot of agent actions and current state information can be using human render mode by calling env.render() after specifying the render mode in gym.make().

env = gym.make("Cessna172P-HeadingControlTask-Shaping.STANDARD-NoFG-v0", render_mode="human")
env.reset()
env.render()

3D

Visualising with FlightGear requires the Gymnasium environment to be created with a FlightGear-enabled environment ID by specifying the render_mode in gym.make() and changing the value after shaping to FG. Using this render mode while training is strongly discouraged due to an error occuring midway through the training (Could not connect to socket for output!).

env = gym.make("Cessna172P-HeadingControlTask-Shaping.STANDARD-FG-v0", render_mode="flightgear")
env.reset()
env.render()

State and Action Space

JSBGym's environments have a continuous state and action space. The state is a 17-tuple:

(name='position/h-sl-ft', description='altitude above mean sea level [ft]', min=-1400, max=85000)
(name='attitude/pitch-rad', description='pitch [rad]', min=-1.5707963267948966, max=1.5707963267948966)
(name='attitude/roll-rad', description='roll [rad]', min=-3.141592653589793, max=3.141592653589793)
(name='velocities/u-fps', description='body frame x-axis velocity [ft/s]', min=-2200, max=2200)
(name='velocities/v-fps', description='body frame y-axis velocity [ft/s]', min=-2200, max=2200)
(name='velocities/w-fps', description='body frame z-axis velocity [ft/s]', min=-2200, max=2200)
(name='velocities/p-rad_sec', description='roll rate [rad/s]', min=-6.283185307179586, max=6.283185307179586)
(name='velocities/q-rad_sec', description='pitch rate [rad/s]', min=-6.283185307179586, max=6.283185307179586)
(name='velocities/r-rad_sec', description='yaw rate [rad/s]', min=-6.283185307179586, max=6.283185307179586)
(name='fcs/left-aileron-pos-norm', description='left aileron position, normalised', min=-1, max=1)
(name='fcs/right-aileron-pos-norm', description='right aileron position, normalised', min=-1, max=1)
(name='fcs/elevator-pos-norm', description='elevator position, normalised', min=-1, max=1)
(name='fcs/rudder-pos-norm', description='rudder position, normalised', min=-1, max=1)
(name='error/altitude-error-ft', description='error to desired altitude [ft]', min=-1400, max=85000)
(name='aero/beta-deg', description='sideslip [deg]', min=-180, max=180)
(name='error/track-error-deg', description='error to desired track [deg]', min=-180, max=180)
(name='info/steps_left', description='steps remaining in episode', min=0, max=300)

Actions are 3-tuples of floats in the range [-1,+1] describing commands to move the aircraft's control surfaces (ailerons, elevator, rudder):

(name='fcs/aileron-cmd-norm', description='aileron commanded position, normalised', min=-1.0, max=1.0)
(name='fcs/elevator-cmd-norm', description='elevator commanded position, normalised', min=-1.0, max=1.0)
(name='fcs/rudder-cmd-norm', description='rudder commanded position, normalised', min=-1.0, max=1.0)

Throttle will be 0.8 by default.

Known Issues

  • Some aircraft when rendering with FlightGear will not start on the ground, but in the ground (A320 does not work completely with render).
  • Human render mode will not work due to Attribute error when calling render with matplotlib>=3.7.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

jsbgym-0.1.7.tar.gz (46.0 kB view details)

Uploaded Source

Built Distribution

jsbgym-0.1.7-py3-none-any.whl (52.2 kB view details)

Uploaded Python 3

File details

Details for the file jsbgym-0.1.7.tar.gz.

File metadata

  • Download URL: jsbgym-0.1.7.tar.gz
  • Upload date:
  • Size: 46.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.2

File hashes

Hashes for jsbgym-0.1.7.tar.gz
Algorithm Hash digest
SHA256 17b4c891260fb40aae55ad6691697b45509f0cd14df30cc417e133e027af99c0
MD5 82e03a31bf69789fe5fc5721796c9bb6
BLAKE2b-256 8f9442940508d800dc7cdc2c24f9bd38ae090f5a9e1aa5bd4d69155e39476090

See more details on using hashes here.

File details

Details for the file jsbgym-0.1.7-py3-none-any.whl.

File metadata

  • Download URL: jsbgym-0.1.7-py3-none-any.whl
  • Upload date:
  • Size: 52.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.2

File hashes

Hashes for jsbgym-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 99ddc2894ee71ab5f4040813db78b672ea223a2092c42286127c3035f3d6d982
MD5 be0e7179b1d5b5879645dce14ec70519
BLAKE2b-256 a9276ab9a41cd33fee5ee7c1ebb9a8fbbef41ed6e2f1e1ecdf7a05b5cc7f54b3

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page