creating a package dedicated to the robot model.
ros2 pkg create my_robot_description --build-type ament_cmake
rm -r include/ src/
mkdir urdf
.
├── CMakeLists.txt
├── **launch**
│ ├── display.launch.py
│ └── display.launch.xml
├── **meshes**
├── package.xml
├── **rviz**
│ └── urdf_config.rviz
└── **urdf**
├── common_properties.xacro
├── mobile_base.xacro
└── my_robot.urdf.xacro
install(
DIRECTORY urdf meshes rviz launch
DESTINATION share/${PROJECT_NAME}/
)
Usually, we add all launch files inside a _bringup
package (a dedicated package used for launch and configuration files). Here, we make an exception, because this launch file will be used only for visualisation and development
launch file must have three components
robot_description
parameter and publishes transformations on the /tf
topic./joint_states
topic.<launch>
<let name="urdf_path"
value="$(find-pkg-share my_robot_description)/urdf/my_robot.urdf.xacro" />
<let name="rviz_config_path"
value="$(find-pkg-share my_robot_description)/rviz/urdf_config.rviz" />
<node pkg="robot_state_publisher" exec="robot_state_publisher">
<param name="robot_description"
value="$(command 'xacro $(var urdf_path)')" />
</node>
<node pkg="joint_state_publisher_gui" exec="joint_state_publisher_gui" />
<node pkg="rviz2" exec="rviz2" args="-d $(var rviz_config_path)" />
</launch>