小鱼 ROS 2 新书上线!点击链接查看, 新书配套视频点击链接查看。
提问前必看的发帖注意事项—— 提问前必看!不符合要求的问题拒绝回答!!
社区使用指南—如何添加标签修改密码
jetson ros2-foxy 自定义消息
-
求指教!
我在jetson上用一键安装的代码,安装了ros2-foxy版本,看起来环境没有问题。此时,我自定义了action文件,并用python搭建了一个action server和client。在我本地机器上(x86)上没有问题,但是在Jetson上运行报错(图片上传老是报错,复制的控制台日志):
(py38) nvidia@nvidia-desktop:/mnt/work_dir/robot_ros/modules/grasp_det_action_client_node$ python grasp_action_client.py
Traceback (most recent call last):
File "/opt/ros/foxy/lib/python3.8/site-packages/rosidl_generator_py/import_type_support_impl.py", line 46, in import_type_support
return importlib.import_module(module_name, package=pkg_name)
File "/home/nvidia/archiconda3/envs/py38/lib/python3.8/importlib/init.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 973, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'robot_interfaces.robot_interfaces_s__rosidl_typesupport_c'During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "grasp_action_client.py", line 74, in <module>
main()
File "grasp_action_client.py", line 68, in main
action_client = GraspActionClient()
File "grasp_action_client.py", line 17, in init
self._action_client = ActionClient(self, GraspAction, 'grasp_det')
File "/opt/ros/foxy/lib/python3.8/site-packages/rclpy/action/client.py", line 148, in init
check_for_type_support(action_type)
File "/opt/ros/foxy/lib/python3.8/site-packages/rclpy/type_support.py", line 29, in check_for_type_support
msg_type.class.import_type_support()
File "/mnt/work_dir/robot_ros/install/robot_interfaces/lib/python3.7/site-packages/robot_interfaces/action/_grasp_action.py", line 1186, in import_type_support
module = import_type_support('robot_interfaces')
File "/opt/ros/foxy/lib/python3.8/site-packages/rosidl_generator_py/import_type_support_impl.py", line 48, in import_type_support
raise UnsupportedTypeSupport(pkg_name)
rosidl_generator_py.import_type_support_impl.UnsupportedTypeSupport: Could not import 'rosidl_typesupport_c' for package 'robot_interfaces'
Exception ignored in: <function ActionClient.del at 0xffff9c26b280>
Traceback (most recent call last):
File "/opt/ros/foxy/lib/python3.8/site-packages/rclpy/action/client.py", line 605, in del
self.destroy()
File "/opt/ros/foxy/lib/python3.8/site-packages/rclpy/action/client.py", line 596, in destroy
if self._client_handle is None:
AttributeError: 'ActionClient' object has no attribute '_client_handle'
测试python调用官方自带的 action_tutorials_interfaces.action.Fibonacci
没有问题,用C++调用自定义的action也没有问题,python调用自定义的action就报错。
求各位大佬解惑 -
这是Cmakelist
cmake_minimum_required(VERSION 3.5) project(robot_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) # uncomment the following section in order to fill in # further dependencies manually. # find_package(<dependency> REQUIRED) find_package(rosidl_default_generators REQUIRED) rosidl_generate_interfaces(${PROJECT_NAME} "msg/ObjectDetMsg1.msg" "msg/ObjectDetMsg2.msg" "msg/GraspMsg.msg" "msg/SuperGlueMsg.msg" "action/SuperGlueAction.action" "action/ObjectAction.action" "action/GraspAction.action" ) 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() ament_package()
-
这是package
<?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>robot_interfaces</name> <version>0.0.0</version> <description>TODO: Package description</description> <maintainer email="zr@todo.todo">zr</maintainer> <license>TODO: License declaration</license> <buildtool_depend>ament_cmake</buildtool_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>
-
在初始化的时候就报错了,但是colcon build没有报错,并且ros2 interface show也可以看到到action的内容
import rclpy from rclpy.action import ActionClient from rclpy.node import Node from robot_interfaces.action import GraspAction class GraspActionClient(Node): def __init__(self): super().__init__('Grasp_action_client') self._action_client = ActionClient(self, GraspAction, 'grasp_det')
-
解决了,原因是python版本不匹配的问题
在colcon build的时候,不知道为什么调用的是python3.7(改了默认的系统python路径也不行),导致编译出的so都是py37的。而我运行程序的conda环境是python3.8的,加载so就报错了。所以在colcon build之前,在cmakelist中,set指定下python3.8路径,就可以了 -