Custom UAV Model to SITL

Hello everyone,
I’ve been developing a custom UAV Model for proprietary purposes and want to run SITL of it on PX4. I’ve built the required SDF file with links, joints, collisions, visuals, plugins for all sensors, and mavlink interface. I have a few questions related to the above.

  1. what Is <input_index> in the mavlnk_interfface plugin, and how to map it w.r.t to pixhawk?
  2. I’ve built custom airframe and mixer files and added them to the required CMake files. I’m able to load the model individually over the gazebo but unable to load it via the make px4_sitl gazebo_model command; only an empty world occurs [I’m not running it via RTPS, just running it via default sim]. I’ve rechecked all TOML, Mixer and Aierframe files and the 3D files. What could be the issue here??
  3. Parameter EFK2_HGT_MODE not found. I have given that the primary height data to be the barometer, but still I get this error. How do I resolve it??
2 Likes

Hi @REGATTE, I am currently in the same situation, I am afraid that the information and the support is very limited to make a new model, I have seen some posts from years ago that did not received any answer.
For point 2 I may be able to help letting you know that you should also add the name of your model in the file:
PX4-Autopilot/platforms/posix/cmake/sitl_target.cmake
About input index in mavlink plugin I have the same doubt, please let me know if you find out.

@REGATTE

  1. what Is <input_index> in the mavlnk_interfface plugin, and how to map it w.r.t to pixhawk?

These are the output channels of the actuator outputs. The index is the same as you set the order of mixing outputs with the mixer system: Mixing and Actuators | PX4 User Guide

  1. I’ve built custom airframe and mixer files and added them to the required CMake files. I’m able to load the model individually over the gazebo but unable to load it via the make px4_sitl gazebo_model command; only an empty world occurs [I’m not running it via RTPS, just running it via default sim]. I’ve rechecked all TOML, Mixer and Aierframe files and the 3D files. What could be the issue here??

Your model needs to follow a specific convention(sitl_gazebo/models/model_name/model_name.sdf) on the path as this is how the make target is searching for sdf files: PX4-Autopilot/sitl_target.cmake at be9385ef06f6d93de2957fa3f2513e60622f6ff0 · PX4/PX4-Autopilot · GitHub

  1. Parameter EFK2_HGT_MODE not found. I have given that the primary height data to be the barometer, but still I get this error. How do I resolve it??

Are you sure that parameter exists? Shouldn’t it be EKF2_HGT_MODE ?

@Jaeyoung-Lim

  1. Thanks for the update on the <input_index>. How do I implement aux connections here after the main?? Do i just right motor index = 8, for aux connections [starting count of main from 0] or is there any specific way to implement it. I have 15 motors to implement into the SITL and working with Pixhawk5X so have 16 connections availbale.

  2. I understand the nomenclature and was successful with building custom quad’s for SITL previously, but unable to do it for the present model [mav_type=22, sort of an standard vtol with octa-coax setup]. Made sure the mixer and toml file are exact to spec in ratio’s. Followed steps on how to add custom models. I’m able to launch gazebo and get the empty world, but unable to load the model. Checked the location of the model:/…/meshes/<>.stl files. Everything is placed in the correct place. SDF version is at 1.7. I’d be happy to share the error on a private chat.

  3. Sorry for the typo. It is EKF2_HGT_MODE.

1 Like
  1. Thanks for the update on the <input_index>. How do I implement aux connections here after the main?? Do i just right motor index = 8, for aux connections [starting count of main from 0] or is there any specific way to implement it. I have 15 motors to implement into the SITL and working with Pixhawk5X so have 16 connections availbale.

You can use the typhoon_h480 as an example on how to configure the aux channel (or payloads)

Followed steps on how to add custom models. I’m able to launch gazebo and get the empty world, but unable to load the model.

This means that it is not able to find the sdf file. You can do VERBOSE_SIM=1 to get more simulation debug outputs

I’d be happy to share the error on a private chat.

Please share them in this thread, so that other people can benefit from the discussion

Sorry for the typo. It is EKF2_HGT_MODE.

I would check if the parameter actually exists on your firmware

2 Likes

@Jaeyoung-Lim

I fixed the input_index and added airframe.post file for inclusion of aux file.

But I’m unable to get rid of error 3. This is my view.

I would check if the parameter actually exists on your firmware

this is my param in airframe file

param set-default EKF2_HGT_MODE 0     # 0 - barometer

this is the error on terminal

