# Simulation-In-Hardware

Simulation-In-Hardware (SIH) is an alternative to [Hardware In The Loop simulation (HITL)](https://px4.gitbook.io/px4-user-guide/development/simulation/hitl) for quadrotors, fixed-wing vehicles (airplane), and tailsitters. In this setup, everything is running on embedded hardware - the controller, the state estimator, and the simulator. The Desktop computer is only used to display the virtual vehicle.

![Simulator MAVLink API](https://4155462212-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LArEa7z2SPawfl3HpCD%2Fuploads%2Fgit-blob-62bd88f46a4475589f44a372a0733af811327efc%2FSIH_diagram.png?alt=media)

The SIH provides two benefits over the HITL:

* It ensures synchronous timing by avoiding the bidirectional connection to the computer. As a result the user does not need such a powerful desktop computer.
* The whole simulation remains inside the PX4 environment. Developers who are familiar with PX4 can more easily incorporate their own mathematical model into the simulator. They can, for instance, modify the aerodynamic model, or noise level of the sensors, or even add a sensor to be simulated.

The SIH can be used by new PX4 users to get familiar with PX4 and the different modes and features, and of course to learn to fly a quadrotor or an airplane with the real RC controller.

The quadrotor dynamic model is described in this [pdf report](https://github.com/PX4/PX4-user_guide/raw/main/assets/simulation/SIH_dynamic_model.pdf).

The aerodynamic model for the fixed-wing airplane is inspired from the PhD thesis:

> "Dynamics modeling of agile fixed-wing unmanned aerial vehicles." Khan, Waqas, supervised by Nahon, Meyer, McGill University, PhD thesis, 2016.

The model for the tailsitter vehicle is inspired from the Master thesis:

> "Modeling and control of a flying wing tailsitter unmanned aerial vehicle." Chiappinelli, Romain, supervised by Nahon, Meyer, McGill University, Masters thesis, 2018.

Furthermore, the physical parameters representing the vehicle (such as mass, inertia, and maximum thrust force) can easily be modified from the [SIH parameters](https://px4.gitbook.io/px4-user-guide/advanced_config/parameter_reference#simulation-in-hardware).

@[youtube](https://youtu.be/PzIpSCRD8Jo)

## Requirements

To run the SIH, you will need a [flight controller](https://px4.gitbook.io/px4-user-guide/drone_parts/flight_controller) (e.g. a Pixhawk-series board). you will also need either a [radio control transmitter and receiver pair](https://px4.gitbook.io/px4-user-guide/getting_started/rc_transmitter_receiver) or a [joystick](https://docs.qgroundcontrol.com/master/en/SetupView/Joystick.html) (a joystick can be used via QGroundControl to emulate a radio control system).

* SIH is compatible with all Pixhawk-series boards except those based on FMUv2.
* SIH for quadrotor supported from PX4 v1.9.
* SIH for fixed-wing (airplane) and tailsitter are supported in versions after PX v1.12 (currently in the master branch).

## Setting up SIH

Running the SIH is as easy as selecting an airframe. Plug the autopilot to the desktop computer with a USB cable, let it boot, then using a ground control station select [SIH Quadcopter X](https://px4.gitbook.io/px4-user-guide/airframes/airframe_reference#copter_simulation_sih_quadcopter_x), `SIH plane AERT`, or 'SIH Tailsitter Duo'. The autopilot will then reboot.

When the SIH airframe is selected, the module `sih` starts by itself, the vehicle should be displayed on the ground control station map.

:::warning The airplane needs to takeoff in manual mode at full throttle. Also, if the airplane hits the floor the state estimator might lose its fix. :::

## Setting up the Display

The simulated vehicle can be displayed in jMAVSim for the following PX4 versions:

* Quadrotor from PX4 v1.11.
* Fixed-wing from the PX4 master (or the release version after PX4 v1.12).

To display the simulated vehicle:

1. Close *QGroundControl* (if open).
2. Unplug and replug the hardware autopilot (allow a few seconds for it to boot).
3. Start jMAVSim by calling the script **jmavsim\_run.sh** from a terminal:

   ```
   ./Tools/simulation/jmavsim/jmavsim_run.sh -q -d /dev/ttyACM0 -b 2000000 -o
   ```

   where the flags are

   * `-q` to allow the communication to *QGroundControl* (optional).
   * `-d` to start the serial device `/dev/ttyACM0` on Linux. On macOS this would be `/dev/tty.usbmodem1`.
   * `-b` to set the serial baud rate to `2000000`.
   * `-o` to start jMAVSim in *display Only* mode (i.e. the physical engine is turned off and jMAVSim only displays the trajectory given by the SIH in real-time).
   * add a flag `-a` to display an aircraft or '-t' to display a tailsitter. If this flag is not present a quadrotor will be displayed by default.
4. After few seconds, *QGroundControl* can be opened again.

At this point, the system can be armed and flown. The vehicle can be observed moving in jMAVSim, and on the QGC *Fly* view.

## Credits

The SIH was originally developed by Coriolis g Corporation, then the airplane model and tailsitter models were added by Altitude R\&D inc. Both are Canadian companies, [Coriolis g](http://ww7.vogi-vtol.com) develops a new type of Vertical Takeoff and Landing (VTOL) vehicles based on passive coupling systems; [Altitude R\&D](https://www.altitude-rd.com/) is specialized in dynamics, control, and real-time simulation. They provide the SIH as a simple simulator for quadrotors and airplanes released for free under BSD license.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://px4.gitbook.io/px4-user-guide/development/simulation/simulation-in-hardware.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
