Creating the URDF ================= A URDF (Unified Robot Description Format) is an XML file that describes a robot's physical structure — its links (rigid bodies), joints (connections), sensors, and collision geometry. Nav2 and RViz both require a URDF to understand the robot's shape and transform sensor data into the correct reference frames. **Official ROS 2 reference:** https://docs.ros.org/en/humble/Tutorials/Intermediate/URDF/URDF-Main.html ---- Key Concepts ------------ **Links** are the rigid bodies of the robot: the chassis, wheels, sensor mounts. **Joints** connect links together. The joint type controls how they move relative to each other: - ``fixed`` — no movement (e.g. a sensor bolted to the chassis) - ``continuous`` — rotates freely (e.g. wheels) - ``revolute`` — rotates within limits (e.g. a steering joint) **Frames** — each link defines a coordinate frame. Nav2 uses these to transform sensor readings (e.g. laser scan in the ``laser`` frame) into the robot body frame (``base_link``) and the map frame (``map``). ---- RoboFlock Physical Dimensions ------------------------------ Use these values when building the RoboFlock URDF. Measure your specific build and update these if they differ. .. list-table:: :widths: 40 60 :header-rows: 1 * - Parameter - Value * - Chassis length - ~0.45 m * - Chassis width - ~0.35 m * - Chassis height (to top deck) - ~0.15 m * - Wheel diameter - ~0.12 m (measure your specific motors) * - Wheel width - ~0.05 m * - Wheelbase (front-to-rear axle) - ~0.30 m * - Track width (left-to-right axle) - ~0.32 m * - LiDAR mount height above base_link - ~0.22 m * - LiDAR horizontal offset (forward) - ~0.05 m * - Ultrasonic sensor height - ~0.08 m ---- Minimal URDF Structure ----------------------- Every URDF starts with a ```` tag and must contain at least a ``base_link``. .. code-block:: xml ---- Four-Wheel Offsets ------------------ For a robot with four independently driven wheels, the joint origins relative to ``base_link`` are: .. code-block:: text Front-left (wheel_fl): xyz = 0.15 0.175 0.0 Front-right (wheel_fr): xyz = 0.15 -0.175 0.0 Rear-left (wheel_rl): xyz = -0.15 0.175 0.0 Rear-right (wheel_rr): xyz = -0.15 -0.175 0.0 The ``rpy="-1.5708 0 0"`` rotation rotates the wheel cylinder so its spin axis aligns with Y (left-right in the robot frame). All four wheels use the same rotation value. ---- Publishing the Robot Description --------------------------------- Add ``robot_state_publisher`` to your launch file to broadcast the URDF transforms over ``/tf``: .. code-block:: python from launch_ros.actions import Node from launch.substitutions import Command from ament_index_python.packages import get_package_share_directory import os urdf_path = os.path.join( get_package_share_directory('bring_up'), 'urdf', 'roboflock.urdf' ) Node( package='robot_state_publisher', executable='robot_state_publisher', parameters=[{'robot_description': Command(['cat ', urdf_path])}] ) This publishes transforms between every ``fixed`` joint automatically. For ``continuous`` wheel joints you also need a ``joint_state_publisher`` that publishes the wheel angle, or encoder odometry from the ODESC controllers. ---- Validating Your URDF -------------------- .. code-block:: bash # Install check tool sudo apt install ros-humble-urdf # Validate syntax check_urdf roboflock.urdf # Visualise in RViz ros2 launch urdf_tutorial display.launch.py model:=roboflock.urdf A correct URDF will show the robot chassis and all four wheels in RViz with no red error text in the terminal. ---- URDF and Nav2 ------------- Nav2 uses two key frames from the URDF: - ``base_link`` — the robot body frame. All navigation is computed relative to this. - ``laser`` (or whatever you name the LiDAR joint's child link) — must match the ``frame_id`` parameter in your ``rplidar_ros`` node config. If the ``laser`` frame name in your URDF does not match the ``frame_id`` published by ``rplidar_ros``, the costmap will be empty. Verify with: .. code-block:: bash ros2 topic echo /scan --field header.frame_id The output should match the child link name of your LiDAR joint. ---- Further Reading --------------- - `URDF tutorials (ROS 2 Humble) `_ - `robot_state_publisher `_ - `tf2 and coordinate frames `_