Skip to main content

Adding drone model to Gazebo simulation

Follow the official CTU-MRS guide for the full step-by-step process: Adding a custom drone to the simulation

Tips & tricks​

Model files & meshes​

Keep the model as simple as possible. Meshes exported straight from CAD are usually far more detailed than the simulation needs, and the extra triangles just increase rendering demand — the visual/collision geometry only has to look right, not be manufacturing-accurate.

Run the mesh through a decimation process before importing it (e.g. Blender's Decimate modifier or meshlab) to cut the triangle count down while keeping the overall shape recognizable.

PX4 airframe​

The .main.mix mixer files described in the official guide are legacy — the ros2 branch of the CTU-MRS repos already correctly uses the more modern PX4 Control Allocation system instead. Instead of an airframe file that just points at a .main.mix file:

# airframes/4001_my_drone
#!/bin/sh
. ${R}etc/init.d/rc.mc_defaults
set MIXER quadrotor_x

rotor geometry and spin direction are defined directly in the airframe file via CA_ROTORx_PX/PY/PZ/CT/KM params, and there is no separate ROMFS/px4fmu_common/mixers/*.main.mix file:

#!/bin/sh
. ${R}etc/init.d/rc.mc_defaults

PX4_SIMULATOR=${PX4_SIMULATOR:=gz}
param set-default SIM_GZ_EN 1
param set-default MAV_TYPE 13 # hexarotor
param set-default CA_AIRFRAME 0
param set-default CA_ROTOR_COUNT 6

param set-default CA_ROTOR0_PX 0
param set-default CA_ROTOR0_PY 0.462
param set-default CA_ROTOR0_PZ -0.0115
param set-default CA_ROTOR0_CT 1.0
param set-default CA_ROTOR0_KM -0.06
# ... CA_ROTOR1..5 the same way

param set-default SIM_GZ_EC_FUNC1 101 # map rotor to a Gazebo ESC output
# ...
param set-default SIM_GZ_EC_MIN1 0 # use the full 0-1000 range
param set-default SIM_GZ_EC_MAX1 1000 # for the best signal resolution

param set-default BAT1_N_CELLS 6
param set-default BAT1_CAPACITY 16000
param set-default MPC_THR_HOVER 0.57

The CA_ROTORx_PX/PY/PZ positions and CA_ROTORx_KM spin direction sign must match the motor geometry defined in the model's sdf.jinja — if they don't, the thrust allocation won't line up with the visual/physical model. SIM_GZ_EC_FUNCx/MIN/MAX additionally map each rotor to a Gazebo ESC output channel, which the legacy mixer approach didn't need to handle explicitly.