Create custom model for SITL

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>
2 Likes

Will you give the procedure in which the files should be changed in order to make a custom model? I have tried it myself by creating my_vehicle file under Tools/sitl_gazebo/models, created airframe file under ROMFS/px4fmu_common/init.d-posix and added airframe name under platforms/posix/cmake/sitl_target.cmake but after running the code went back to the standard iris copter.

This helps a lot and most importantly, it worked! Thanks :slight_smile:

1 Like

I am interested in making a model that in qgroundcontrol detects as a fixed-wing airplane. I don’t know if there is a pattern like iris in this case. I have tried plane but it detects it as a custom model.

I followed the instructions. Here is my issue:

INFO  [px4] Calling startup script: /bin/sh etc/init.d-posix/rcS 0
Error: Unknown model my_vehicle (not found by name on /home/user/Desktop/File/PX4-Autopilot/build/px4_sitl_default/tmp/rootfs/etc/init.d-posix/airframes)
ERROR [px4] Startup script returned with return value: 256

I am new to these things but i checked the

/home/user/Desktop/File/PX4-Autopilot/ROMFS/px4fmu_common/init.d-posix/airframes

I can find the file which is instructions saying “4229_my_vehicle”

Can you help me about it ? Or are there any instructions for adding custom model(Couldn’t find properly) ?

@Fatih_Ozkan You need to add it to the cmake lists: PX4-Autopilot/CMakeLists.txt at master · PX4/PX4-Autopilot · GitHub

3 Likes

It handled the issue but now my model is not showin up in gazebo.

Thanks for your concern

@Fatih_Ozkan Please share exactly what you are doing and how it is failing. Otherwise we can’t help you other than tell you you are doing something wrong

HI, i tried the steps mentioned here but when i run make px4_sitl gazebo_76motordrone, it gets stuck at using the sdf file as shown but displayed no errors, its just stuck. Pls help me, thank you! :slight_smile:

src_path: /home/xavierrocker/Desktop/PX4-Autopilot
build_path: /home/xavierrocker/Desktop/PX4-Autopilot/build/px4_sitl_default
GAZEBO_PLUGIN_PATH :/home/xavierrocker/Desktop/PX4-Autopilot/build/px4_sitl_default/build_gazebo
GAZEBO_MODEL_PATH :/home/xavierrocker/Desktop/PX4-Autopilot/Tools/sitl_gazebo/models
LD_LIBRARY_PATH :/home/xavierrocker/Desktop/PX4-Autopilot/build/px4_sitl_default/build_gazebo
empty world, default world 76motordrone.world for model found
Using: /home/xavierrocker/Desktop/PX4-Autopilot/Tools/sitl_gazebo/models/76motordrone/76motordrone.sdf

@Jaeyoung-Lim
Like @antonerasm said. I did:

  • I created a folder under Tools/sitl_gazebo/models for my model, named my_vehicle

  • I created 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)

  • I created a world file in Tools/sitl_gazebo/worlds called my_vehicle.world

  • I create my own airframe file in init.d-posix. Also i will use my own mixer.

  • I added the airframe name to the platforms/posix/cmake/sitl_target.cmake in the command set(models …)

  • And finaly i added name of it to PX4-Autopilot/ROMFS/px4fmu_common/init.d-posix/airframes/CMakeLists.txt

My issues

  1. Can not connect to QGroundControl
  2. Now my model is showing up but can’t control. Motors spinnin freely.

Regards.

I created a world file in Tools/sitl_gazebo/worlds called my_vehicle .world

You need to remove your world file

My issues

  1. Can not connect to QGroundControl
  2. Now my model is showing up but can’t control. Motors spinnin freely.

This means that your mavlink interface is not configured properly with your mixers. To do it in steps and provide less confusion, change your custom model / airframe configs into a copy paste of the iris model, make sure everything works and then add your custom changes on top.
Otherwise you will have multiple issues showing up at once for everything you did wrong along the way.

1 Like

same ques, have u solved that? if you have,would u plz tell me how?

Sorry for late message. Thank you. I did it step by step and it solved.

I solved but can’t remember exactly but like @Jaeyoung-Lim said:

  1. First check your mixer and airframe. Most importantly check mixer.
  2. Go step by step and if you are getting specific error. Committing here will be helpful.
  3. For me my sdf wasn’t good enough so be sure about your model’s sdf. Check difference with same models and be careful about PX4 version

Hi, followed the same process. The model loads up and everything looks fine, but the terminal window is stuck at

[Msg] Waiting for master.
[Msg] Connected to gazebo master @ http://127.0.0.1:11345
[Msg] Publicized address: IP Address

