top of page

Running Hardware-In-The-Loop (HITL) on ModalAI’s VOXL 2

Writer's picture: Michael PehelMichael Pehel

Hardware-In-The-Loop (HITL) simulation is a crucial technique in drone development, allowing developers to test their flight control systems in a virtual environment while using real hardware. Any solution, no matter how well constructed, can run into unforeseen issues when deployed on actual UAS. HITL testing will help you troubleshoot those problems and bring your projects closer to realization faster. This tutorial will guide you through the process of setting up and running HITL on Modal AI’s VOXL 2 platform, combining the power of PX4 firmware and Gazebo simulation.


The Stack

VOXL 2

The VOXL 2 is a sophisticated flight controller developed by ModalAI, designed to provide advanced capabilities for autonomous drone operations. Running HITL on the VOXL 2 requires a bit more software experience compared to traditional Flight Control Units (FCUs), but the benefits are substantial.

PX4

PX4 is an open source flight control software for drones that supports a wide range of vehicle configurations, including multicopters, fixed-wing, VTOLs and other form factors. The VOXL-2 is built to run PX4 firmware, so it’s optimized for PX4-based applications, but it can be used with other autopilot software. For today’s tutorial, we are sticking with PX4 and recommend you do so to follow along.

Gazebo

Gazebo is a powerful open source simulation environment with realistic physics modeling. It’s like a flight simulator, but it’s tuned for robotics development, making it a great choice for our HITL setup today.

Hardware Setup

To begin our HITL setup with the VOXL 2, we need to gather and connect the necessary hardware components. Here’s what you’ll need:

  1. VOXL 2 board

  2. Power supply (Wall plug to XT60/Adjustable Power Supply OR battery providing up to 4Cell)

  3. XT60 connector

  4. ModalAI Power Management Board + 4 PIN adapter for power

  5. USB to USB-C cable (OR USB-C to USB-C depending on what parent computer uses)

  6. FTDI cable

  7. 4 PIN JST to Pin OUT


A close up look at the FTDI Cable
A close up look at the FTDI Cable

The FTDI cable plays a crucial role in our setup. It essentially acts as a bridge between USB and raw header pins, allowing for serial communication. The four-pin (only leveraging three spaces) adapter we’ve created connects to the VOXL 2 and includes ground, TX (transmit), and RX (receive) pins. To make your own, you will have to do a little soldering, but it’s a small price to pay for HITL testing capabilities (Or users can use JST 4 Pin to raw PIN OUT to plug into the FTDI).

Pay close atention to the separation of the wires and where it connects to on the VOXL 2
Pay close atention to the separation of the wires and where it connects to on the VOXL 2

For further reference, you can check out the official ModalAI documentation and PX4 User Guide, but don’t worry, we’ll be covering everything you need to know to get started here.

The hardware setup process involves the following steps:

  1. Connect the XT60 to the ModalAI Power Adapter, which will provide power to the VOXL 2.

  2. Plug the USB to USB-C cable into the USB-C port of the VOXL 2 (USB other side connected to parent computer).

  3. Prepare the FTDI cable by soldering the four-pin adapter mentioned above and connect to the VOXL 2.

Software Configuration

With the hardware in place, we can now focus on configuring the software for our HITL simulation. We’ll be using two primary resources:

Configuring the FTDI Cable

The first step in our software setup is to configure the FTDI cable for optimal communication with the VOXL 2. Open up your terminal and use this command to set the appropriate parameters:

echo 1 | sudo tee /sys/bus/usb-serial/devices/ttyUSB0/latency_timer

This reduces the latency timer for the FTDI cable, ensuring faster data relay between the VOXL 2 and our simulation environment.

Setting Up the PX4 Environment

Next, we need to set up our PX4 environment. Navigate to your PX4 directory and source the necessary tools:

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

This command sets up the Gazebo simulation environment and ensures all the required paths are correctly configured.

Configuring the Simulation Model

An important detail to note is the configuration of the serial device in the simulation model. Open the file located at:

