Rosjet Part II launch with custom_interfaces error

Hi,

I have a problem to launch rosp2 (named the part II package)

ros2 launch rosp2 find_wall_launch_file.launch.py
[INFO] [launch]: All log files can be found below /home/user/.ros/log/2022-02-22-09-09-23-066018-8_xterm-65520
[INFO] [launch]: Default logging verbosity is set to INFO
[INFO] [rosp2-1]: process started with pid [65684]
[rosp2-1] Traceback (most recent call last):
[rosp2-1]   File "/opt/ros/foxy/lib/python3.8/site-packages/rosidl_generator_py/import_type_support_impl.py", line 46, in import_type_support
[rosp2-1]     return importlib.import_module(module_name, package=pkg_name)
[rosp2-1]   File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
[rosp2-1]     return _bootstrap._gcd_import(name[level:], package, level)
[rosp2-1]   File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
[rosp2-1]   File "<frozen importlib._bootstrap>", line 991, in _find_and_load
[rosp2-1]   File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
[rosp2-1]   File "<frozen importlib._bootstrap>", line 657, in _load_unlocked
[rosp2-1]   File "<frozen importlib._bootstrap>", line 556, in module_from_spec
[rosp2-1]   File "<frozen importlib._bootstrap_external>", line 1166, in create_module
[rosp2-1]   File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
[rosp2-1] ImportError: /home/user/ros2_ws/install/custom_interfaces/lib/libcustom_interfaces__rosidl_generator_c.so: undefined symbol: geometry_msgs__msg__Point__Sequence__init
[rosp2-1]
[rosp2-1] During handling of the above exception, another exception occurred:
[rosp2-1]
[rosp2-1] Traceback (most recent call last):
[rosp2-1]   File "/home/user/ros2_ws/install/rosp2/lib/rosp2/rosp2", line 33,in <module>
[rosp2-1]     sys.exit(load_entry_point('rosp2==0.0.0', 'console_scripts', 'rosp2')())
[rosp2-1]   File "/home/user/ros2_ws/install/rosp2/lib/python3.8/site-packages/rosp2/find_wall.py", line 138, in main
[rosp2-1]     findwall_service = Service()
[rosp2-1]   File "/home/user/ros2_ws/install/rosp2/lib/python3.8/site-packages/rosp2/find_wall.py", line 21, in __init__
[rosp2-1]     self.srv = self.create_service(FindWall, 'findwall', self.FindWallService_callback)
[rosp2-1]   File "/opt/ros/foxy/lib/python3.8/site-packages/rclpy/node.py", line 1295, in create_service
[rosp2-1]     check_for_type_support(srv_type)
[rosp2-1]   File "/opt/ros/foxy/lib/python3.8/site-packages/rclpy/type_support.py", line 29, in check_for_type_support
[rosp2-1]     msg_type.__class__.__import_type_support__()
[rosp2-1]   File "/home/user/ros2_ws/install/custom_interfaces/lib/python3.8/site-packages/custom_interfaces/srv/_find_wall.py", line 235, in __import_type_support__
[rosp2-1]     module = import_type_support('custom_interfaces')
[rosp2-1]   File "/opt/ros/foxy/lib/python3.8/site-packages/rosidl_generator_py/import_type_support_impl.py", line 48, in import_type_support
[rosp2-1]     raise UnsupportedTypeSupport(pkg_name)
[rosp2-1] rosidl_generator_py.import_type_support_impl.UnsupportedTypeSupport: Could not import 'rosidl_typesupport_c' for package 'custom_interfaces'
[ERROR] [rosp2-1]: process has died [pid 65684, exit code 1, cmd '/home/user/ros2_ws/install/rosp2/lib/rosp2/rosp2 --ros-args'].

which the service interface can be showed correctly

part of the code to import the custom_interfaces.srv FindWall

what could be wrong about? Thx very much!

1 Like

Hi can you share your package.xml ?

rosp2

