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

    3.4.3系统信息获取与发布

    已定时 已固定 已锁定 已移动
    动手学ROS2
    编译出现错误 不知道怎么办
    2
    2
    233
    正在加载更多帖子
    • 从旧到新
    • 从新到旧
    • 最多赞同
    回复
    • 在新帖中回复
    登录后回复
    此主题已被删除。只有拥有主题管理权限的用户可以查看。
    • Z
      zqq 年度VIP
      最后由 编辑

      fishros@fishros-linux:~/chapt3/topic_practice_ws$ ros2 run status_publisher sys_status_pub
      Traceback (most recent call last):
      File "/home/fishros/chapt3/topic_practice_ws/install/status_publisher/lib/status_publisher/sys_status_pub", line 33, in <module>
      sys.exit(load_entry_point('status-publisher==0.0.0', 'console_scripts', 'sys_status_pub')())
      File "/home/fishros/chapt3/topic_practice_ws/install/status_publisher/lib/python3.10/site-packages/status_publisher/sys_status_pub.py", line 39, in main
      rclpy.spin(node)
      File "/opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/init.py", line 226, in spin
      executor.spin_once()
      File "/opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/executors.py", line 739, in spin_once
      self._spin_once_impl(timeout_sec)
      File "/opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/executors.py", line 736, in _spin_once_impl
      raise handler.exception()
      File "/opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/task.py", line 239, in call
      self._handler.send(None)
      File "/opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/executors.py", line 437, in handler
      await call_coroutine(entity, arg)
      File "/opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/executors.py", line 351, in _execute_timer
      await await_or_execute(tmr.callback)
      File "/opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/executors.py", line 107, in await_or_execute
      return callback(*args)
      File "/home/fishros/chapt3/topic_practice_ws/install/status_publisher/lib/python3.10/site-packages/status_publisher/sys_status_pub.py", line 28, in timer_callback
      msg.memory_total = memory_info.total
      File "/home/fishros/chapt3/topic_practice_ws/install/status_interfaces/local/lib/python3.10/dist-packages/status_interfaces/msg/_system_status.py", line 227, in memory_total
      assert
      AssertionError: The 'memory_total' field must be of type 'float'
      [ros2run]: Process exited with failure 1

      1 条回复 最后回复 回复 引用 0
      • 小伊小
        机器人小伊
        最后由 编辑

        这个错误信息表明在发布系统状态信息时遇到了一个问题,具体是在设置 memory_total 字段的值时发生了断言错误(AssertionError)。错误信息指出 'memory_total' field must be of type 'float',这意味着 memory_total 字段的值必须是浮点数类型,但是在你的代码中可能传递了一个非浮点数的值。

        错误发生在 status_publisher 包的 sys_status_pub.py 文件的第 28 行,在 timer_callback 函数中。这个函数尝试从某个地方获取内存信息(可能是通过 memory_info.total),并将这个值赋给消息对象的 memory_total 字段。

        要解决这个问题,你可以按照以下步骤操作:

        1. 检查数据类型:确保 memory_info.total 的值是浮点数。如果 memory_info.total 是整数或其他类型,你需要将其转换为浮点数。例如,可以使用 float(memory_info.total) 来确保它是浮点数。

        2. 修改代码:在 sys_status_pub.py 文件的第 28 行,修改代码如下:

          msg.memory_total = float(memory_info.total)
          

          如果 memory_info.total 已经是浮点数,这行代码不会改变其值,但如果它是整数或其他类型,这将会进行类型转换。

        3. 重新编译并运行:在做了上述修改后,重新编译你的 ROS 2 包(如果之前已经编译过),然后再次运行你的节点来查看问题是否解决。

        4. 调试:如果问题仍然存在,检查 memory_info 对象的来源和它是如何被赋值的。确保在赋值给 msg.memory_total 之前,memory_info.total 的值是正确的类型。

        通过这些步骤,你应该能够解决这个类型不匹配的问题,并使你的 ROS 2 节点能够正确发布系统状态信息。


        以上为生成回答,仅供参考~

        我是小伊,已接入ChatGpt,所有回复,仅供参考~

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