Package: jsbgym
JSBGymJSBGym 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.Pretrained models can be foundhereSetupOpen a terminal and install jsbgym:pip install jsbgymFor Linux systems, rendering with some modes will require an additional package:sudo apt-get install python3-tkTo render the environment with FlightGear, dowloand and install it fromhere. Make sure the FlightGear bin directory is in PATH (UsuallyC:\Program Files\FlightGear 2020.3\bin) and if not already existant, add a system variable calledFG_ROOTwith the FG data folder as it's value (UsuallyC:\Program Files\FlightGear 2020.3\data). For Linux, rename the AppImage file to fgfs.AppImage and place it in /usr/local/bin/fgfs. The data file must also be downloaded fromhere(approximately 2 GB) then in terminal, enterexport FG_ROOT=/path/to/folderIf there are aircraft installed in a different location, add the folder to theFG_AIRCRAFTsystem variable.
3D visualisation requires installation of the FlightGear simulator. Confirm it is runnable from terminal with:fgfs --versionGetting Startedimportjsbgymimportgymnasiumasgymenv=gym.make(ENV_ID)env.reset()observation,reward,terminated,truncated,info=env.step(action)EnvironmentsEnvironment ID strings are constructed as follows:f"{aircraft}-{task}-{shaping}-{flightgear}-v0"AircraftThe environment can be configured to use one of nine aircraft:C172Cessna 172P Skyhawk (Default FlightGear Aircraft)PA28Piper PA-28-161 Warrior IIJ3Piper J-3 CubF15McDonnell Douglas F-15C Eagle (F-15C in FlightGear)F16General Dynamics F-16CJ Block 52OV10North American OV-10A USAFE BroncoPC7Pilatus PC-7A320Airbus A320 (A320 Familiy in Flightgear)B747Boeing 747-400MD11McDonnell Douglas MD-11DHC6de Havilland Canada DHC-6-300 Twin OtterAll aircraft except the Cessna 172P requires the aircraft to be downloaded via the launcher using the default FlightGear Hangar if using flightgear.TaskJSBGym implements two tasks for controlling the altitude and heading of aircraft:HeadingControlTaskaircraft must fly in a straight line, maintaining its initial altitude and direction of travel (heading)TurnHeadingControlTaskaircraft must turn to face a random target heading while maintaining their initial altitudeShapingThe environment can use three different shaping types:Shaping.STANDARDShaping.EXTRAShaping.EXTRA_SEQUENTIALFlightGearIf using FlightGear as a render mode, useFG, if not, useNoFGEnvironment IDTo fly a Cessna on the Heading Control task withoug using FlightGear,env=gym.make("C172-HeadingControlTask-Shaping.STANDARD-NoFG-v0")Visualisation2DA basic plot of agent actions and current state information can be usinghumanrender mode by callingenv.render()after specifying the render mode ingym.make().env=gym.make("C172-HeadingControlTask-Shaping.STANDARD-NoFG-v0",render_mode="human")env.reset()env.render()3DVisualising with FlightGear requires the Gymnasium environment to be created with a FlightGear-enabled environment ID by specifying the render_mode ingym.make()and changing the value after{shaping}toFG. 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("C172-HeadingControlTask-Shaping.STANDARD-FG-v0",render_mode="flightgear")env.reset()env.render()State and Action SpaceJSBGym'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)