VOXL2 PX4 HITL
Table of contents
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
- FTDI Cable (USB to serial) connected to a 4-pin JST.
- Host computer that is capable of running gazebo (Ubuntu or MacOS)
- Voxl2
FTDI Cable Image
Hardware setup
- 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).
- 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:
git clone https://github.com/PX4/PX4-Autopilot --recursive
cd PX4-Autopilot
./Tools/setup/ubuntu.sh
- Using vim or nano, open the
PX4-Autopilot/Tools/simulation/gazebo-classic/sitl_gazebo-classic/models/iris_hitl/iris_hitl.sdf
and edit theserialDevice
to/dev/ttyUSB0
and save the file. DONT_RUN=1 make px4_sitl_default gazebo
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.
https://gitlab.com/voxl-public/voxl-sdk/services/voxl-px4
- 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.
- 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
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:
- 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:
- qshell commander arm
- qshell commander takeoff
- qshell commander disarm
- qshell commander mode posctl
Running a mission from QGroundControl (QGC)
- Open QGC on the parent computer running the simulation.
- Ensure that all AutoConnect options within the QGC settings are unchecked except for “UDP”.
- 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.
- Once connected, proceed to the top left corner of QGC, and select the Plan option within the Fly icon.
- 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.
- Navigate back to the original screen by selecting the Fly option in the top left of QGC, under the Plan icon.
- 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.
- Sit back and enjoy watching the mission be executed in the gazebo.