and loads up gazebo, but the terminal window doesn’t load any more text lines. I mean usually the [MSG] loads then lines come where we put commander takeoff. unable to get that with the custom mode, checked my mavlink interface and that looks normal.

sometimes get this error as well

[Wrn] [Publisher.cc:135] Queue limit reached for topic /gazebo/default/user_camera/pose, deleting message. This warning is printed only once.

HI, i tried:

  • I created a folder under Tools/sitl_gazebo/models for my model, named x4vtail_vtol3
  • I created the following files under Tools/sitl_gazebo/models/x4vtail_vtol3: model.config and x4vtail_vtol3.sdf (which is based off the standard_vtol models in Tools/sitl_gazebo/models)
  • I create my own airframe file in init.d-posix, named 1044_x4vtail_vtol3. Also i will use my own mixer, name x4vtail_vtol3_sitl.main.mix.
  • I added the airframe name to the platforms/posix/cmake/sitl_target.cmake in the command set(models …)
  • And i added name of it to ROMFS/px4fmu_common/mixers-sitl/CMakeLists.txt.
    *Then, i run
cd build
cmake .. 
make
cd ..

*When i run
make px4_sitl gazebo_x4vtail_vtol3
it gets stuck at INFO [simulator] Waiting for simulator to accept connection on TCP port 4560 and gazebo do not open, here is the result:

[0/1] Re-running CMake...
-- PX4 version: v1.12.1
-- PX4 config file: /home/x/PX4-Autopilot/boards/px4/sitl/default.cmake
-- PX4 config: px4_sitl_default
-- PX4 platform: posix
-- PX4 lockstep: enabled
-- cmake build type: RelWithDebInfo
-- Building for code coverage
-- ccache enabled (export CCACHE_DISABLE=1 to disable)
-- build type is RelWithDebInfo
-- PX4 ECL: Very lightweight Estimation & Control Library v1.9.0-rc1-591-gb3fed06
-- ROMFS: ROMFS/px4fmu_common
-- Configuring done
-- Generating done
-- Build files have been written to: /home/x/PX4-Autopilot/build/px4_sitl_default
[0/4] Performing build step for 'sitl_gazebo'
ninja: no work to do.
[3/4] cd /home/x/PX4-Autopilot/build/px4_sitl_default/t...-Autopilot /home/x/PX4-Autopilot/build/px4_sitl_default
SITL ARGS
sitl_bin: /home/x/PX4-Autopilot/build/px4_sitl_default/bin/px4
debugger: none
program: gazebo
model: x4vtail_vtol3
world: none
src_path: /home/x/PX4-Autopilot
build_path: /home/x/PX4-Autopilot/build/px4_sitl_default
GAZEBO_PLUGIN_PATH :/home/x/PX4-Autopilot/build/posix_sitl_default/build_gazebo:/home/x/PX4-Autopilot/build/posix_sitl_default/build_gazebo:/home/x/PX4-Autopilot/build/posix_sitl_default/build_gazebo:/home/x/PX4-Autopilot/build/px4_sitl_default/build_gazebo
GAZEBO_MODEL_PATH :/home/x/PX4-Autopilot/Tools/sitl_gazebo/models:/home/x/PX4-Autopilot/Tools/sitl_gazebo/models:/home/x/PX4-Autopilot/Tools/sitl_gazebo/models:/home/x/PX4-Autopilot/Tools/sitl_gazebo/models
LD_LIBRARY_PATH /home/x/catkin_ws/devel/lib:/opt/ros/melodic/lib:/home/x/PX4-Autopilot/build/posix_sitl_default/build_gazebo:/home/x/PX4-Autopilot/build/posix_sitl_default/build_gazebo:/home/x/PX4-Autopilot/build/posix_sitl_default/build_gazebo:/home/x/PX4-Autopilot/build/px4_sitl_default/build_gazebo
empty world, setting empty.world as default
Using: /home/x/PX4-Autopilot/Tools/sitl_gazebo/models/x4vtail_vtol3/x4vtail_vtol3.sdf
/home/x/PX4-Autopilot/Tools/sitl_run.sh: line 201: 30918 Segmentation fault      (core dumped) gzserver $verbose $world_path
SITL COMMAND: "/home/x/PX4-Autopilot/build/px4_sitl_default/bin/px4" "/home/x/PX4-Autopilot/build/px4_sitl_default"/etc -s etc/init.d-posix/rcS -t "/home/x/PX4-Autopilot"/test_data
INFO  [px4] Creating symlink /home/x/PX4-Autopilot/build/px4_sitl_default/etc -> /home/x/PX4-Autopilot/build/px4_sitl_default/tmp/rootfs/etc

