Create custom model for SITL

Hello,

I am trying to modify iris model to simulate a bigger drone.
For that I started with iris.sdf file and replaced mass value of base_link to 18. I also replaced for each one of the rotors:
maxRotVelocity 7435.52
motorConstant 0.000252428
momentConstant 0.0955
rotorDragCoefficient 0.0000315
The numbers are calculated with the formulas from this thread: https://github.com/PX4/sitl_gazebo/issues/110

I created an ekf2 file (copying everything from the iris) and modified mavros_posix_sitl.launch to point to my model. It loads but behaviour of the drone is bad.
First of all, it is spawned underground. I was able to solve this changing mass to 10. I don’t know what does the mass has to do with drone position, but it does.
With that changed, I can command with QGroundControl a take off, but it is very unstable, and falls to the ground after a few seconds.

What am I doing wrong? This is not very well documented so it’s hard to debug.
Is there any bigger drone model available? Something between 15-20 kg?

Hi @danividanivi, Have you been able to do SITL for your custom drone in Gazebo?
I am trying to do the same by facing weird issues as well.

1 Like

I don’t remember the details, but starting with a small model and tunning the parameters one by one I was able to perform the simulations.
There was not really good documentation, so it was a trial-error proccess, with some parameters modification leading to the weird issues described.

Hi @danividanivi, I have successfully created a custom model for SITL.

The steps I took for creating a custom Gazebo model and PX4 SITL airframe with the adjusted gains:

  1. Create a folder under Tools/sitl_gazebo/models for your model, let’s call it my_vehicle
  2. Create the following files under Tools/sitl_gazebo/models/my_vehicle: model.config and my_vehicle.sdf (these can be based off the iris or solo models in Tools/sitl_gazebo/models)
  3. Create a world file in Tools/sitl_gazebo/worlds called my_vehicle.world (Again, this can be based off the iris or solo world files)
  4. Create an airframe file under ROMFS/px4fmu_common/init.d-posix (Yet again, this can be based off the iris or solo airframe files), give it a number (for example 4229) and name it 4229_my_vehicle
  5. Add the airframe name (my_vehicle) to the file platforms/posix/cmake/sitl_target.cmake in the command set(models …

Now you are free to tweak any of the model values in the SDF file and any of the controller gains in the airframe file.
You can launch SITL with your model with “make px4_sitl gazebo_my_vehicle”

A couple of things to keep in mind:

  1. When increasing the mass of the vehicle, also increase the inertias. I found that Gazebo does not like really small inertias.
  2. With the larger vehicle, tweak the motor values (but you have done this already)
  3. If the quad is unstable, it is probably due to bad controller gains. Tweak them for the larger vehicle.

The make px4_sitl gazebo_my_vehicle command is running the default iris quad.
What are the basic things that can be modified to see it in the simulation to know if it is working or not?

In the steps I gave, I suggested to base the new files of the iris or solo files.
The parameters, such as the vehicle mass, inertias, motor models, controller gains etc. can be changed in the new files to simulate a different vehicle.
But one won’t necessarily be able to physically see a difference in the simulation.

The easiest way, I would say, to see a physical difference is to use another 3D model for the vehicle.
So, for instance, in the following section of the solo.sdf file:

  <visual name='base_link_inertia_visual'>
    <pose>0 0 0 0 0 0</pose>
    <geometry>
      <mesh>
        <scale>1 1 1</scale>
        <uri>model://solo/meshes/solo.stl</uri>
      </mesh>
    </geometry>
    <material>
      <script>
        <name>Gazebo/DarkGrey</name>
        <uri>file://media/materials/scripts/gazebo.material</uri>
      </script>
    </material>
  </visual>

The file model://solo/meshes/solo.stl can be replaced with another stl file, which will be the visual vehicle during SITL.
Instead of replacing it with another 3D model, a naive way would be to replace it with a box just to see if everything is working.
So replacing the part with:

    <geometry>
      <box>
        <size>0.32 0.32 0.18</size>
      </box>
    </geometry>