ZilantRobotics / innopolis_vtol_dynamics

Cyphal/DroneCAN UAV HITL simulator
GNU General Public License v3.0
41 stars 8 forks source link
cyphal drone dronecan hitl robotics ros simulation uav uavcan

UAV HITL Simulator catkin_build

UAV HITL Simulator brings up a set of ROS packages, config files and instructions to establish a full simulation for UAV based on PX4/Ardupilot autopilot.

drawing

The key feature of this simulation is to run it in such a way that the hardware knows nothing about the simulation. This can be done with Cyphal/DroneCAN. It covers more PX4 modules than standard SITL and HITL.

Purpose

Minimal requirements (for HITL only):

Recommended requirements (for HITL + 3D simulator):

Required hardware:

1. USE CASES

By centralizing communication through CAN and leveraging the HITL simulator, you can perform a wide range of tests that were previously complex or impractical. Let's consider them.

1.1. CI/CD Unit

The HITL simulator itself is not computationally expensive. You can run it even on single-board computers like the Raspberry Pi. This feature allows the HITL simulator to be used as part of CI/CD process. Each time a developer makes a commit to the autopilot software, a the compiled binary can be deployed to a real flight controller and tested with HITL simulator. It is especially useful for developers actively working with DroneCAN/Cyphal drivers or related parts of the autopilot software.

drawing

A few examples of test scenarios for CI/CD are shown in the table below.

Test Description
1. Takeoff And Land This is the simplest possible test scenario: take off, wait a few seconds, and land. It is the fastest scenario and it is intended to be triggered on every commit as part of CI.
Approximate duration: 30 sec
Plan: tests/ci/takeoff_and_land.plan
2. Square flight Simple quadcopter flight test.
Approximate duration: 1 minute
Plan: tests/ci/square.plan
3. VTOL Long flight This is the longest test scenario. It is dedicated for testing the stability.
Approximate duration: 10 minutes
Plan: tests/ci/sviyazhsk_vtol.plan

Any of these scenarios can be run with 3 steps.

# 1. Upload the new firmware to the autopilot
autopilot-configurator --firmware <path_to_the_binary.px4>

# 2. Run the simulator itself with the desired protocol and airframe.
./scripts/sim.py cq

# 3. Run the test scenario. The default test scenario execution timeout is 5 minutes. For long flights you need to explicitly increase the timeout:
test-scenario --output flight.ulg --timeout 1000 tests/ci/sviyazhsk_vtol.plan

1.2. HITL Simulator with desktop computer and 3D-simulator

Running the HITL simulator on a desktop unlocks advanced visualization and simulation capabilities. With tools like gui_tool, yakut, and rviz, you can monitor and interact with the simulation in real-time. If your desktop is equipped with a modern GPU, you can further enhance the experience by integrating a 3D simulator. This setup is ideal for testing complex scenarios such as delivery missions or inspections and can even be used for pilot training, offering a realistic and immersive simulation environment.

The setup is as simple as possible. Just connect a CAN-sniffer and a flight controller to you Desktop via USB and connect the devices with each outher with CAN cable.

drawing

Tool 1. CAN bus analysis tools: gui_tool, yakut

If you run a HITL simulator, you can then run both yakut, gui_tool and any other similar tools at any time. It allows you analyse the CAN bus in real time.

DroneCAN: gui_tool Cyphal: yakut
drawing drawing

Tool 2. RVIZ for a flight visualization

With RVIZ you can visualise the vehicle orientation, vectors of the applied forces, torques, speed and more.

drawing

Tool 3. 3D-simulator

3D-simulator demo is in process...

Test scenarios

Test scenario Description
drawing Delivery or Last Mile Aerologistics Scenarios. Testing and optimization of cargo delivery processes using unmanned aerial vehicles.
1. Delivery from KazanExpress to the Yard. 4 minutes. Plan: kazanexpress_to_yard.plan
2. Delivery from KazanExpress to the Technopark. 6 minutes. Plan: kazanexpress_to_technopark.plan
drawing Construction Inspection.
1. Quadcopter. 3:40. Plan: technopark.plan
2. VTOL. Structure scan of the northest techonopark. 9:25. Plan: technopark_structure_scan.plan
3. VTOL. Survey of all technoparks in the town. 28:00. technopark_survey_half_town.plan
3. VTOL. Survey of all the town. 44:40. technopark_survey_full_town.plan
drawing Fault scenarios.
Evaluation of the behavior and response of UAV to various types of failures during flight.
1. Using /uav/scenario ROS topic run or stop a specific event, for example disable differential pressure sensor (as shown on the example), gnss, ESC feedback or turn off ICE. Please, check scenarios.hpp for details
2. In Cyphal you can disable/enable any port in real time

Key points in 3D simulation

Yard Delivery point Technopark office parking Buildings
drawing drawing drawing drawing

1.3. Testing with Real UAV Components

Connect the HITL simulator to a particular component of a vehicle or almost to the whole system.

An example of connection to the whole system is show below.

drawing

2. USAGE

