Skip to content

moa_description

Tanish Bhatt edited this page Jul 18, 2023 · 5 revisions

URDF

URDF stands for Unified Robot Description Format. A robot is made up of multiple components that work together to get some sort of output. A URDF is an xml formatted file that explains how the individual building blocks work in order to produce that specific result and also show the bounds on the components. The file is generally made of links and joints where a link is generally defined as a physical component on the robot and a joint is something that defines the restrictions on the links motion. A URDF is useful for simulation, visualization and even controlling the robot.

Links

The following is a general template of a link (e.g., Chassis):

<link name='chassis_link'>
        <visual>
            <geometry>
                <mesh filename='...'/>
            </geometry>
            <material name='grey'>
                <color rgba='0.4 0.4 0.4 1'/>
            </material> 
            <origin  xyz='0 0 0' rpy='${pi/2} 0 0'/>
        </visual>
</link>

In the above code we first define the name of the link then within the link structure define the visual, material and positional properties.

Joints

The following is a general template of a joint (e.g., Origin to Chassis):

<joint name='world_to_chassis_joint' type='fixed'>
        <parent link='world_link'/>
        <child link='chassis_link'/>
        <origin xyz='1 0 1' rpy='0 0 0'/>
    </joint>

In the above code we first define the name of the joint and it is customary to name the joint by its starting point to end point. We also define the type of joint it is, in this case it's a fixed joint meaning the chassis link has 0 degrees of freedom. There are 6 types of joints: revolute, continuous, prismatic, fixed, floating and planar, where all follow a different path of motion.

The Directory

The urdf of the autonomous car can be found in moa/moa_description/urdf. Now you may have noticed that there are multiple files and that is because coding up the file for a complex robot can mean several hundred lines of code which is time consuming and inefficient when there are duplicated components that have same structure. Therefore, using the power of xacro we can separate links and joints into their respective files and then a final robot.urdf.xacro file can include both of them. To make code evening easier xacro allows for creating constants which can be used in other files any time and macros which are similar to functions that can be called with arguments to generate code.

Visualisating The Robot

To see the autonomous car and how it moves we must start a ros2 node that outputs the state of the robot to /robot_description topic. In moa/moa_description/launch there's a urdf_model.py file that starts a ros2 node using the robot_state_publisher package and publishes the necessary info to the topic. To launch the file, copy this command into the terminal: ros2 launch moa_description urdf_model.py or ros2 launch moa_bringup base.py to start all nodes.

Assuming you are developing inside a dev container Rviz (visualisation tool for ros2) will not work as it won't be able to detect a display. To solve this, you must download Foxglove which is similar to Rviz but allows for port sharing which allows for robot visualisation, but it also has many other features and capabilities that are useful for this project.

To see the urdf model in Foxglove you have to launch foxglove bridge in addition to the urdf model. To launch foxglove bridge, copy this command into the terminal: ros2 launch foxglove_bridge foxglove_bridge_launch.xml port:=8765 - the port number can be different, if you started all nodes using the second command then you do not need to enter this above command.

Once both files have been launched open Foxglove and connect to the appropriate port, then open the 3D panel and in the Topics tab check the visibility of /robot_description. You should now be able to see the robot. To see what joints are moveable expand the topic and then further expand Joints and then expand the joint you wish to manually change.

No Meshes Showing Up In Foxglove?

The urdf of a robot may have meshes which are defined as a path to a file and if you're running ros on a docker container Foxglove will try to find that file on your local/host machine which it will not find. Thus if no meshes show up/ you can't see the car you will need to change a setting in Foxglove:

  1. Open Foxglove setting/about which is under help tab

  2. Navigate to ROS_PACKAGE_PATH which is under the General section

  3. Enter the local/host machine path to the package that contains the meshes (exclude package name in path)

    e.g., if a mesh in a urdf is defined as: <mesh filename="package://moa_description/meshes/robot.stl"/> and in your host machine the path to those meshes is: C:\autonomous\src\moa\moa_description\meshes\robot.stl then in Foxglove setting enter: C:\autonomous\src\moa

  • For multiple mesh directories add all them to ROS_PACKAGE_PATH but separated by ;.
Clone this wiki locally