0
$\begingroup$

Rosanswers logo

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='[email protected]',
    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="[email protected]">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>

Originally posted by RobotDreams on ROS Answers with karma: 327 on 2021-06-29

Post score: 1

$\endgroup$

2 Answers 2

0
$\begingroup$

Rosanswers logo

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.


Originally posted by trunc8 with karma: 156 on 2021-06-29

This answer was NOT ACCEPTED on the original site

Post score: 2


Original comments

Comment by RobotDreams on 2021-06-29:
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.

Comment by trunc8 on 2021-06-29:
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!

$\endgroup$
0
$\begingroup$

Rosanswers logo

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}/
</pre>
but did not at that time understand I also needed:
<pre>
# 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.


Originally posted by RobotDreams with karma: 327 on 2021-06-29

This answer was ACCEPTED on the original site

Post score: 1

$\endgroup$

Your Answer

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