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

ROS2 always starts wrong node rclpy

asked 2019-11-11 16:23:43 -0500

LeoE gravatar image

I just started to program a new node of my project and tried to start it now and it always starts the wrong node. I have two nodes written in python, the first I wrote works fine, but the second one always starts the first instead of the second. Here my package.xml, setup.py and setup.cfg of the new node (CartpoleView):

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>cartpole_view</name>
  <version>0.0.0</version>
  <description>TODO: Package description</description>
  <maintainer email="info@luhbots.de">leonard</maintainer>
  <license>TODO: License declaration</license>

  <buildtool_depend>ament_cmake</buildtool_depend>

  <depend>rclpy</depend>
  <depend>custom_msgs</depend>

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

  <export>
    <build_type>ament_python</build_type>
  </export>
</package>

setup.py of CartPole node:

from setuptools import setup

package_name = 'cartpole_view'

setup(
    name=package_name,
    version='0.0.0',
    packages=[],
    py_modules=[
        'scripts.main'
    ],
    install_requires=['setuptools'],
    zip_safe=True,
    author='user',
    author_email="user@todo.todo",
    maintainer='user',
    maintainer_email="user@todo.todo",
    keywords=['ROS', 'ROS2'],
    classifiers=[
        'Intended Audience :: Developers',
        'License :: OSI Approved :: Apache Software License',
        'Programming Language :: Python',
        'Topic :: Software Development',
    ],
    description='TODO: Package description.',
    license='Apache License, Version 2.0',
    tests_require=['pytest'],
    entry_points={
        'console_scripts': [
            'cartpole_view = scripts.main:main'
        ],
    },
)

and setup.cfg of CartPole node:

[develop]
script-dir=$base/lib/cartpole_view
[install]
install-scripts=$base/lib/cartpole_view

And now the same for my other node (which is always started instead of CartPole node):

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>python_learner</name>
  <version>0.0.0</version>
  <description>TODO: Package description</description>
  <maintainer email="info@luhbots.de">leonard</maintainer>
  <license>TODO: License declaration</license>

  <buildtool_depend>ament_cmake</buildtool_depend>

  <depend>rclpy</depend>
  <depend>custom_msgs</depend>

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

  <export>
    <build_type>ament_python</build_type>
  </export>
</package>

setup.py:

from setuptools import setup

package_name = 'python_learner'

setup(
    name=package_name,
    version='0.0.0',
    packages=[],
    py_modules=[
        'scripts.main',
        'scripts.gym_interface',
        'scripts.test',
        'scripts.test_2',
        'scripts.double_deep_q_n'
    ],
    install_requires=['setuptools'],
    zip_safe=True,
    author='user',
    author_email="user@todo.todo",
    maintainer='user',
    maintainer_email="user@todo.todo",
    keywords=['ROS', 'ROS2'],
    classifiers=[
        'Intended Audience :: Developers',
        'License :: OSI Approved :: Apache Software License',
        'Programming Language :: Python',
        'Topic :: Software Development',
    ],
    description='TODO: Package description.',
    license='Apache License, Version 2.0',
    tests_require=['pytest'],
    entry_points={
        'console_scripts': [
            'python_learner = scripts.main:main'
        ],
    },
)

and setup.cfg:

[develop]
script-dir=$base/lib/python_learner
[install]
install-scripts=$base/lib/python_learner

If I build it using colcon build the cartpole node is being built, but if I start it with ros2 run cartpole_view cartpole_view it starts the gym_interface script, which is part of the python_learner node.... Anybody has any idea why this might be? I can't see anything wrong with the names etc. I tried deleting the install, build and log folders and rebuild the whole project, but still the same.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2019-11-11 16:48:05 -0500

sloretz gravatar image

It looks like both packages python_learner and cartepole_view create and install a python package called scripts. Both create a console_scripts entry point importing scripts.main. I'd recommend renaming your python module from scripts to the package name.

A console_scripts entry point like python_learner = scripts.main:main means an executable called python_learner will be created that starts python, imports something called main from scripts.main, and calls it. In other words, calling python_learner is like running the command: python3 -c "from scripts.main import main ; main()". Since both packages are installing to scripts.main, I would assume both python_learner and cartpole_view would run the same code, whichever was installed last.

edit flag offensive delete link more

Comments

I will try this out immediatley, but this means I'm not allowed to have the same folder (scripts is my python script folder) in both packages?! Thats really weird....

LeoE gravatar image LeoE  ( 2019-11-11 16:49:32 -0500 )edit

Do you know by any chance if this is wanted behaviour? Otherwise I would write a bug report. And thanks a lot, it works!

LeoE gravatar image LeoE  ( 2019-11-11 16:51:02 -0500 )edit

The arguments being passed to setup.py says scripts is more than a folder. The arguments to py_modules says "install scripts/main.py as scripts.mainglobally". It might be helpful to read the first two examples (6.1 and 6.2) on this page: https://docs.python.org/3/distutils/e...

sloretz gravatar image sloretz  ( 2019-11-11 16:57:35 -0500 )edit

Thanks a lot!

LeoE gravatar image LeoE  ( 2019-11-11 18:22:44 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2019-11-11 16:23:43 -0500

Seen: 357 times

Last updated: Nov 11 '19