Link Search Menu Expand Document

VOXL2 PX4 HITL

Table of contents

  1. Introduction
    1. HITL
    2. Gazebo Setup
      1. Hardware requirements
      2. FTDI Cable Image
      3. Hardware setup
      4. Gazebo simulator setup on host computer:
      5. Software setup on VOXL2
      6. Running the simulation and PX4 in GPS/VIO mode
        1. On host computer
        2. On Voxl2
      7. Running a mission from QGroundControl (QGC)

Introduction

In order to test the VOXL2’s PX4 instance - the user has the option of running HITL (Hardware in the Loop) simulation.

HITL

The VOXL2 is connected to a host computer via a serial link. The host computer is running the simulation where simulated sensor readings are sent to PX4 and actuator responses (essentially, ESC commands) are sent back to the simulation.

VOXL2 supports the Gazebo simulator. The simulation only supports both GPS and VIO flight.

Gazebo Setup

Note: The following requires a knowledge of how to run software in terminal/bash.

Hardware requirements

  1. FTDI Cable (USB to serial) connected to a 4-pin JST.
  2. Host computer that is capable of running gazebo (Ubuntu or MacOS)
  3. Voxl2

FTDI Cable Image

m0052-FTDI-cable

Hardware setup

  1. Connect the FTDI USB side to your host computer and the JST connector to the VOXL2 J18 port (https://docs.modalai.com/voxl2-connectors/#j18-uart-esc).
  2. Open terminal window on parent computer and enter the following: echo 1 | sudo tee /sys/bus/usb-serial/devices/ttyUSB0/latency_timer - This will decrease the default latency associated with FTDI cables in order to meet the timing requirements of the simulation.

Note: This setting will revert back to it’s default when the host computer is restarted so this step will need to be completed after each restart. If wanted, place this in the ~/.bashrc or ~/.zsh file.

Gazebo simulator setup on host computer:

In order to get gazebo running on the host machine, run the following:

  1. git clone https://github.com/PX4/PX4-Autopilot --recursive
  2. cd PX4-Autopilot
  3. ./Tools/setup/ubuntu.sh
  4. Using vim or nano, open the PX4-Autopilot/Tools/simulation/gazebo-classic/sitl_gazebo-classic/models/iris_hitl/iris_hitl.sdf and edit the serialDevice to /dev/ttyUSB0 and save the file.
  5. DONT_RUN=1 make px4_sitl_default gazebo
  6. source Tools/simulation/gazebo-classic/setup_gazebo.bash $(pwd) $(pwd)/build/px4_sitl_default

Note: This is to run GPS Iris model - if you wish to run VIO - swap the iris_hitl model in the hitl_iris world, with the iris_vision model.

Software setup on VOXL2

NOTE: If you are using a Voxl2 running the most recent build of PX4, the following steps do NOT need to be done.

  1. https://gitlab.com/voxl-public/voxl-sdk/services/voxl-px4
  2. Follow the instructions in the repository README above on gitlab to build px4 on a linux distro and push/download on a voxl2

Running the simulation and PX4 in GPS/VIO mode

On host computer

NOTE: If the user wishes to use QGC with gazebo - this must be opened AFTER gazebo has been spun up.

  1. If the user wishes to use a specific GPS location, run the following in ones terminal (where XYZ represents the GPS coord): a. export PX4_HOME_LAT=XYZ
    b. export PX4_HOME_LON=XYZ
    c. export PX4_HOME_ALT=XYZ
  2. gazebo Tools/simulation/gazebo-classic/sitl_gazebo-classic/worlds/hitl_iris.world

On Voxl2

NOTE: The following commands are done on the voxl2 shell via adb or ssh.

In an terminal instance, run:

  1. voxl-px4-hitl

This will boot up px4 to run in HITL and as long as the ftdi cable connection is connected to J8 on the voxl2, mavlink packets are being sent to and from. If the user wishes to run some commands from px4-shell, you can run things such as:

  1. qshell commander arm
  2. qshell commander takeoff
  3. qshell commander disarm
  4. qshell commander mode posctl

Running a mission from QGroundControl (QGC)

  1. Open QGC on the parent computer running the simulation.
  2. Ensure that all AutoConnect options within the QGC settings are unchecked except for “UDP”.
  3. Restart QGC and upon these setting changes, the VOXL2 instance of PX4 will auto connect to QGC - Note: QGC will ALWAYS need to be opened after gazebo - this is so there are no port conflicts.

qgc-autoconnect

  1. Once connected, proceed to the top left corner of QGC, and select the Plan option within the Fly icon.
  2. The user can now input a mission with an initial takeoff point, waypoints, and other options. Once satisfied with the mission, proceed to select upload option. This will push the mission to the VOXL2.

qgc-mission-upload

  1. Navigate back to the original screen by selecting the Fly option in the top left of QGC, under the Plan icon.
  2. Now that the mission has been uploaded, the user can select to takeoff and execute the mission by sliding the icon on the bottom of QGC to confirm/execute said mission.
  3. Sit back and enjoy watching the mission be executed in the gazebo.

Next: VOXL 2 PX4 Build Guide