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

ROS2: urdf not copied to install folder

asked 2021-06-29 13:04:36 -0500

RobotDreams gravatar image

ROS2 Foxy (on Ubuntu 20.04LTS Desktop)

Problem: urdf directory in package not being copied to the install folder
Error Msg:

InvalidLaunchFileError: Caught exception when trying to load file of format [py]: [Errno 2] No such file or directory: '/home/ubuntu/handsonros2/install/rviz2_basics/share/rviz2_basics/urdf/gopigoMinimal.urdf'

Package Tree: ~/handsonros2/src/chap3rviz2_basics/

.
├── CMakeLists.txt
├── launch
│   ├── ros1_gopigoMinimal_rviz.launch.donotuse
│   ├── ros1_gopigoMinimal_rviz_simple.launch.donotuse
│   └── ros2_gpgMin_rviz2_simple.launch.py
├── package.xml
├── README.md
├── ros1CMakeLists.txt
├── ros1package.xml
├── ros2CMakeLists.txt
├── ros2package.xml
├── rviz
│   ├── default.rviz
│   ├── gopigoMinimal.rviz
│   └── gpgMin.rviz2.rviz
├── setup.py
└── urdf
    ├── gopigoMinimal.urdf
    └── keith_gpg.urdf

setup.py:

import os
from glob import glob
from setuptools import setup
from setuptools import find_packages

package_name = 'rviz2_basics'

setup(
    name=package_name,
    version='0.0.0',
    packages=[package_name],
    data_files=[
        ('share/ament_index/resource_index/packages',
            ['resource/' + package_name]),
        ('share/' + package_name, ['package.xml']),
        (os.path.join('share', package_name), glob('launch/*.py)),
        (os.path.join('share', package_name), glob('urdf/*'))
    ],
    install_requires=['setuptools'],
    zip_safe=True,
    maintainer='slowrunner',
    maintainer_email='slowrunner@users.noreply.github.com',
    description='ROS2 Version of Hands-On ROS - Chap4 RVIZ Basics',
    license='Apache License 2.0',
    tests_require=['pytest'],
    # entry_points={
    #     'console_scripts': [
    #     ],
    },
)

package.xml:

<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
  <name>rviz2_basics</name>
  <version>0.0.0</version>
  <description>ROS2 Version of Hands-On ROS - Chap4 RVIZ Basics"</description>
  <maintainer email="slowrunner@users.noreply.github.com">slowrunner</maintainer>
  <license>Apache License 2.0</license>

  <buildtool_depend>ament_cmake</buildtool_depend>

  <test_depend>ament_lint_auto</test_depend>
  <test_depend>ament_lint_common</test_depend>

  <exec_depend>robot_state_publisher</exec_depend>
  <exec_depend>joint_state_publisher</exec_depend>

  <export>
    <build_type>ament_cmake</build_type>
  </export>
</package>
edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
1

answered 2021-06-29 20:53:16 -0500

RobotDreams gravatar image

updated 2021-06-29 21:31:02 -0500

Looks like setup.py was a red herring. I initially created the package with:

ros2 pkg create rviz2_basics

which created package.xml and CMakeLists.txt.

Then added dependencies to package.xml
<exec_depend>robot_state_publisher</exec_depend> <exec_depend>joint_state_publisher</exec_depend>

Added launch files installation in the CMakeLists.txt

# (Always add before ament_package() line)
# Install launch files
install(DIRECTORY
  launch
  DESTINATION share/${PROJECT_NAME}/

but did not at that time understand I also needed:

# Install urdf files
install(DIRECTORY
  urdf
  DESTINATION share/${PROJECT_NAME}/

and started following the urdf-tutorial which creates a setup.py to satisfy the urdf, but it turned out all my efforts with setup.py were not actually being used.

Solution was to edit the CMakeLists.txt and add the urdf files installation.

edit flag offensive delete link more
2

answered 2021-06-29 16:15:30 -0500

Make a modification in your launch file. Your other files are fine. Your setup.py will result the urdf files to be copied and not the directory like this: /home/ubuntu/handsonros2/install/rviz2_basics/share/rviz2_basics/gopigoMinimal.urdf
You can confirm if the file exists on this path by cd'ing into it.

If you'd like the syntax for reference, you can refer to this package.

edit flag offensive delete link more

Comments

1

That (urdf-tutorial) was what led me to add the setup.py in the first place. I originally created the package as a cmake which didn't include a setup.py or setup.cfg.

I deleted the build and install directories, and rebuilt - share/rviz2_basics/launch gets created with the launch files, but for some reason the urdf folder does not get created, (nor is the gopigoMinimal.urdf copied anywhere - did not get copied to share/rviz2_basics )

I added a setup.cfg file and tried again, no cigars - still launch folder but no urdf folder no urdf file.

I think I might see the problem - in CMakeLists.txt the install for the launch folder instructions exist, but not the urdf folder. I'll try adding that and see what happens.

RobotDreams gravatar image RobotDreams  ( 2021-06-29 18:25:37 -0500 )edit

Yeah! CMakeLists and setup.py shouldn't be existing together. I missed them in your directory structure entirely! Your obervations in the other answer are correct. Cheers!

trunc8 gravatar image trunc8  ( 2021-06-29 22:45:46 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2021-06-29 13:04:36 -0500

Seen: 1,378 times

Last updated: Jun 29 '21