The simulator is distributed as a Docker image. To simplify the interraction with Docker, a ./scripts/sim.py script was written. The script configures all the necessary Docker flags, performs automatic firmware upload, configuration, creates a CAN interface, and generally provides a simple interface to interact with the simulator.

Step 1. Clone repository with submodules

git clone https://github.com/ZilantRobotics/innopolis_vtol_dynamics.git --recursive

Whenever you pull this repository, don't forget to update submodules:

git submodule update --init --recursive

Step 2. Build/pull the docker image

To build docker image, type:

./scripts/sim.py b # build

An image on dockerhub usually is not up to date, so it's better to build manually

Step 3. Connect everything together for HITL

You should skip this step if you want to run PX4 MAVLink SITL mode. Please follow docs/px4/mavlink for details.

Typically we use CUAV v5+ and RL-programmer-sniffer, but it might be anything else.

An example of a connection is shown in the picture below.

drawing

All default parameters expect that you use CAN1 on the autopilot side.

Step 4. Run the container in force mode

In --force mode the script automatically upload the required firmware and parameters corresponded to the specified mode, create SLCAN and run the container with required docker flags.

To run force mode you need to install autopilot-tools python package: pip install autopilot-tools.

To get the list of all supported modes, just type:

./scripts/sim.py --help

To run PX4 Cyphal quadcopter, type:

./scripts/sim.py cq  # cq = px4_v1_15_0_cyphal_quadcopter

To run PX4 Dronecan VTOL, type:

./scripts/sim.py dv  # cq = dronecan_vtol

Troubleshooting:

If something doesn't work, please open an issue.

Step 5. Run ground control station

Here 2 options are suggested.

  1. You can run QGroundControl or MissionPlanner to have manual flight
  2. (soon) You can run a script to run one of the test scenario in automatic mode.

Step 6. (optional) 3D Simulator

A new 3D simulator will appear here soon.

3. SUPPORTED MODES

You can obrain the actual list of the suported modes by typing ./scripts/sim.py --help.

Well, here is the output of the command:

Primary supported modes (with aliases):
  px4_v1_15_0_cyphal_quadcopter,cq       | Cyphal     PX4 v1.15-beta  Quadrotor x (4001)
  px4_v1_15_0_cyphal_quadplane_vtol,csv  | Cyphal     PX4 v1.15-beta  Standard VTOL (13000)
  px4_v1_15_0_dronecan_quadrotor,dq      | DroneCAN   PX4 v1.15-beta  Quadrotor (4001)
  px4_v1_15_0_dronecan_quadplane_vtol,dv | DroneCAN   PX4 v1.15-beta  Standard VTOL (13000)
  px4_v1_13_0_dronecan_vtol,dv1130       | DroneCAN   PX4 v1.13.0     vtol 13070

Other modes:
  px4_v1_12_0_mavlink_quadplane_vtol    | MAVLink     PX4 v1.12       vtol 13070
  px4_v1_12_0_mavlink_quadcopter        | MAVLink     PX4 v1.12       Quadrotor (4001)
  cyphal_and_dronecan                   | 2 CAN       AP  v4.4.0      Copter
  px4_v1_15_0_cyphal_octorotor,co       | Cyphal      PX4 v1.15-beta  Octorotor Coaxial (12001)

New modes will be extended step by step.

4. DESIGN

VTOL HITL Dynamics Simulator is designed to be modular. It is divided into the following main components:

  1. UAV dynamics is the main node that handles actuator commands from the communicator, performs dynamics simulation, and publishes vehicle and sensors states.
  2. Communicator is the set of nodes that communicate with the PX4 flight stack in HITL (via Cyphal/DroneCAN) and SITL (via MAVLink) modes.
  3. inno_sim_interface is a bridge for interaction with 3D-Simulator through ROS.

The design of the simulator is shown below.

drawing

5. EXAMPLE

Check the video below.

Cyphal/DroneCAN HITL VTOL dynamics simulator

6. REFERENCE

Docs:

Outdated manual instructions:

7. CHANGELOG NOTES

Version ReleaseDate Major changes
v0.9.0 Nov .., 2024 Add fmu-v6c and fmu-v6x support beside fmu-v5
v0.8.0 Jun 10, 2024 Update PX4 from v1.14 to v1.15
v0.7.0 Oct 31, 2023 Update PX4 from v1.13 to v1.14
v0.6.0 Jul 16, 2023 Add Octorotor dynamics, fault scenarios and Cyphal ESC feedback
v0.5.0 May 17, 2023 Add Cyphal PX4 v1.13.0 quadcopter, update DroneCAN PX4 from v1.12.1 to v1.13.0
v0.4.0 May 16, 2022 Add Cyphal/DroneCAN custom version of Ardupilot
v0.3.0 Aug 25, 2021 Add Docker
v0.2.0 Aug 17, 2021 Update to public DroneCAN PX4 v1.12.1
v0.1.0 Mar 18, 2021 First public release for private custom version of DroneCAN PX4 v1.11.2, only CUAV V5+, SITL and HITL modes