明明.srv、package.xml和CMakeLists.txt都一一对照没有问题,但是就是编译不通过。
将功能包换到另外一个工作空间下又能编译成功,我之前还以为是没有将环境变量写入到.bashrc的原因。结果今天才发现问题出在工作空间的路径有中文。
其他的功能包可以在中文路径下正常编译,但是定义通信接口的功能包不行!
另外,附上依赖std_msgs的一个自定义通信接口:
Jabocian.srv:
# request
float64[] theta # theta角度
---
# response
std_msgs/Float64MultiArray jabocian # 求和结果
CMakeLists.txt:
cmake_minimum_required(VERSION 3.8)
project(arm_interface)
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(std_msgs REQUIRED) # 1.有用到就需要加(非必须)
find_package(rosidl_default_generators REQUIRED) # 2.必须
rosidl_generate_interfaces(${PROJECT_NAME} # 3.必须
"srv/Jabocian.srv"
DEPENDENCIES std_msgs # 有用到就需要加(非必须)
)
if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
# the following line skips the linter which checks for copyrights
# comment the line when a copyright and license is added to all source files
set(ament_cmake_copyright_FOUND TRUE)
# the following line skips cpplint (only works in a git repo)
# comment the line when this package is in a git repo and when
# a copyright and license is added to all source files
set(ament_cmake_cpplint_FOUND TRUE)
ament_lint_auto_find_test_dependencies()
endif()
ament_package()
package.xml:
<?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>arm_interface</name>
<version>0.0.0</version>
<description>TODO: Package description</description>
<maintainer email="mi@todo.todo">mi</maintainer>
<license>TODO: License declaration</license>
<buildtool_depend>ament_cmake</buildtool_depend>
<depend>std_msgs</depend>
<test_depend>ament_lint_auto</test_depend>
<test_depend>ament_lint_common</test_depend>
<build_depend>rosidl_default_generators</build_depend>
<exec_depend>rosidl_default_runtime</exec_depend>
<member_of_group>rosidl_interface_packages</member_of_group>
<export>
<build_type>ament_cmake</build_type>
</export>
</package>