______  __   __    ___ 
| ___ \ \ \ / /   /   |
| |_/ /  \ V /   / /| |
|  __/   /   \  / /_| |
| |     / /^\ \ \___  |
\_|     \/   \/     |_/

px4 starting.

INFO  [px4] Calling startup script: /bin/sh etc/init.d-posix/rcS 0
Info: found model autostart file as SYS_AUTOSTART=1044
INFO  [param] selected parameter default file eeprom/parameters_1044
[param] parameter file not found, creating eeprom/parameters_1044
  SYS_AUTOCONFIG: curr: 0 -> new: 1
  SYS_AUTOSTART: curr: 0 -> new: 1044
  CAL_ACC0_ID: curr: 0 -> new: 1310988
  CAL_GYRO0_ID: curr: 0 -> new: 1310988
  CAL_ACC1_ID: curr: 0 -> new: 1310996
  CAL_GYRO1_ID: curr: 0 -> new: 1310996
  CAL_ACC2_ID: curr: 0 -> new: 1311004
  CAL_GYRO2_ID: curr: 0 -> new: 1311004
  CAL_MAG0_ID: curr: 0 -> new: 197388
  CAL_MAG1_ID: curr: 0 -> new: 197644
  SENS_BOARD_X_OFF: curr: 0.0000 -> new: 0.0000
  SENS_DPRES_OFF: curr: 0.0000 -> new: 0.0010
Gazebo multi-robot simulator, version 9.19.0
Copyright (C) 2012 Open Source Robotics Foundation.
Released under the Apache 2 License.
http://gazebosim.org

[Msg] Waiting for master.
* SYS_AUTOCONFIG: curr: 1 -> new: 0
  IMU_INTEG_RATE: curr: 200 -> new: 250
INFO  [dataman] Unknown restart, data manager file './dataman' size is 11798680 bytes
PX4 SIM HOST: localhost
INFO  [simulator] Waiting for simulator to accept connection on TCP port 4560

I have no idea about it ,can you help me? Please and Thanks! :sob:

I once added this model in another computer through the above steps. At that time, it could be successfully added, and my plane could fly normally. But this time I followed the same steps and failed. I don’t know why.

1 Like

I have the same problem
if anyone could help, it would be appreciated.
to find the solution to this problem, I used the iris model but just changed the name to something else, and I got the following errors:
@Jaeyoung-Lim Jaeyoung-Lim

[0/4] Performing build step for 'sitl_gazebo'
ninja: no work to do.
[3/4] cd /home/aminys/PX4-Autopilot/bu...s/PX4-Autopilot/build/px4_sitl_default
SITL ARGS
sitl_bin: /home/aminys/PX4-Autopilot/build/px4_sitl_default/bin/px4
debugger: none
program: gazebo
model: HB_x500
world: none
src_path: /home/aminys/PX4-Autopilot
build_path: /home/aminys/PX4-Autopilot/build/px4_sitl_default
GAZEBO_PLUGIN_PATH :/home/aminys/PX4-Autopilot/build/px4_sitl_default/build_gazebo
GAZEBO_MODEL_PATH :/home/aminys/PX4-Autopilot/Tools/sitl_gazebo/models
LD_LIBRARY_PATH :/home/aminys/PX4-Autopilot/build/px4_sitl_default/build_gazebo
empty world, setting empty.world as default
Using: /home/aminys/PX4-Autopilot/Tools/sitl_gazebo/models/HB_x500/HB_x500.sdf
Warning [parser.cc:833] XML Attribute[version] in element[sdf] not defined in SDF, ignoring.
Error [Param.cc:329] Invalid boolean value
Error [Param.cc:329] Invalid boolean value
Error [Param.cc:449] Invalid argument. Unable to set value [{{ mavlink_udp_port }} ] for key[mavlink_udp_port].
Error [Param.cc:449] Invalid argument. Unable to set value [{{ mavlink_tcp_port }} ] for key[mavlink_tcp_port].
SITL COMMAND: "/home/aminys/PX4-Autopilot/build/px4_sitl_default/bin/px4" "/home/aminys/PX4-Autopilot/build/px4_sitl_default"/etc -s etc/init.d-posix/rcS -t "/home/aminys/PX4-Autopilot"/test_data
Creating symlink /home/aminys/PX4-Autopilot/build/px4_sitl_default/etc -> /home/aminys/PX4-Autopilot/build/px4_sitl_def

I have a question, if I change let’s say the box size in the sdf file, will the physical properties change like will it simulate according to real life conditions based on the measurements given