How do you load urdf files in rviz2 with ROS2?
Edit 2: Following fergs's launch file code on https://github.com/mikeferguson/ubr_r... , 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 ...