Hardware in the Loop Simulation (HITL)

Hardware-in-the-Loop (HITL or HIL) is a simulation mode in which normal PX4 firmware is run on real flight controller hardware. This approach has the benefit of testing most of the actual flight code on the real hardware.

PX4 supports HITL for multicopters (using jMAVSim or Gazebo) and VTOL (using Gazebo).

HITL-Compatible Airframes

The current set of compatible airframes vs Simulators is:

Airframe SYS_AUTOSTART Gazebo jMAVSim
HIL Quadcopter X 1001 Y Y
HIL Standard VTOL QuadPlane 1002 Y
Generic Quadrotor x copter 4001 Y Y
DJI Flame Wheel f450 4011 Y Y

HITL Simulation Environment

With Hardware-in-the-Loop (HITL) simulation the normal PX4 firmware is run on real hardware. JMAVSim or Gazebo (running on a development computer) are connected to the flight controller hardware via USB/UART. The simulator acts as gateway to share MAVLink data between PX4 and QGroundControl.

The simulator can also be connected via UDP if the flight controller has networking support and uses a stable, low-latency connection (e.g. a wired Ethernet connection - WiFi is usually not sufficiently reliable). 예를 들어, 컴퓨터와 이더넷으로 연결해 둔 라즈베리 파이와 PX4의 설정 시험을 이미 진행했습니다(jMAVSim 실행 명령이 들어간 시작 설정은 여기에 있습니다).

The diagram below shows the simulation environment:

  • A HITL configuration is selected (via QGroundControl) that doesn't start any real sensors.
  • jMAVSim or Gazebo are connected to the flight controller via USB.
  • The simulator is connected to QGroundControl via UDP and bridges its MAVLink messages to PX4.
  • Gazebo and jMAVSim can also connect to an offboard API and bridge MAVLink messages to PX4.
  • (Optional) A serial connection can be used to connect Joystick/Gamepad hardware via QGroundControl.

HITL Setup - jMAVSim and Gazebo

HITL vs SITL

SITL runs on a development computer in a simulated environment, and uses firmware specifically generated for that environment. Other than simulation drivers to provide fake environmental data from the simulator the system behaves normally.

By contrast, HITL runs normal PX4 firmware in "HITL mode", on normal hardware. The simulation data enters the system at a different point than for SITL. Core modules like commander and sensors have HITL modes at startup that bypass some of the normal functionality.

In summary, HITL runs PX4 on the actual hardware using standard firmware, but SITL actually executes more of the standard system code.

Setting up HITL

PX4 Configuration

  1. Connect the autopilot directly to QGroundControl via USB.
  2. Enable HITL Mode

    1. Open Setup > Safety section.
    2. Enable HITL mode by selecting Enabled from the HITL Enabled list:

      QGroundControl HITL 설정

  3. Select Airframe

    1. Open Setup > Airframes
    2. Select a compatible airframe you want to test. Then click Apply and Restart on top-right of the Airframe Setup page.

      Select Airframe

  4. Calibrate your RC or Joystick, if needed.

  5. Setup UDP

    1. Under the General tab of the settings menu, uncheck all AutoConnect boxes except for UDP.

      QGC Auto-connect settings for HITL

  6. (Optional) Configure Joystick and Failsafe. Set the following parameters in order to use a joystick instead of an RC remote control transmitter:

    • COM_RC_IN_MODE to "Joystick/No RC Checks". This allows joystick input and disables RC input checks.
    • NAV_RCL_ACT to "Disabled". This ensures that no RC failsafe actions interfere when not running HITL with a radio control.

      The QGroundControl User Guide also has instructions on Joystick and Virtual Joystick setup.

Once configuration is complete, close QGroundControl and disconnect the flight controller hardware from the computer.

Simulator-Specific Setup

Follow the appropriate setup steps for the specific simulator in the following sections.

Gazebo

Make sure QGroundControl is not running!

  1. Build PX4 with Gazebo (in order to to build the Gazebo plugins).

     sh
     cd <Firmware_clone>
     DONT_RUN=1 make px4_sitl_default gazebo
    
  2. Open the vehicle model's sdf file (e.g. Tools/sitl_gazebo/models/iris/iris.sdf).

  3. Under the mavlink_interface plugin section, change the serialEnabled and hil_mode parameters to true.

    HIL Parameters

    The file iris.sdf is autogenerated. Therefore you need to either keep a copy of your changed file or re-edit it for every build.

  4. Replace the serialDevice parameter (/dev/ttyACM0) if necessary.

    The serial device depends on what port is used to connect the vehicle to the computer (this is usually /dev/ttyACM0). An easy way to check on Ubuntu is to plug in the autopilot, open up a terminal, and type dmesg | grep "tty". The correct device will be the last one shown.

  5. Set up the environment variables:

     source Tools/setup_gazebo.bash $(pwd) $(pwd)/build/px4_sitl_default
    

    and run Gazebo in HITL mode:

     gazebo Tools/sitl_gazebo/worlds/iris.world
    
  6. QGroundControl 을 시작하십시오. It should autoconnect to PX4 and Gazebo.

jMAVSim (Quadrotor only)

QGroundControl을 실행하고 있지 않은지 확인하십시오!

  1. Connect the flight controller to the computer and wait for it to boot.
  2. Run jMAVSim in HITL mode:

     sh
     ./Tools/jmavsim_run.sh -q -s -d /dev/ttyACM0 -b 921600 -r 250 > 
    

    Note Replace the serial port name /dev/ttyACM0 as appropriate. On macOS this port would be /dev/tty.usbmodem1. On Windows (including Cygwin) it would be the COM1 or another port - check the connection in the Windows Device Manager.

  3. QGroundControl 을 시작하십시오. It should autoconnect to PX4 and jMAVSim.

Fly an Autonomous Mission in HITL

임무를 수행 하거나 기체를 조종하려면 QGroundControl을 활용할 수 있어야 합니다.

results matching ""

    No results matching ""