Simulating custom drone in ROS2 Gazebo with PX4

Dear all,

I want to add a camera to rc_cessna_model and simulate it with ROS2 Gazebo in PX4. I mentioned ROS2, so you can understand that I don’t work with Gazebo custom. Let me tell what I have done. Indeed I have replicated exactly what has been done to x500_mono_cam. Below are the steps and files:

  • Created rc_cessna mono_cam folder which is exact copy of rc_cessna folder inside Tools/simulation/gz/models directory. I have adjusted model.sdf file like below:
<?xml version="1.0" encoding="UTF-8"?>
<sdf version='1.9'>
  <model name='rc_cessna_mono_cam'>
    <include merge='true'>
      <uri>rc_cessna</uri>
    </include>
    <include merge='true'>
      <uri>model://mono_cam</uri>
      <pose>.12 .03 .242 0 0 0</pose>
    </include>
    <joint name="CameraJoint" type="fixed">
      <parent>base_link</parent>
      <child>mono_cam/base_link</child>
      <pose relative_to="base_link">.12 .03 .242 0 0 0</pose>
    </joint>
  </model>
</sdf>

And model.config like below:

<?xml version="1.0"?>
<model>
  <name>rc_cessna_mono_cam</name>
  <version>1.0</version>
  <sdf version='1.9'>model.sdf</sdf>

  <author>
   <name>Benjamin Perseghetti</name>
   <email>bperseghetti@rudislabs.com</email>
  </author>

  <description>
    This is a model of an RC Cessna 182 with simple monocular camera.
  </description>
</model>

  • Then inside ROMFS/px4fmu_common/init.d-posix/airframes directory I added 4012_gz_rc_cessna_mono_cam file with below content:
#!/bin/sh
#
# @name Gazebo rc_cessna_mono_cam
# @type Fixedwing
#

PX4_SIM_MODEL=${PX4_SIM_MODEL:=rc_cessna_mono_cam}

. ${R}etc/init.d-posix/airframes/4003_gz_rc_cessna

  • Finally, I have added 4012_gz_rc_cessna_mono_cam to ROMFS/px4fmu_common/init.d-posix/airframes/CMakeLists.txt file.

That’s all.

I have seen this answer also:

However, the structure of Px4 folders have been changed, and I think there is no need to do set(models rc_cessna_mono_cam) inside platforms/posix/cmake/sitl_target.cmake.

My problem is that, when I do

make make px4_sitl gz_rc_cessna_mono_cam

, it is written in terminal

[UserCommands.cc:1097] Error Code 1: Msg: Error finding file [rc_cessna_mono_cam/model.sdf].
[UserCommands.cc:1097] Error Code 1: Msg: Unable to read file: [rc_cessna_mono_cam/model.sdf]

I don’t know what is the problem. I would highly appreciate your help. Thank you for your time.

Hi @Burhan

It’s true that the the PX4 folder structure changed but the procedure is still valid:

  • Create new model in Tools/simulation/gz/models (pay attention to rename everything everywhere).
  • Create new airframe in ROMFS/px4fmu_common/init.d-posix/airframes and add it to the CMakeList.txt

I indeed encoutered your same issue though.
In my case it was due to Tools/simulation/gz being now a submodule → GitHub - PX4/PX4-gazebo-models: Model repo in app.gazebosim.org
After adding the new module as above I run make distclean and then make px4_sitl gz_rc_cessna2 (I called the new model rc_cessna2).
But make distclean clears all submodules and I ended up deleting my new rc_cessna2.

I suggest you to check for similar issues because as soon as I re-created the model and rebuild with

rm -rf build/
make px4_sitl gz_rc_cessna2

(first to force a full build without resetting the submodules)
I got it working.

You can also take a look at GitHub - PX4/PX4-gazebo-models: Model repo in app.gazebosim.org and the PX4 documentation: Gazebo Simulation | PX4 User Guide (main) and Gazebo Models Repository (PX4-gazebo-models) | PX4 User Guide (main).
The last link explain how you can define new models outside PX4.
It could be useful to you as I guess you don’t even need a new airframe, you just want the cessna with the camera.

Thank you very much. Indeed it worked the way you said.