vim Tools/sitl_gazebo/models/iris/iris_hitl.sdf

Find the line specifying the serial device and ensure it reads:

<serialDevice>/dev/ttyUSB0</serialDevice>

This configuration is crucial because FTDI cables typically appear as /dev/ttyUSB0 in your environment. If this line originally says /dev/ttyACM0, make sure to change it to /dev/ttyUSB0.

Running the Simulation

With our hardware connected and software configured, we’re ready to launch our HITL simulation. Here’s how to get started:

  1. In your terminal, run the following command to start Gazebo:

    gazebo Tools/sitl_gazebo/worlds/iris.world

    This command will open up Gazebo with a simulated drone in the environment.

    The drone you see should reflect the hardware you have
    The drone you see should reflect the hardware you have
  2. Open a new terminal window and use ADB (Android Debug Bridge) to shell into your VOXL 2:

    adb shell

  3. Once connected to the VOXL 2, start PX4. This command launches PX4 on the VOXL 2, which will then connect to Gazebo via the serial link we set up earlier.

voxl-px4-hitl
PX4 Starting!
PX4 Starting!
  1. Allow about 30 seconds for PX4 to boot up and advertise all its topics. Once it’s ready, you’ll be able to interact with the drone through the PX4 shell.

Make sure all your topics are advertised before moving on
Make sure all your topics are advertised before moving on

Interacting with the Simulated Drone

Now that our HITL simulation is running, we can send commands to the drone and observe its behavior in the Gazebo environment. Here are a few examples:

  1. To start the motors:

commander arm

Imagine the motors are spinning in this image
Imagine the motors are spinning in this image
  1. To make the drone take off:

commander takeoff
We're flying (in sumulation)!
We're flying (in sumulation)!
  1. To land the drone:

commander land

The drone will perform a landing sequence and then disarm.

And back down again we go
And back down again we go

These commands demonstrate the basic functionality of our HITL setup. You can explore more complex missions, test different flight modes, and even simulate various environmental conditions to thoroughly validate your drone’s behavior.

Troubleshooting Connectivity

While running HITL simulations on the VOXL 2, you may encounter some common connection issues. This is hardware after all. If you’re having trouble establishing a connection between PX4 and Gazebo, double-check the following:

  1. Ensure the FTDI cable is properly connected and recognized by your system.

  2. Verify that the serial device in the simulation model is correctly set to /dev/ttyUSB0.

  3. Check that the baud rate settings match between PX4 and Gazebo.

If issues persist, try unplugging and reconnecting the FTDI cable, then restart both PX4 and Gazebo.

Troubleshooting Unexpected Simulation Behavior

If the drone in your simulation behaves unexpectedly, it could be due to misconfiguration or software issues. Try the following:

  1. Ensure you’re using the latest compatible versions of PX4 and Gazebo.

  2. Double-check your PX4 parameters, especially those related to flight control and simulation.

  3. Verify that the drone model in Gazebo matches your PX4 configuration (easy win).

Next Steps

Now that you have a grasp on the basics, you can do way more than make drone go up and make drone go down. You can conduct sensor fusion testing, computer vision integration, failure mode testing, and simulating environmental conditions. HITL offers you a path to testing rapidly without the costs of damaging hardware in the process, so take advantage of that and start trying to break your drone in simulation.

Conclusion

Hardware-In-The-Loop simulation on the ModalAI VOXL 2 platform offers a powerful way to test and validate drone systems in a safe, controlled environment. By combining the computational capabilities of the VOXL 2 with the flexibility of PX4 and the visual fidelity of Gazebo, you can now create highly realistic simulations that closely mirror real-world conditions with your hardware.

Remember that HITL is just one part of a comprehensive testing strategy. While it provides excellent insights into system behavior, it should be complemented with other testing methods, including Software-In-The-Loop simulations and real-world flight tests, to ensure the highest level of reliability and safety in your drone applications.

Enough talk, time for you to get on to testing with your brand new HITL setup.

164 views0 comments

Comments


bottom of page