How to Use P3D with ROS2 PX4 and Gazebo

Firstly, insert the plugin libgazebo_ros_p3d to the model.

The ModelPlugin is inserted in the SDF inside the model element.

Project PX4-Autopilot use jinja generate the SDF file.

Inside the code to /PX4-Autopilot/Tools/sitl_gazebo/models/iris/iris.sdf.jinjabefore build the project.

1
2
3
4
5
6
7
8
9
10
11
<plugin name='p3d_base_controller' filename='libgazebo_ros_p3d.so'>
<ros>
<namespace/>
</ros>
<update_rate>1</update_rate>
<body_name>base_link</body_name>
<frame_name>world</frame_name>
<xyz_offset>0 0 0</xyz_offset>
<rpy_offset>0 0 0</rpy_offset>
<gaussian_noise>0.01</gaussian_noise>
</plugin>

Before run rhe PX4 simulation , build and install gazebo_ros_pkgs from Source.

This is very important.

Build the PX4-Autopilot.

1
2
3
cd PX4-Autopilot/
make clean
make px4_sitl gazebo

Run make clean before run make px4_sitl gazebo, otherwise you can not generate the SDF file by jinja temple.

install gazebo_ros_pkgs before run make px4_sitl gazebo, otherwise you can not load the plugin libgazebo_ros_p3d.

Check the topic.

Open another terminal and run.

1
ros2 topic list