鱼香ROS社区
    • 版块
    • 最新
    • 未解决
    • 已解决
    • 群组
    • 注册
    • 登录
    紧急通知:禁止一切关于政治&VPN翻墙等话题,发现相关帖子会立马删除封号
    提问前必看的发帖注意事项: 社区问答规则(小鱼个人)更新 | 高质量帖子发布指南

    launch文件报错

    已定时 已固定 已锁定 已移动
    动手学ROS2
    ros2-foxy ros2 launch文件
    1
    1
    500
    正在加载更多帖子
    • 从旧到新
    • 从新到旧
    • 最多赞同
    回复
    • 在新帖中回复
    登录后回复
    此主题已被删除。只有拥有主题管理权限的用户可以查看。
    • 6437553616
      无痕
      最后由 编辑

      虚拟机安装的ubuntu20.04,ros2版本foxy,在编写launch文件启动节点时遇到如下错误:
      [INFO] [launch]: All log files can be found below /home/daisy/.ros/log/2023-12-07-14-31-39-216423-daisy-VirtualBox-9375
      [INFO] [launch]: Default logging verbosity is set to INFO
      Task exception was never retrieved
      future: <Task finished name='Task-2' coro=<LaunchService._process_one_event() done, defined at /opt/ros/foxy/lib/python3.8/site-packages/launch/launch_service.py:226> exception=InvalidLaunchFileError('py')>
      Traceback (most recent call last):
      File "/opt/ros/foxy/lib/python3.8/site-packages/launch/launch_description_sources/any_launch_file_utilities.py", line 53, in get_launch_description_from_any_launch_file
      return loader(launch_file_path)
      File "/opt/ros/foxy/lib/python3.8/site-packages/launch/launch_description_sources/python_launch_file_utilities.py", line 68, in get_launch_description_from_python_launch_file
      return getattr(launch_file_module, 'generate_launch_description')()
      File "/home/daisy/test2/src/install/print/share/print/launch/print.launch.py", line 9, in generate_launch_description
      return LaunchDescription(generate_launch_description)
      File "/opt/ros/foxy/lib/python3.8/site-packages/launch/launch_description.py", line 55, in init
      self.__entities = list(initial_entities) if initial_entities is not None else []
      TypeError: 'function' object is not iterable

      The above exception was the direct cause of the following exception:

      Traceback (most recent call last):
      File "/opt/ros/foxy/lib/python3.8/site-packages/launch/launch_service.py", line 228, in _process_one_event
      await self.__process_event(next_event)
      File "/opt/ros/foxy/lib/python3.8/site-packages/launch/launch_service.py", line 248, in __process_event
      visit_all_entities_and_collect_futures(entity, self.__context))
      File "/opt/ros/foxy/lib/python3.8/site-packages/launch/utilities/visit_all_entities_and_collect_futures_impl.py", line 45, in visit_all_entities_and_collect_futures
      futures_to_return += visit_all_entities_and_collect_futures(sub_entity, context)
      File "/opt/ros/foxy/lib/python3.8/site-packages/launch/utilities/visit_all_entities_and_collect_futures_impl.py", line 45, in visit_all_entities_and_collect_futures
      futures_to_return += visit_all_entities_and_collect_futures(sub_entity, context)
      File "/opt/ros/foxy/lib/python3.8/site-packages/launch/utilities/visit_all_entities_and_collect_futures_impl.py", line 38, in visit_all_entities_and_collect_futures
      sub_entities = entity.visit(context)
      File "/opt/ros/foxy/lib/python3.8/site-packages/launch/action.py", line 108, in visit
      return self.execute(context)
      File "/opt/ros/foxy/lib/python3.8/site-packages/launch/actions/include_launch_description.py", line 130, in execute
      launch_description = self.__launch_description_source.get_launch_description(context)
      File "/opt/ros/foxy/lib/python3.8/site-packages/launch/launch_description_source.py", line 84, in get_launch_description
      self._get_launch_description(self.__expanded_location)
      File "/opt/ros/foxy/lib/python3.8/site-packages/launch/launch_description_sources/any_launch_description_source.py", line 53, in _get_launch_description
      return get_launch_description_from_any_launch_file(location)
      File "/opt/ros/foxy/lib/python3.8/site-packages/launch/launch_description_sources/any_launch_file_utilities.py", line 56, in get_launch_description_from_any_launch_file
      raise InvalidLaunchFileError(extension, likely_errors=exceptions)
      launch.invalid_launch_file_error.InvalidLaunchFileError: Caught exception when trying to load file of format [py]: 'function' object is not iterable
      daisy@daisy-VirtualBox:~/test2/src$ colcon build --packages-select print
      Starting >>> print
      Finished <<< print [1.24s]

      Summary: 1 package finished [2.34s]
      daisy@daisy-VirtualBox:~/test2/src$ source install/setup.bash
      daisy@daisy-VirtualBox:~/test2/src$ ros2 launch print.launch.py
      Package 'print.launch.py' not found: "package 'print.launch.py' not found, searching: ['/home/daisy/test2/src/install/print', '/home/daisy/test2/src/install/village_interface', '/opt/ros/foxy']"
      daisy@daisy-VirtualBox:~/test2/src$ ros2 launch print print.launch.py
      [INFO] [launch]: All log files can be found below /home/daisy/.ros/log/2023-12-07-14-34-04-971162-daisy-VirtualBox-9556
      [INFO] [launch]: Default logging verbosity is set to INFO
      Task exception was never retrieved
      future: <Task finished name='Task-2' coro=<LaunchService._process_one_event() done, defined at /opt/ros/foxy/lib/python3.8/site-packages/launch/launch_service.py:226> exception=InvalidLaunchFileError('py')>
      Traceback (most recent call last):
      File "/opt/ros/foxy/lib/python3.8/site-packages/launch/launch_description_sources/any_launch_file_utilities.py", line 53, in get_launch_description_from_any_launch_file
      return loader(launch_file_path)
      File "/opt/ros/foxy/lib/python3.8/site-packages/launch/launch_description_sources/python_launch_file_utilities.py", line 68, in get_launch_description_from_python_launch_file
      return getattr(launch_file_module, 'generate_launch_description')()
      File "/home/daisy/test2/src/install/print/share/print/launch/print.launch.py", line 9, in generate_launch_description
      return LaunchDescription(generate_launch_description)
      File "/opt/ros/foxy/lib/python3.8/site-packages/launch/launch_description.py", line 55, in init
      self.__entities = list(initial_entities) if initial_entities is not None else []
      TypeError: 'function' object is not iterable

      The above exception was the direct cause of the following exception:

      Traceback (most recent call last):
      File "/opt/ros/foxy/lib/python3.8/site-packages/launch/launch_service.py", line 228, in _process_one_event
      await self.__process_event(next_event)
      File "/opt/ros/foxy/lib/python3.8/site-packages/launch/launch_service.py", line 248, in __process_event
      visit_all_entities_and_collect_futures(entity, self.__context))
      File "/opt/ros/foxy/lib/python3.8/site-packages/launch/utilities/visit_all_entities_and_collect_futures_impl.py", line 45, in visit_all_entities_and_collect_futures
      futures_to_return += visit_all_entities_and_collect_futures(sub_entity, context)
      File "/opt/ros/foxy/lib/python3.8/site-packages/launch/utilities/visit_all_entities_and_collect_futures_impl.py", line 45, in visit_all_entities_and_collect_futures
      futures_to_return += visit_all_entities_and_collect_futures(sub_entity, context)
      File "/opt/ros/foxy/lib/python3.8/site-packages/launch/utilities/visit_all_entities_and_collect_futures_impl.py", line 38, in visit_all_entities_and_collect_futures
      sub_entities = entity.visit(context)
      File "/opt/ros/foxy/lib/python3.8/site-packages/launch/action.py", line 108, in visit
      return self.execute(context)
      File "/opt/ros/foxy/lib/python3.8/site-packages/launch/actions/include_launch_description.py", line 130, in execute
      launch_description = self.__launch_description_source.get_launch_description(context)
      File "/opt/ros/foxy/lib/python3.8/site-packages/launch/launch_description_source.py", line 84, in get_launch_description
      self._get_launch_description(self.__expanded_location)
      File "/opt/ros/foxy/lib/python3.8/site-packages/launch/launch_description_sources/any_launch_description_source.py", line 53, in _get_launch_description
      return get_launch_description_from_any_launch_file(location)
      File "/opt/ros/foxy/lib/python3.8/site-packages/launch/launch_description_sources/any_launch_file_utilities.py", line 56, in get_launch_description_from_any_launch_file
      raise InvalidLaunchFileError(extension, likely_errors=exceptions)
      launch.invalid_launch_file_error.InvalidLaunchFileError: Caught exception when trying to load file of format [py]: 'function' object is not iterable

      节点程序:
      import rclpy
      from rclpy.node import Node
      from std_msgs.msg import String,UInt32 # 导入消息类型,这里是字符串,整形
      from village_interface.srv import BorrowMoney

      class Print(Node):
      def init(self, name):
      super().init(name)
      # self.get_logger().info("hahhhahha")
      # 发布小说 (话题的类型, 话题的name, 这个参数在研究研究)
      self.pub_novel = self.create_publisher(String, "sexy_girl", 10)
      # 定时发布(周期, 回调hafunction)
      self.count = 0
      self.masage = String()
      self.t = 5
      self.timer = self.create_timer(self.t, self.call_back_fun)

          self.account = 80   #账户
          # 收钱(类型,name,回调函数, 10不懂)
          # self.submoney = self.create_subscription(UInt32,"money", self.money_callback, 10)
          # 创建服务端
          # self.borrow_serve = self.create_service(BorrowMoney, "borrow_money",self.borrowmoney_callback)
      def call_back_fun(self):
          # msg = String()
          self.masage.data = "lala%d,;alal%d" % (self.count, self.count)
          self.pub_novel.publish(self.masage)
          self.get_logger().info("%s" % self.masage.data)
          self.count += 1
      # def money_callback(self, money):
          # self.account += money.data
          # self.get_logger().info("shoudao%d的稿费,现在有%d" % (money.data,self.account))
      

      def borrowmoney_callback(self,requst,response):

      # self.get_logger().info("%s, %d"%(requst.name, self.account))
      # if request.money <= self.account*0.1:
      #    response.success = True
      #    response.money = request.money
      # else:
      #     response.success = False
      #     response.money = 0
      # return response
      

      def main(args = None):

      rclpy.init(args = args)
      # my_print = Node("print")
      # my_print.get_logger().info("lalallalallalal")
      my_print = Print("print")
      rclpy.spin(my_print)
      rclpy.shutdown()
      

      launch 文件:
      from launch import LaunchDescription
      from launch_ros.actions import Node

      def generate_launch_description():
      my_print = Node(
      package = 'print',
      executable = 'my_print'
      )
      return LaunchDescription(generate_launch_description)

      setup 文件:
      from setuptools import setup
      import os
      from glob import glob

      package_name = 'print'

      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,'launch'),glob('launch/*.py'))
      ],
      install_requires=['setuptools'],
      zip_safe=True,
      maintainer='daisy',
      maintainer_email='daisy@todo.todo',
      description='TODO: Package description',
      license='TODO: License declaration',
      tests_require=['pytest'],
      entry_points={
      'console_scripts': [
      "my_print = print.my_print:main"
      ],
      },
      )

      1 条回复 最后回复 回复 引用 0
      • 第一个帖子
        最后一个帖子
      皖ICP备16016415号-7
      Powered by NodeBB | 鱼香ROS