Robotics StackExchange | Archived questions

Error with pkg turtlebot2_demo ( ModuleNotFoundError: No module named 'launch.exit_handler')

Good,

I'm a bit new to ROS2, and I wanted to port my turtlebot 2 to ROS 2, so I looked at the following repository: https://github.com/ros2/turtlebot2_demo.

This repository says that you can use the demos that were originally available for turtlebot 2 in ROS 1 but working in ROS 2.

I have installed ROS 1 (melodic) and ROS 2 bouncy as indicated in the repository. However some demos do work, at least the teleop joystick and the follower but if I run the nodes separately, as shown in the README.

But what I'm really interested in is to see if I can scan a room and navigate with ROS 2, for this some cartographer packages are presented with which it can be done, however, when I run the launch command of ros 2 to launch all the nodes that do the mapping with the following command:

launch `ros2 pkg prefix turtlebot2_cartographer`/share/turtlebot2_cartographer/launch/turtlebot_carto_2d.py

I get the following error:

turtlebot@turtlebot@turtlebot:~/ros2$ launch ``ros2 pkg prefix turtlebot2_cartographer`/share/turtlebot2_cartographer/launch/turtlebot_carto_2d.py
Traceback (most recent call last):
  File "/opt/ros/bouncy/bin/launch", line 11, in <module>
    load_entry_point('launch==0.5.1', 'console_scripts', 'launch')()
  File "/opt/ros/bouncy/lib/python3.6/site-packages/launch/legacy/main.py", line 50, in main
    load_launch_file(launch_file, launch_descriptor, args.args)
  File "/opt/ros/bouncy/lib/python3.6/site-packages/launch/legacy/loader.py", line 20, in load_launch_file
    launch_module = loader.load_module()
  File "<frozen importlib._bootstrap_external>", line 399, in _check_name_wrapper
  File "<frozen importlib._bootstrap_external>", line 823, in load_module
  File "<frozen importlib._bootstrap_external>", line 682, in load_module
  File "<frozen importlib._bootstrap>", line 265, in _load_module_shim
  File "<frozen importlib._bootstrap>", line 684, in _load_module_shim
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/turtlebot/ros2/install/turtlebot2_cartographer/share/turtlebot2_cartographer/launch/turtlebot_carto_2d.py", line 18, in <module>
    from launch.exit_handler import restart_exit_handler
ModuleNotFoundError: No module named 'launch.exit_handler'

I haven't been able to find any information about why this error can occur, and I can't find any other way to use my turtlebot 2 in ROS 2, at least to do a little testing.

My ROS env variables are these:

turtlebot@turtlebot:~/ros2$ env | grep ROS
ROS_ETC_DIR=/opt/ros/melodic/etc/ros
ROS_ROOT=/opt/ros/melodic/share/ros
ROS_MASTER_URI=http://localhost:11311
ROS1_DISTRO=melodic
ROS_VERSION=2
ROS_PYTHON_VERSION=3
ROS_PACKAGE_PATH=/opt/ros/melodic/share
ROSLISP_PACKAGE_DIRECTORIES=
ROS_DISTRO=bouncy

This is the python code where the launch.exit_handler import is done:

# Copyright 2017 Open Source Robotics Foundation, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import os

from ament_index_python.packages import get_package_share_directory
from launch.exit_handler import restart_exit_handler
from ros2run.api import get_executable_path


def launch(launch_descriptor, argv):
    ld = launch_descriptor
    package = 'turtlebot2_drivers'
    ld.add_process(
        cmd=[get_executable_path(package_name=package, executable_name='kobuki_node')],
        name='kobuki_node',
        exit_handler=restart_exit_handler,
    )
    package = 'astra_camera'
    ld.add_process(
        cmd=[
            get_executable_path(package_name=package, executable_name='astra_camera_node'),
            '-dw', '320', '-dh', '240', '-C', '-I'],
        name='astra_camera_node',
        exit_handler=restart_exit_handler,
    )
    package = 'depthimage_to_laserscan'
    ld.add_process(
        cmd=[
            get_executable_path(
                package_name=package, executable_name='depthimage_to_laserscan_node')],
        name='depthimage_to_laserscan_node',
        exit_handler=restart_exit_handler,
    )
    package = 'tf2_ros'
    ld.add_process(
        # The XYZ/Quat numbers for base_link -> camera_rgb_frame are taken from the
        # turtlebot URDF in
        # https://github.com/turtlebot/turtlebot/blob/931d045/turtlebot_description/urdf/sensors/astra.urdf.xacro
        cmd=[
            get_executable_path(
                package_name=package, executable_name='static_transform_publisher'),
            '-0.087', '-0.0125', '0.287',
            '0', '0', '0', '1',
            'base_link',
            'camera_rgb_frame'
        ],
        name='static_tf_pub_base_rgb',
        #exit_handler=restart_exit_handler,
    )
    package = 'tf2_ros'
    ld.add_process(
        # The XYZ/Quat numbers for camera_rgb_frame -> camera_depth_frame are taken from the
        # turtlebot URDF in
        # https://github.com/turtlebot/turtlebot/blob/931d045/turtlebot_description/urdf/sensors/astra.urdf.xacro
        cmd=[
            get_executable_path(
                package_name=package, executable_name='static_transform_publisher'),
            '0', '0.0250', '0',
            '0', '0', '0', '1',
            'camera_rgb_frame',
            'camera_depth_frame'
        ],
        name='static_tf_pub_rgb_depth',
        exit_handler=restart_exit_handler,
    )
    package = 'joy'
    ld.add_process(
        cmd=[get_executable_path(package_name=package, executable_name='joy_node')],
        name='joy_node',
        exit_handler=restart_exit_handler,
    )
    package = 'teleop_twist_joy'
    ld.add_process(
        cmd=[get_executable_path(package_name=package, executable_name='teleop_node')],
        name='teleop_node',
        exit_handler=restart_exit_handler,
    )
    package = 'cartographer_ros'
    turtlebot2_cartographer_prefix = get_package_share_directory('turtlebot2_cartographer')
    cartographer_config_dir = os.path.join(turtlebot2_cartographer_prefix, 'configuration_files')
    ld.add_process(
        cmd=[
            get_executable_path(package_name=package, executable_name='cartographer_node'),
            '-configuration_directory', cartographer_config_dir,
            '-configuration_basename', 'turtlebot_2d.lua'
        ],
        name='cartographer_node',
        exit_handler=restart_exit_handler,
    )

    return ld

I think it's a problem with the ROS2 launch command but I can't figure out what the error is or what exactly I need to do to fix it.

I have tried to remove everything related to that import in the code, with this it starts the program but quickly for some reason that I don't know all the nodes send a SIGINT signal to kill themselves and the program closes.

(kobuki_node) pid 3223: ['/opt/ros/bouncy/lib/turtlebot2_drivers/kobuki_node'] (stderr > stdout, all > console)
(astra_camera_node) pid 3224: ['/opt/ros/bouncy/lib/astra_camera/astra_camera_node', '-dw', '320', '-dh', '240', '-C', '-I'] (stderr > stdout, all > console)
(depthimage_to_laserscan_node) pid 3225: ['/opt/ros/bouncy/lib/depthimage_to_laserscan/depthimage_to_laserscan_node'] (stderr > stdout, all > console)
(static_tf_pub_base_rgb) pid 3226: ['/opt/ros/bouncy/lib/tf2_ros/static_transform_publisher', '-0.087', '-0.0125', '0.287', '0', '0', '0', '1', 'base_link', 'camera_rgb_frame'] (stderr > stdout, all > console)
(static_tf_pub_rgb_depth) pid 3229: ['/opt/ros/bouncy/lib/tf2_ros/static_transform_publisher', '0', '0.0250', '0', '0', '0', '0', '1', 'camera_rgb_frame', 'camera_depth_frame'] (stderr > stdout, all > console)
(joy_node) pid 3233: ['/opt/ros/bouncy/lib/joy/joy_node'] (stderr > stdout, all > console)
[astra_camera_node] [INFO] []: Device "2bc5/0401@1/2" found.
[astra_camera_node] Using depth frame id openni_depth_optical_frame
[astra_camera_node] Using color frame id openni_color_optical_frame
[astra_camera_node] [INFO] []: Astra IR camera disabled
[astra_camera_node] [INFO] []: Astra RGB camera disabled
(teleop_node) pid 3241: ['/opt/ros/bouncy/lib/teleop_twist_joy/teleop_node'] (stderr > stdout, all > console)
[astra_camera_node] [INFO] []: No matching device found.... waiting for devices. Reason: astra_wrapper::AstraDevice::AstraDevice(const string&) @ /tmp/binarydeb/ros-bouncy-astra-camera-2.1.1/src/astra_device.cpp @ 76 : Device open failed
[astra_camera_node]     Could not open "2bc5/0401@1/2": Failed to open the USB device!
[astra_camera_node]
[astra_camera_node]
(cartographer_node) pid 3255: ['/opt/ros/bouncy/lib/cartographer_ros/cartographer_node', '-configuration_directory', '/opt/ros/bouncy/share/turtlebot2_cartographer/configuration_files', '-configuration_basename', 'turtlebot_2d.lua'] (stderr > stdout, all > console)
[static_tf_pub_base_rgb] [INFO] []: LOOPING due to no latching at the moment
[static_tf_pub_rgb_depth] [INFO] []: LOOPING due to no latching at the moment
[teleop_node] [INFO] [TeleopTwistJoy]: Teleop enable button 5.
[teleop_node] [INFO] [TeleopTwistJoy]: Linear axis x on 5 at scale 0.500000.
[teleop_node] [INFO] [TeleopTwistJoy]: Angular axis yaw on 2 at scale 0.500000.
[joy_node] [ERROR] []: Couldn't open joystick /dev/input/js0. Will retry every second.
(cartographer_node) rc -4
() tear down
(kobuki_node) signal SIGINT
(astra_camera_node) signal SIGINT
(depthimage_to_laserscan_node) signal SIGINT
(static_tf_pub_base_rgb) signal SIGINT
(static_tf_pub_rgb_depth) signal SIGINT
(joy_node) signal SIGINT
(teleop_node) signal SIGINT
[static_tf_pub_rgb_depth] signal_handler(2)
[kobuki_node] signal_handler(2)
[static_tf_pub_base_rgb] signal_handler(2)
[depthimage_to_laserscan_node] signal_handler(2)
^C(joy_node) signal SIGTERM
(kobuki_node) rc 0
(astra_camera_node) rc -11
(depthimage_to_laserscan_node) rc 0
(static_tf_pub_base_rgb) rc 0
(static_tf_pub_rgb_depth) rc 0
(joy_node) rc -15
(teleop_node) rc -2

Asked by Sergiiio__ on 2023-06-13 11:26:16 UTC

Comments

Answers