<?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>rosp2</name>
  <version>0.0.0</version>
  <description>TODO: Package description</description>
  <maintainer email="user@todo.todo">user</maintainer>
  <license>TODO: License declaration</license>

  <depend>rclpy</depend>
  <depend>custom_interfaces</depend>
  <depend>geometry_msgs</depend>
  <depend>sensor_msgs</depend>
  <depend>nav_msgs</depend>

  <test_depend>ament_copyright</test_depend>
  <test_depend>ament_flake8</test_depend>
  <test_depend>ament_pep257</test_depend>
  <test_depend>python3-pytest</test_depend>

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

findwall

<?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>custom_interfaces</name>
  <version>0.0.0</version>
  <description>TODO: Package description</description>
  <maintainer email="user@todo.todo">user</maintainer>
  <license>TODO: License declaration</license>

  <buildtool_depend>ament_cmake</buildtool_depend>

  <depend>rclcpp</depend>
  <depend>std_msgs</depend>
  <depend>action_msgs</depend>
  <depend>geometry_msgs</depend>

  <build_depend>rosidl_default_generators</build_depend>
  <exec_depend>rosidl_default_runtime</exec_depend>
  <member_of_group>rosidl_interface_packages</member_of_group>

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

  <export>
    <build_type>ament_cmake</build_type>
  </export>
</package>

thx

what about your findwall CMakelist ?

cmake_minimum_required(VERSION 3.5)
project(custom_interfaces)

# Default to C99
if(NOT CMAKE_C_STANDARD)
  set(CMAKE_C_STANDARD 99)
endif()

# Default to C++14
if(NOT CMAKE_CXX_STANDARD)
  set(CMAKE_CXX_STANDARD 14)
endif()

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  add_compile_options(-Wall -Wextra -Wpedantic)
endif()

# find dependencies
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(std_msgs REQUIRED)
find_package(geometry_msgs REQUIRED)
find_package(action_msgs REQUIRED)
find_package(rosidl_default_generators REQUIRED)
# uncomment the following section in order to fill in
# further dependencies manually.
# find_package(<dependency> REQUIRED)

if(BUILD_TESTING)
  find_package(ament_lint_auto REQUIRED)
  # the following line skips the linter which checks for copyrights
  # uncomment the line when a copyright and license is not present in all source files
  #set(ament_cmake_copyright_FOUND TRUE)
  # the following line skips cpplint (only works in a git repo)
  # uncomment the line when this package is not in a git repo
  #set(ament_cmake_cpplint_FOUND TRUE)
  ament_lint_auto_find_test_dependencies()
endif()

rosidl_generate_interfaces(${PROJECT_NAME}
  "srv/FindWall.srv"
  "action/OdomRecord.action"
  DEPENDENCIES std_msgs
)


ament_package()

can you share this file as well ?

# import the Twist module from geometry_msgs messages interface
from geometry_msgs.msg import Twist
from custom_interfaces.srv import FindWall
# import the ROS2 python client libraries
import rclpy
from rclpy.node import Node
from sensor_msgs.msg import LaserScan
from nav_msgs.msg import Odometry
from rclpy.qos import ReliabilityPolicy, QoSProfile


