ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

I figured out the problem on my own, if I had 5 karma, I'd show a picture of the model being rendered and my rviz setup. Here were the problems that were found and solved:

Problem 1: Rviz was throwing errors due to a plethora of undefined libraries:

Solution: I was using a custom .rviz config file copied from the ROS1 urdf tutorial on github, and it ended up throwing undefined library errors due to ROS1 and RO2 having different naming conventions. To fix this, I renamed "class:" declarations to either have rviz_common/(nameofpanel) and rviz_default_plugins/(name of panel) instead of just (name of panel). E.G, "rviz_common/Displays" instead of "/Displays".

I can't find where in the documentation when and why they changed them so someone please comment and link that here

Problem 2: My launch file I was using from urdf_tutorial was throwing: "[ERROR] [launch]: Caught exception in launch (see debug for traceback): The launch file may have a syntax error, or its format is unknown".

Solution: My launch file was in .xml, and it appears ROS2 launch files are now only in .cpp and python. Thanks to the help of fergs's linked launch file example, I was able to modify it to publish robot_state_publisher with the urdf file contents!

#!/usr/bin/env python3

import os
import sys

from ament_index_python.packages import get_package_share_directory

import launch
import launch_ros.actions


def generate_launch_description():
    # Load the URDF into a parameter
    bringup_dir = get_package_share_directory('testpkg')
    urdf_path = os.path.join(bringup_dir, 'urdf', 'doggo.urdf')
    urdf = open(urdf_path).read()
  )

    return launch.LaunchDescription([),
        launch_ros.actions.Node(
            name='robot_state_publisher',
            package='robot_state_publisher',
            executable='robot_state_publisher',
            parameters=[{'robot_description': urdf}],
        ),
       ),
     )
    ])


def main(argv=sys.argv[1:]):
    """Run lifecycle nodes via launch."""
    ld = generate_launch_description()
    ls = launch.LaunchService(argv=argv)
    ls.include_launch_description(ld)
    return ls.run()


if __name__ == '__main__':
    main()

I have no clue how it works, but it does.

Problem 3: rviz2 was not loading the urdf despite a robot_state_publisher node being published.

Solution: This was actually a collection of problems instead of one! I wish I was able to publish pictures to explain it, but I do not have enough karma. First rviz2 was throwing an error "Fixed Frame [map] does not exist", but what eclipsed me was that this frame is supposed to reference the fixed frame in your urdf file. I named mine base_link so I renamed "map" to "base_link" in the displays menu and that fixed that.

Next despite there being no visible errors, my urdf was not displaying. What did not understand was that you need to have a display ADD ON enabled called "robotmodel" enabled! This is not in the panels menu. In order to enable this, you need to click the "Add" button within the display panel menu, scroll down rviz_default_plugins to click RobotModel, then click ok to enable that. Robot model needs to be enabled in the displays panel in order to render urdf files.

Next, despite both RobotModel and rviz2 being enabled rviz2 was still not loading the model. What I did not know was that rviz2 does not automatically listen to the description topic where your urdf is being published. You need to enter in the node that rviz listens to in order for it to listen to the node! According to the answer here You need to scroll down to the "Description Topic" drop-down menu in RobotModel and double click to the right of it and enter in "robot_description" for it to listen to the node where your urdf file node is being published. The name may be different based on what you named the robot_state_publisher node.

After solving these set of problems. The urdf of the model finally loaded....

I figured out the problem on my own, if I had 5 karma, I'd show a picture of the model being rendered and my rviz setup. Here were the problems that were found and solved:solved. If I had 10 karma, I'd also accept this awnser:

Problem 1: Rviz was throwing errors due to a plethora of undefined libraries:

Solution: I was using a custom .rviz config file copied from the ROS1 urdf tutorial on github, and it ended up throwing undefined library errors due to ROS1 and RO2 having different naming conventions. To fix this, I renamed "class:" declarations to either have rviz_common/(nameofpanel) and rviz_default_plugins/(name of panel) instead of just (name of panel). E.G, "rviz_common/Displays" instead of "/Displays".

I can't find where in the documentation when and why they changed them so someone please comment and link that here

Problem 2: My launch file I was using from urdf_tutorial was throwing: "[ERROR] [launch]: Caught exception in launch (see debug for traceback): The launch file may have a syntax error, or its format is unknown".

Solution: My launch file was in .xml, and it appears ROS2 launch files are now only in .cpp and python. Thanks to the help of fergs's linked launch file example, I was able to modify it to publish robot_state_publisher with the urdf file contents!

#!/usr/bin/env python3

import os
import sys

from ament_index_python.packages import get_package_share_directory

import launch
import launch_ros.actions


def generate_launch_description():
    # Load the URDF into a parameter
    bringup_dir = get_package_share_directory('testpkg')
    urdf_path = os.path.join(bringup_dir, 'urdf', 'doggo.urdf')
    urdf = open(urdf_path).read()
  )

    return launch.LaunchDescription([),
        launch_ros.actions.Node(
            name='robot_state_publisher',
            package='robot_state_publisher',
            executable='robot_state_publisher',
            parameters=[{'robot_description': urdf}],
        ),
       ),
     )
    ])


def main(argv=sys.argv[1:]):
    """Run lifecycle nodes via launch."""
    ld = generate_launch_description()
    ls = launch.LaunchService(argv=argv)
    ls.include_launch_description(ld)
    return ls.run()


if __name__ == '__main__':
    main()

I have no clue how it works, but it does.

Problem 3: rviz2 was not loading the urdf despite a robot_state_publisher node being published.

Solution: This was actually a collection of problems instead of one! I wish I was able to publish pictures to explain it, but I do not have enough karma. First rviz2 was throwing an error "Fixed Frame [map] does not exist", but what eclipsed me was that this frame is supposed to reference the fixed frame in your urdf file. I named mine base_link so I renamed "map" to "base_link" in the displays menu and that fixed that.

Next despite there being no visible errors, my urdf was not displaying. What did not understand was that you need to have a display ADD ON enabled called "robotmodel" enabled! This is not in the panels menu. In order to enable this, you need to click the "Add" button within the display panel menu, scroll down rviz_default_plugins to click RobotModel, then click ok to enable that. Robot model needs to be enabled in the displays panel in order to render urdf files.

Next, despite both RobotModel and rviz2 being enabled rviz2 was still not loading the model. What I did not know was that rviz2 does not automatically listen to the description topic where your urdf is being published. You need to enter in the node that rviz listens to in order for it to listen to the node! According to the answer here You need to scroll down to the "Description Topic" drop-down menu in RobotModel and double click to the right of it and enter in "robot_description" for it to listen to the node where your urdf file node is being published. The name may be different based on what you named the robot_state_publisher node.

After solving these set of problems. The urdf of the model finally loaded....