jMAVSim Simulation
Last updated
Last updated
jMAVSim is a simple multirotor/Quad simulator that allows you to fly copter type vehicles running PX4 around a simulated world. It is easy to set up and can be used to test that your vehicle can take off, fly, land, and responds appropriately to various fail conditions (e.g. GPS failure).
Supported Vehicles:
Quad
This topic shows how to set up jMAVSim to connect with a SITL version of PX4.
:::tip jMAVSim can also be used for HITL Simulation (). :::
jMAVSim setup is included in our (for macOS, Ubuntu Linux, Windows).
Software in the Loop Simulation runs the complete system on the host machine and simulates the autopilot. It connects via local network to the simulator. The setup looks like this:
After ensuring that the are installed on the system, just launch: The convenience make target will compile the POSIX host build and run the simulation.
This will bring up the PX4 shell:
The system will start printing status information. You will be able to start flying once you have a position lock (shortly after the console displays the message: EKF commencing GPS fusion).
To takeoff enter the following into the console:
The default takeoff location in can be overridden using the environment variables: PX4_HOME_LAT
, PX4_HOME_LON
, and PX4_HOME_ALT
.
For example, to set the latitude, longitude and altitude:
The simulation speed can be increased or decreased with respect to realtime using the environment variable PX4_SIM_SPEED_FACTOR
.
There is a special target to simulate a drone connected via Wifi on the local network:
The simulator broadcasts its address on the local network as a real drone would do.
You can start JMAVSim and PX4 separately:
This allows a faster testing cycle (restarting jMAVSim takes significantly more time).
To start jMAVSim without the GUI, set the env variable HEADLESS=1
as shown:
:::note The build system enforces the correct submodule to be checked out for all dependencies, including the simulator. It will not overwrite changes in files in the directory, however, when these changes are committed the submodule needs to be registered in the Firmware repo with the new commit hash. To do so, git add Tools/jMAVSim
and commit the change. This will update the GIT hash of the simulator. :::
The simulated root file system ("/
" directory) is created inside the build directory here: build/px4_sitl_default/rootfs
.
This warning can be ignored (it will probably be displayed but the simulation will still work correctly).
If you see this error, try this workaround:
Edit the accessibility.properties file:
and comment out the line indicated below:
When compiling jMAVsim, you might encounter the following error:
This error is telling you, you need a more recent version of Java in your environment. Class file version 58 corresponds to jdk14, version 59 to jdk15, version 60 to jdk 16 etc.
To fix it under macOS, we recommend installing OpenJDK through homebrew
It will also bring up a window showing a 3D view of the simulator:
You can use QGroundControl to fly a mission or to connect to a .
Options that apply to all simulators are covered in the top level topic (some of these may be duplicated below).
explains how to trigger safety failsafes like GPS failure and battery drain.
For more information see: .
Joystick and thumb-joystick support are supported through QGroundControl ().
JMAVSim can be used for multi-vehicle simulation: .
To extend or customize the simulation interface, edit the files in the Tools/jMAVSim folder. The code can be accessed through the on Github.
The simulation can be the same way as onboard a real vehicle.
The startup scripts are discussed in .
This error should no longer occur once the jMAVSim submodule is and Java 11 or Java 14 should work fine.
For more info, check . A contributor found the fix in .