# jMAVSim with SITL

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:

This topic shows how to set up jMAVSim to connect with a SITL version of PX4.

jMAVSim can also be used for HITL Simulation (as shown here.

## Simulation Environment

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:

## Running SITL

After ensuring that the simulation prerequisites are installed on the system, just launch: The convenience make target will compile the POSIX host build and run the simulation.

make px4_sitl_default jmavsim


This will bring up the PX4 shell:

[init] shell id: 140735313310464

______  __   __    ___
| ___ \ \ \ / /   /   |
| |_/ /  \ V /   / /| |
|  __/   /   \  / /_| |
| |     / /^\ \ \___  |
\_|     \/   \/     |_/

pxh>


It will also bring up a window showing a 3D view of the jMAVSim simulator:

## Taking it to the Sky

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:

pxh> commander takeoff


You can use QGroundControl to fly a mission or to connect to a joystick.

## Usage/Configuration Options

### Set Custom Takeoff Location

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:

export PX4_HOME_LAT=28.452386
export PX4_HOME_LON=-13.867138
export PX4_HOME_ALT=28.5
make px4_sitl_default jmavsim


### Change Simulation Speed

The simulation speed can be increased or decreased with respect to realtime using the environment variable PX4_SIM_SPEED_FACTOR.

export PX4_SIM_SPEED_FACTOR=2
make px4_sitl_default jmavsim


### Using a Joystick

Joystick and thumb-joystick support are supported through QGroundControl (setup instructions here).

### Simulating a Wifi Drone

There is a special target to simulate a drone connected via Wifi on the local network:

make broadcast jmavsim


The simulator broadcasts its address on the local network as a real drone would do.

### Start JMAVSim and PX4 Separately

You can start JMAVSim and PX4 separately:

./Tools/jmavsim_run.sh -l
make px4_sitl none


This allows a faster testing cycle (restarting jMAVSim takes significantly more time).

## Multi-Vehicle Simulation

JMAVSim can be used for multi-vehicle simulation: Multi-Vehicle Sim with JMAVSim.

## Extending and Customizing

To extend or customize the simulation interface, edit the files in the Tools/jMAVSim folder. The code can be accessed through thejMAVSim repository on Github.

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.

## Interfacing to ROS

The simulation can be interfaced to ROS the same way as onboard a real vehicle.

## Important Files

• The startup script is in the posix-configs/SITL/init folder and named rcS_SIM_AIRFRAME, the default is rcS_jmavsim_iris.
• The simulated root file system ("/" directory) is created inside the build directory here: build/px4_sitl_default/tmp/rootfs.