~/Desktop/PX4-Autopilot$ VERBOSE_SIM=1 make px4_sitl gazebo_mobility_2
[0/4] Performing build step for 'sitl_gazebo'
ninja: no work to do.
[3/4] cd /home/ashok/Desktop/PX4-Autopilot/build/px4_sitl_default/...Autopilot /home/ashok/Desktop/PX4-Autopilot/build/px4_sitl_default
SITL ARGS
sitl_bin: /home/ashok/Desktop/PX4-Autopilot/build/px4_sitl_default/bin/px4
debugger: none
program: gazebo
model: mobility_2
world: none
src_path: /home/ashok/Desktop/PX4-Autopilot
build_path: /home/ashok/Desktop/PX4-Autopilot/build/px4_sitl_default
GAZEBO_PLUGIN_PATH :/home/ashok/Desktop/PX4-Autopilot/build/px4_sitl_default/build_gazebo
GAZEBO_MODEL_PATH :/home/ashok/Desktop/PX4-Autopilot/Tools/sitl_gazebo/models
LD_LIBRARY_PATH /home/ashok/px4_ros_com_ros2/install/ros2_aruco_interfaces/lib:/home/ashok/px4_ros_com_ros2/install/px4_ros_com/lib:/home/ashok/px4_ros_com_ros2/install/px4_msgs/lib:/home/ashok/px4_ros_com_ros2/install/custom_messages/lib:/usr/lib/x86_64-linux-gnu/gazebo-11/plugins:/opt/ros/foxy/opt/yaml_cpp_vendor/lib:/opt/ros/foxy/opt/rviz_ogre_vendor/lib:/opt/ros/foxy/lib/x86_64-linux-gnu:/opt/ros/foxy/lib:/home/ashok/Desktop/PX4-Autopilot/build/px4_sitl_default/build_gazebo
empty world, setting empty.world as default
Using: /home/ashok/Desktop/PX4-Autopilot/Tools/sitl_gazebo/models/mobility_2/mobility_2.sdf
Gazebo multi-robot simulator, version 11.10.2
Copyright (C) 2012 Open Source Robotics Foundation.
Released under the Apache 2 License.
http://gazebosim.org

gzserver not ready yet, trying again!
[Msg] Waiting for master.
[Msg] Connected to gazebo master @ http://127.0.0.1:11345
[Msg] Publicized address: 192.168.121.128
[Msg] Loading world file [/home/ashok/Desktop/PX4-Autopilot/Tools/sitl_gazebo/worlds/empty.world]
[Wrn] [gazebo_airspeed_plugin.cpp:86] [gazebo_airspeed_plugin]: mobility_2::airspeed using airspeed topic "airspeed"
[Wrn] [gazebo_gps_plugin.cpp:78] [gazebo_gps_plugin]: mobility_2::gps0 using gps topic "gps0"
[Wrn] [gazebo_gps_plugin.cpp:203] [gazebo_gps_plugin] Using default update rate of 5hz 
[Wrn] [gazebo_gps_plugin.cpp:78] [gazebo_gps_plugin]: mobility_2::gps1 using gps topic "gps1"
[Wrn] [gazebo_gps_plugin.cpp:203] [gazebo_gps_plugin] Using default update rate of 5hz 
SITL COMMAND: "/home/ashok/Desktop/PX4-Autopilot/build/px4_sitl_default/bin/px4" "/home/ashok/Desktop/PX4-Autopilot/build/px4_sitl_default"/etc -s etc/init.d-posix/rcS -t "/home/ashok/Desktop/PX4-Autopilot"/test_data
Creating symlink /home/ashok/Desktop/PX4-Autopilot/build/px4_sitl_default/etc -> /home/ashok/Desktop/PX4-Autopilot/buil

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

px4 starting.

INFO  [px4] Calling startup script: /bin/sh etc/init.d-posix/rcS 0
INFO  [init] found model autostart file as SYS_AUTOSTART=1002
INFO  [param] selected parameter default file eeprom/parameters_1002
INFO  [parameters] BSON document size 291 bytes, decoded 291 bytes (INT32:12, FLOAT:3)
[param] Loaded: eeprom/parameters_1002
ERROR [param] Parameter EFK2_HGT_MODE not found.
ERROR [px4] Startup script returned with return value: 65280

I did add the required baro, magnetometer & ground-truth plugins in the sdf file and even they don’t seem to show up in the verbose output.

1 Like

Update
I had commented out all EKF param’s, now I get this error