class Service(Node):

    def __init__(self):
        # Here we have the class constructor

        # call the class constructor to initialize the node as service_moving
        super().__init__('find_wall')
        # create the service server object
        # defines the type, name and callback function
        self.srv = self.create_service(FindWall, 'findwall', self.FindWallService_callback)
        # create the publisher object
        # in this case the publisher will publish on /cmd_vel topic with a 
				# queue size of 10 messages.
        # use the Twist module
        self.publisher_ = self.create_publisher(Twist, 'cmd_vel', 10)

        # create the subscriber object
        self.subscriber = self.create_subscription(LaserScan, '/scan', self.laser_scan, QoSProfile(depth=10, reliability=ReliabilityPolicy.BEST_EFFORT))
        # prevent unused variable warning
        self.subscriber
        # define the timer period for 0.1 seconds
        self.timer_period = 0.1
        # define the variable to save the received info
        self.laser_minrange = 0
        self.laser_maxrange = 0
        self.laser_forward = 0
        self.laser_backward = 0
        self.laser_right = 0
        self.laser_left = 0

        self.subscriberodom= self.create_subscription(
            Odometry,
            '/odom',
            self.listenerodom_callback,
            QoSProfile(depth=10, reliability=ReliabilityPolicy.BEST_EFFORT))
        self.subscriberodom
        self.orientintheta = 0

        self.robotstate = 0
        

    def FindWallService_callback(self, request, response):
        # The callback function recives the self class parameter, 
        # received along with two parameters called request and response
        # - receive the data by request
        # - return a result as response

        self.timer = self.create_timer(self.timer_period, self.motion)

        # print a pretty message
        self.get_logger().info('To Find Wall!')


        while self.robotstate != 3:
            self.get_logger().info('robot orientation in theta: "%s"' % str(self.orientintheta))
        else:
            self.get_logger().info('Wall founded - rotation stopped!')
            self.destroy_timer(self.timer)
        
        # return the response parameter
        return response

    def laser_scan(self, msg):
        # Save the frontal laser scan info at 180°
        # self.get_logger().info('laser range [] length "%s"' % str(len(msg.ranges)))
        self.laser_minrange = msg.range_min
        self.laser_maxrange = msg.range_max
        self.laser_forward = msg.ranges[180]
        self.laser_backward = msg.ranges[0]
        self.laser_right = msg.ranges[90]
        self.laser_left = msg.ranges[270]


    def listenerodom_callback(self, msg):
        # print the log info in the terminal
        x = msg.pose.pose.orientation.x
        y = msg.pose.pose.orientation.y
        z = msg.pose.pose.orientation.z
        w = msg.pose.pose.orientation.w

        theta = 2 * math.atan2(z, w)
        self.orientintheta = np.degrees(theta)


    def motion(self):
        # print the data
        self.get_logger().info('I receive: "%s"' % str(self.laser_forward))

        orientlist = [self.laser_forward, laser_backward, laser_right, laser_left]

        if self.robotstate == 0:
            if self.laser_forward - min(orientlist) > 0.01:
                self.cmd.angular.z = 0.5
            else:
                self.cmd.linear = 0
                self.cmd.angular = 0
                self.robotstate = 1
            
            self.publisher_.publish(self.cmd)

        if self.robotstate == 1:
            if self.laser_backward > 0.3:
                self.cmd.linear.x = 0.5
            else:
                self.cmd.linear = 0
                self.cmd.angular = 0
                self.robotstate = 2

            self.publisher_.publish(self.cmd)

        if self.robotstate == 2:
            if self.laser_right - min(orientlist) > 0.01:
                self.cmd.angular.z = 0.5
            else:
                self.cmd.linear = 0
                self.cmd.angular = 0
                self.robotstate = 3

            self.publisher_.publish(self.cmd)



def main(args=None):
    # initialize the ROS communication
    rclpy.init(args=args)
    # declare the node constructor
    findwall_service = Service()
    # pause the program execution, waits for a request to kill the node (ctrl+c)
    rclpy.spin(findwall_service)
    # shutdown the ROS communication
    rclpy.shutdown()


if __name__ == '__main__':
    main()

Can you send a screenshot of your file tree with your custom interface package and your rosp2 pkg ? I am still trying to spot the error

Nice, what does the error says in find_wall.py ?

