srv出现报错
-
使用wsl创建自定义接口时编译不通过
drotheall@Adortheall:~/ros2/CHAT4/server_ws$ colcon build
Starting >>> chat4_interface
--- stderr: chat4_interface
CMake Error at /opt/ros/humble/share/rosidl_adapter/cmake/rosidl_adapt_interfaces.cmake:59 (message):
execute_process(/usr/bin/python3 -m rosidl_adapter --package-name
chat4_interface --arguments-file
/home/drotheall/ros2/CHAT4/server_ws/build/chat4_interface/rosidl_adapter__arguments__chat4_interface.json
--output-dir
/home/drotheall/ros2/CHAT4/server_ws/build/chat4_interface/rosidl_adapter/chat4_interface
--output-file
/home/drotheall/ros2/CHAT4/server_ws/build/chat4_interface/rosidl_adapter/chat4_interface.idls)
returned error code 1:Error processing 'float32 target_x' of 'chat4_interface/Patrol_Request':
''float32' is an invalid message name. It should have the pattern
'^[A-Z][A-Za-z0-9]*$''Traceback (most recent call last):
File "/usr/lib/python3.10/runpy.py", line 196, in _run_module_as_main return _run_code(code, main_globals, None, File "/usr/lib/python3.10/runpy.py", line 86, in _run_code exec(code, run_globals) File "/opt/ros/humble/local/lib/python3.10/dist-packages/rosidl_adapter/__main__.py", line 19, in <module> sys.exit(main()) File "/opt/ros/humble/local/lib/python3.10/dist-packages/rosidl_adapter/main.py", line 53, in main abs_idl_file = convert_to_idl( File "/opt/ros/humble/local/lib/python3.10/dist-packages/rosidl_adapter/__init__.py", line 24, in convert_to_idl return convert_srv_to_idl( File "/opt/ros/humble/local/lib/python3.10/dist-packages/rosidl_adapter/srv/__init__.py", line 28, in convert_srv_to_idl srv = parse_service_string(package_name, input_file.stem, content) File "/opt/ros/humble/local/lib/python3.10/dist-packages/rosidl_adapter/parser.py", line 859, in parse_service_string request_message = parse_message_string( File "/opt/ros/humble/local/lib/python3.10/dist-packages/rosidl_adapter/parser.py", line 520, in parse_message_string Type(type_string, context_package_name=pkg_name), File "/opt/ros/humble/local/lib/python3.10/dist-packages/rosidl_adapter/parser.py", line 277, in __init__ super(Type, self).__init__( File "/opt/ros/humble/local/lib/python3.10/dist-packages/rosidl_adapter/parser.py", line 205, in __init__ raise InvalidResourceName(rosidl_adapter.parser.InvalidResourceName: 'float32' is an invalid
message name. It should have the pattern '^[A-Z][A-Za-z0-9]*$'Call Stack (most recent call first):
/opt/ros/humble/share/rosidl_cmake/cmake/rosidl_generate_interfaces.cmake:130 (rosidl_adapt_interfaces)
CMakeLists.txt:12 (rosidl_generate_interfaces)
Failed <<< chat4_interface [0.74s, exited with code 1]
Summary: 0 packages finished [1.17s]
1 package failed: chat4_interface
1 package had stderr output: chat4_interface

-
消息名首字母要大写
-
@2691336941 找到问题的解决办法了,主要是因为utf8编码的bom导致识别的问题需要删除相关文件以我的文件为例
cd ~/ros2/CHAT4/server_ws/src/chat4_interface/srvsed -i '1s/^\xEF\xBB\xBF//' Patrol.srv