make px4_sitl gazebo_mobility_2
[0/4] Performing build step for 'sitl_gazebo'
ninja: no work to do.
[3/4] cd /home/ashok/Desktop/PX4-Autopilot/build/px4_sitl_default/...Autopilot /home/ashok/Desktop/PX4-Autopilot/build/px4_sitl_default
SITL ARGS
sitl_bin: /home/ashok/Desktop/PX4-Autopilot/build/px4_sitl_default/bin/px4
debugger: none
program: gazebo
model: mobility_2
world: none
src_path: /home/ashok/Desktop/PX4-Autopilot
build_path: /home/ashok/Desktop/PX4-Autopilot/build/px4_sitl_default
GAZEBO_PLUGIN_PATH :/home/ashok/Desktop/PX4-Autopilot/build/px4_sitl_default/build_gazebo
GAZEBO_MODEL_PATH :/home/ashok/Desktop/PX4-Autopilot/Tools/sitl_gazebo/models
LD_LIBRARY_PATH /home/ashok/px4_ros_com_ros2/install/ros2_aruco_interfaces/lib:/home/ashok/px4_ros_com_ros2/install/px4_ros_com/lib:/home/ashok/px4_ros_com_ros2/install/px4_msgs/lib:/home/ashok/px4_ros_com_ros2/install/custom_messages/lib:/usr/lib/x86_64-linux-gnu/gazebo-11/plugins:/opt/ros/foxy/opt/yaml_cpp_vendor/lib:/opt/ros/foxy/opt/rviz_ogre_vendor/lib:/opt/ros/foxy/lib/x86_64-linux-gnu:/opt/ros/foxy/lib:/home/ashok/Desktop/PX4-Autopilot/build/px4_sitl_default/build_gazebo
empty world, setting empty.world as default
Using: /home/ashok/Desktop/PX4-Autopilot/Tools/sitl_gazebo/models/mobility_2/mobility_2.sdf
SITL COMMAND: "/home/ashok/Desktop/PX4-Autopilot/build/px4_sitl_default/bin/px4" "/home/ashok/Desktop/PX4-Autopilot/build/px4_sitl_default"/etc -s etc/init.d-posix/rcS -t "/home/ashok/Desktop/PX4-Autopilot"/test_data
Creating symlink /home/ashok/Desktop/PX4-Autopilot/build/px4_sitl_default/etc -> /home/ashok/Desktop/PX4-Autopilot/buil

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

px4 starting.

INFO  [px4] Calling startup script: /bin/sh etc/init.d-posix/rcS 0
INFO  [init] found model autostart file as SYS_AUTOSTART=1002
INFO  [param] selected parameter default file eeprom/parameters_1002
INFO  [parameters] BSON document size 291 bytes, decoded 291 bytes (INT32:12, FLOAT:3)
[param] Loaded: eeprom/parameters_1002

### Description
Command to access and manipulate parameters via shell or script.

This is used for example in the star
Usage: param <command> [arguments...]
 Commands:

   load          Load params from a file (overwrite all)
     [<file>   ] File name (use default if not given)

   import        Import params from a file
     [<file>   ] File name (use default if not given)

   save          Save params to a file
     [<file>   ] File name (use default if not given)

   dump          Dump params from a file
     [<file>   ] File name (use default if not given)

   select        Select default file
     [<file>   ] File name

   select-backup Select default file
     [<file>   ] File name

   show          Show parameter values
     [-a]        Show all parameters (not just used)
     [-c]        Show only changed params (unused too)
     [-q]        quiet mode, print only param value (name needs to be exact)
     [<filter> ] Filter by param name (wildcard at end allowed, eg. sys_*)

   show-for-airframe Show changed params for airframe config

   status        Print status of parameter system

   set           Set parameter to a value
     <param_name> <value> Parameter name and value to set
     [fail     ] If provided, let the command fail if param is not found

   set-default   Set parameter default to a value
     [-s]        If provided, silent errors if parameter doesn't exists
     <param_name> <value> Parameter name and value to set
     [fail     ] If provided, let the command fail if param is not found

   compare       Compare a param with a value. Command will succeed if equal
     [-s]        If provided, silent errors if parameter doesn't exists
     <param_name> <value> Parameter name and value to compare

   greater       Compare a param with a value. Command will succeed if param is greater than the value
     [-s]        If provided, silent errors if parameter doesn't exists
     <param_name> <value> Parameter name and value to compare
     <param_name> <value> Parameter name and value to compare

   touch         Mark a parameter as used
     [<param_name1> [<param_name2>]] Parameter name (one or more)

   reset         Reset only specified params to default
     [<param1> [<param2>]] Parameter names to reset (wildcard at end allowed)

   reset_all     Reset all params to default
     [<exclude1> [<exclude2>]] Do not reset matching params (wildcard at end allowed)

   index         Show param for a given index
     <index>     Index: an integer >= 0

   index_used    Show used param for a given index
     <index>     Index: an integer >= 0

   find          Show index of a param
     <param>     param name
ERROR [px4] Startup script returned with return value: 256
1 Like

@REGATTE This means there is a syntax error in your airframe config file

Can you check if you actually get baro/magnetometer data?

this is my param in airframe file

You need to verify that the parameter actually exists in your firmware, not the startup script.
Type something like param show in your px4 shell

@Jaeyoung-Lim

You need to verify that the parameter actually exists in your firmware, not the startup script.
Type something like param show in your px4 shell

x EKF2_HGT_MODE [242,470] : 0
The param is available in the shell. Turns out I had a typo and dint notice it in the parameters. I’ve fixed that now. Sorry for that.

Could you please help me with this error. [Full terminal output is in my prev reply]
ERROR [px4] Startup script returned with return value: 256

I still get this even after fixing all parameter typo’s and I’ve rechecked paths, and mention of the model name in CMakeLists.txt(wherever necessary). All 3D(.stl) files are being read when launched with gazebo alone.

1 Like