ros2 launch rosp2 find_wall_launch_file.launch.py
[INFO] [launch]: All log files can be found below /home/user/.ros/log/2022-02-22-09-09-23-066018-8_xterm-65520
[INFO] [launch]: Default logging verbosity is set to INFO
[INFO] [rosp2-1]: process started with pid [65684]
[rosp2-1] Traceback (most recent call last):
[rosp2-1]   File "/opt/ros/foxy/lib/python3.8/site-packages/rosidl_generator_py/import_type_support_impl.py", line 46, in import_type_support
[rosp2-1]     return importlib.import_module(module_name, package=pkg_name)
[rosp2-1]   File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
[rosp2-1]     return _bootstrap._gcd_import(name[level:], package, level)
[rosp2-1]   File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
[rosp2-1]   File "<frozen importlib._bootstrap>", line 991, in _find_and_load
[rosp2-1]   File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
[rosp2-1]   File "<frozen importlib._bootstrap>", line 657, in _load_unlocked
[rosp2-1]   File "<frozen importlib._bootstrap>", line 556, in module_from_spec
[rosp2-1]   File "<frozen importlib._bootstrap_external>", line 1166, in create_module
[rosp2-1]   File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
[rosp2-1] ImportError: /home/user/ros2_ws/install/custom_interfaces/lib/libcustom_interfaces__rosidl_generator_c.so: undefined symbol: geometry_msgs__msg__Point__Sequence__init
[rosp2-1]
[rosp2-1] During handling of the above exception, another exception occurred:
[rosp2-1]
[rosp2-1] Traceback (most recent call last):
[rosp2-1]   File "/home/user/ros2_ws/install/rosp2/lib/rosp2/rosp2", line 33,in <module>
[rosp2-1]     sys.exit(load_entry_point('rosp2==0.0.0', 'console_scripts', 'rosp2')())
[rosp2-1]   File "/home/user/ros2_ws/install/rosp2/lib/python3.8/site-packages/rosp2/find_wall.py", line 138, in main
[rosp2-1]     findwall_service = Service()
[rosp2-1]   File "/home/user/ros2_ws/install/rosp2/lib/python3.8/site-packages/rosp2/find_wall.py", line 21, in __init__
[rosp2-1]     self.srv = self.create_service(FindWall, 'findwall', self.FindWallService_callback)
[rosp2-1]   File "/opt/ros/foxy/lib/python3.8/site-packages/rclpy/node.py", line 1295, in create_service
[rosp2-1]     check_for_type_support(srv_type)
[rosp2-1]   File "/opt/ros/foxy/lib/python3.8/site-packages/rclpy/type_support.py", line 29, in check_for_type_support
[rosp2-1]     msg_type.__class__.__import_type_support__()
[rosp2-1]   File "/home/user/ros2_ws/install/custom_interfaces/lib/python3.8/site-packages/custom_interfaces/srv/_find_wall.py", line 235, in __import_type_support__
[rosp2-1]     module = import_type_support('custom_interfaces')
[rosp2-1]   File "/opt/ros/foxy/lib/python3.8/site-packages/rosidl_generator_py/import_type_support_impl.py", line 48, in import_type_support
[rosp2-1]     raise UnsupportedTypeSupport(pkg_name)
[rosp2-1] rosidl_generator_py.import_type_support_impl.UnsupportedTypeSupport: Could not import 'rosidl_typesupport_c' for package 'custom_interfaces'
[ERROR] [rosp2-1]: process has died [pid 65684, exit code 1, cmd '/home/user/ros2_ws/install/rosp2/lib/rosp2/rosp2 --ros-args'].

I mean in the code editor, it seems that you have an error in find_wall.py, something must be underlined in red

Have you tried colcon build after deleting /build and /install and then source install/setup.bash ?

no, should I try it?

1 Like

yes tell me if you get the same error

the same error and I got some warnings when only do colcon build without specify package

warnings are allright

Oh after googling seemed the problem solved by adding DEPENDENCIES in CMakeLists.txt

# find dependencies
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(std_msgs REQUIRED)
find_package(geometry_msgs REQUIRED)
find_package(action_msgs REQUIRED)
---
---
find_package(rosidl_default_generators REQUIRED)

rosidl_generate_interfaces(${PROJECT_NAME}
  "srv/FindWall.srv"
  "action/OdomRecord.action"
  DEPENDENCIES geometry_msgs action_msgs std_msgs
)


This topic was automatically closed after 22 hours. New replies are no longer allowed.