creating a package dedicated to the robot model.

create a package for urdf files

ros2 pkg create my_robot_description --build-type ament_cmake

remove unnecessary folders

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

update CMakeLists

install(
  DIRECTORY urdf meshes rviz launch
  DESTINATION share/${PROJECT_NAME}/
)

Writing a launch file to publish TFs and visualise the robot

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

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