0
$\begingroup$

Rosanswers logo

Edit 2: Following fergs's launch file code on https://github.com/mikeferguson/ubr_reloaded/blob/ros2/ubr1_bringup/launch/robot.launch.py , I was able to create a working launch file which sets up robot_state_publisher which rviz2 picks up. However, now the problem is that, although the joints for the models load, the models do not... I do not have the 5 karma required to upload the picture, but here is the modified launch file im using, and the urdf file are below.

I also removed the error log mention in Edit 1 as well as the .rviz config file since they are no longer relevant to the current problem.

Edit: As stevemacenski pointed out, I was getting errors thrown about non-existent libraries was an rviz config problem. it throws an error with the old library names but it doesn't tell you that in rviz2, they renamed the libraries. So When when my laucnh file was loading, It threw an error because I was using Rviz1 library naming conventions instead of Rviz2 library naming conventions . I fixed the .rviz config file and the full working file has been moved into the question

I thought it would be a straight port of ros1 launch file to ros2 launch file to load but apprently not. I've now fixed the rviz config library naming convention to match ros2's, and I managed to get the launch file to load robot_state_publisher and got rviz2 to read it, the final problem seems to be that rviz2 loads the joints of urdf, but not the model(basic geometry and .dae file) of the robot. This urdf file I have will work in

Python launch file:

 #!/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()

URDF file:

<?xml version="1.0"?>
<robot name="StlTest">
  <link name="base_link">
    <visual>
            <color rgba="0.1 0.1 0.1 1"/>
      <geometry>
        <cylinder length="0.01" radius="0.2"/>
      </geometry>
    </visual>
  </link>
   
    <link name="body_link">
        <visual>
        <origin xyz="0 0 0" rpy="0 0 0"/> 
            <geometry>
                <mesh filename="package://testpkg/meshes/doggo_body.dae"/>
            </geometry>
        </visual>
    </link>

    <joint name="base_to_right_leg" type="fixed">
      <parent link="base_link"/>
      <child link="body_link"/>
  </joint>
</robot>

Incase the filestructure is the issue, here it is.

  SourceBattleDoggo  
    ├── build
│   ├── COLCON_IGNORE
│   └── testpkg
│       ├── ament_cmake_core
│       ├── ament_cmake_environment_hooks
│       ├── ament_cmake_index
│       ├── ament_cmake_package_templates
│       ├── ament_cmake_symlink_install
│       ├── ament_cmake_uninstall_target
│       ├── ament_copyright
│       ├── ament_lint_cmake
│       ├── ament_xmllint
│       ├── cmake_args.last
│       ├── CMakeCache.txt
│       ├── CMakeFiles
│       ├── cmake_install.cmake
│       ├── colcon_build.rc
│       ├── colcon_command_prefix_build.sh
│       ├── colcon_command_prefix_build.sh.env
│       ├── CTestConfiguration.ini
│       ├── CTestCustom.cmake
│       ├── CTestTestfile.cmake
│       ├── install_manifest.txt
│       ├── Makefile
│       └── symlink_install_manifest.txt
├── install
│   ├── COLCON_IGNORE
│   ├── local_setup.bash
│   ├── local_setup.ps1
│   ├── local_setup.sh
│   ├── _local_setup_util_ps1.py
│   ├── _local_setup_util_sh.py
│   ├── local_setup.zsh
│   ├── setup.bash
│   ├── setup.ps1
│   ├── setup.sh
│   ├── setup.zsh
│   └── testpkg
│       └── share
├── launch
│   ├── test.launch
│   └── test.launch.py
├── rviz
│   ├── urdf.rviz
│   └── urdf.vcg
├── share
│   └── launch
│       └── test.launch
└── src
    └── testpkg
        ├── CMakeLists.txt
        ├── include
        ├── meshes
        ├── package.xml
        ├── rviz
        ├── src
        └── urdf

So how do you load a urdf in ROS2 like you can in ROS1?


Originally posted by rydb on ROS Answers with karma: 125 on 2020-06-08

Post score: 0

$\endgroup$

2 Answers 2

0
$\begingroup$

Rosanswers logo

This doesn't look like a URDF problem but your rviz config file issue. You have displays and plugins that don't exist or were renamed in ROS2. Most of those are just renamed to rviz_common or rviz_default_plugins.


Originally posted by stevemacenski with karma: 8272 on 2020-06-08

This answer was NOT ACCEPTED on the original site

Post score: 1


Original comments

Comment by rydb on 2020-06-09:
The .rviz config problem and the working rviz has been placed in the question

$\endgroup$
0
$\begingroup$

Rosanswers logo

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


Originally posted by rydb with karma: 125 on 2020-06-23

This answer was ACCEPTED on the original site

Post score: 4


Original comments

Comment by 808brick on 2021-03-29:
I can confirm that this solution worked. Note that this answer gets clipped since it is long, and you need to hit the "more" button to see all of it (I was missing the last step, which is the most important)

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.