如何使用 CLion 为节点设置动态重新配置?

How to set up Dynamic Reconfigure for a Node using CLion?

我已经根据来自 JetBrains 的 link 为 ROS 开发设置了 CLion:https://www.jetbrains.com/help/clion/2018.3/ros-setup-tutorial.html ...我已经成功地完成了一些开发工作。

但是现在是时候根据这个教程用c++开发"Dynamic Reconfigure for a Node"了:http://wiki.ros.org/dynamic_reconfigure/Tutorials/SettingUpDynamicReconfigureForANode%28cpp%29 在使用命令 catkin_make 时,我可以轻松构建所有内容(请参阅下面的文件)。 但是我如何使用 CLion(而不是 catkin_make)构建相同的代码?当我尝试从 CLion 构建此代码时,出现以下错误:

/snap/clion/current/bin/cmake/linux/bin/cmake --build /home/maciej/ros/test_clion/build --target my_server_node -- -j 4
[ 50%] Building CXX object CMakeFiles/my_server_node.dir/nodes/server.cpp.o
/home/maciej/ros/test_clion/src/dynamic_tutorials/nodes/server.cpp:11:10: fatal error: dynamic_tutorials/TutorialsConfig.h: No such file or directory
 #include <dynamic_tutorials/TutorialsConfig.h>
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
CMakeFiles/my_server_node.dir/build.make:62: recipe for target 'CMakeFiles/my_server_node.dir/nodes/server.cpp.o' failed
make[3]: *** [CMakeFiles/my_server_node.dir/nodes/server.cpp.o] Error 1
CMakeFiles/Makefile2:105: recipe for target 'CMakeFiles/my_server_node.dir/all' failed
make[2]: *** [CMakeFiles/my_server_node.dir/all] Error 2
CMakeFiles/Makefile2:112: recipe for target 'CMakeFiles/my_server_node.dir/rule' failed
make[1]: *** [CMakeFiles/my_server_node.dir/rule] Error 2
Makefile:175: recipe for target 'my_server_node' failed
make: *** [my_server_node] Error 2

我的包结构如下:

dynamic_tutorials
---cfg
------Tutorials.cfg
---include
-------dynamic_tutorials (empty)
---nodes
------server.cpp
---CMakeLists.txt
---package.xml

Tutorials.cfg

#!/usr/bin/env python

PACKAGE = "dynamic_tutorials"
from dynamic_reconfigure.parameter_generator_catkin import *

gen = ParameterGenerator()
gen.add("int_param",    int_t,    0, "An Integer parameter", 50,  0, 100)
gen.add("double_param", double_t, 0, "A double parameter",    .5, 0,   1)
gen.add("str_param",    str_t,    0, "A string parameter",  "Hello World")
gen.add("bool_param",   bool_t,   0, "A Boolean parameter",  True)

size_enum = gen.enum([ gen.const("Small",      int_t, 0, "A small constant"),
                       gen.const("Medium",     int_t, 1, "A medium constant"),
                       gen.const("Large",      int_t, 2, "A large constant"),
                       gen.const("ExtraLarge", int_t, 3, "An extra large constant")],
                     "An enum to set size")


gen.add("size", int_t, 0, "A size parameter which is edited via an enum", 1, 0, 3, edit_method=size_enum)


exit(gen.generate(PACKAGE, "dynamic_tutorials", "Tutorials"))

server.cpp

#include <ros/ros.h>

#include <dynamic_reconfigure/server.h>
#include <dynamic_tutorials/TutorialsConfig.h>


void callback(dynamic_tutorials::TutorialsConfig &config, uint32_t level) {
    ROS_INFO("Reconfigure Request: %d %f %s %s %d",
             config.int_param, config.double_param,
             config.str_param.c_str(),
             config.bool_param?"True":"False",
             config.size);
}


int main(int argc, char **argv) {
    ros::init(argc, argv, "dynamic_tutorials");

    dynamic_reconfigure::Server<dynamic_tutorials::TutorialsConfig> server;
    dynamic_reconfigure::Server<dynamic_tutorials::TutorialsConfig>::CallbackType f;

    f = boost::bind(&callback, _1, _2);
    server.setCallback(f);

    ROS_INFO("Spinning node");
    ros::spin();
    return 0;
}

CMakeLists.txt

cmake_minimum_required(VERSION 2.8.3)
project(dynamic_tutorials)


find_package(catkin REQUIRED COMPONENTS
  dynamic_reconfigure
  roscpp
)

generate_dynamic_reconfigure_options(
        cfg/Tutorials.cfg
        #...
)

catkin_package(
#  INCLUDE_DIRS include
#  LIBRARIES dynamic_tutorials
#  CATKIN_DEPENDS dynamic_reconfigure roscpp
#  DEPENDS system_lib
)

include_directories(
# include
  ${catkin_INCLUDE_DIRS}
)

add_executable(my_server_node nodes/server.cpp)
target_link_libraries(my_server_node ${catkin_LIBRARIES})

package.xml

<?xml version="1.0"?>
<package format="2">
  <name>dynamic_tutorials</name>
  <version>0.0.0</version>
  <description>The dynamic_tutorials package</description>

  <!-- One maintainer tag required, multiple allowed, one person per tag -->
  <!-- Example:  -->
  <!-- <maintainer email="jane.doe@example.com">Jane Doe</maintainer> -->
  <maintainer email="maciej@todo.todo">maciej</maintainer>


  <!-- One license tag required, multiple allowed, one license per tag -->
  <!-- Commonly used license strings: -->
  <!--   BSD, MIT, Boost Software License, GPLv2, GPLv3, LGPLv2.1, LGPLv3 -->
  <license>TODO</license>


  <buildtool_depend>catkin</buildtool_depend>
  <build_depend>dynamic_reconfigure</build_depend>
  <build_depend>roscpp</build_depend>
  <build_export_depend>dynamic_reconfigure</build_export_depend>
  <build_export_depend>roscpp</build_export_depend>
  <exec_depend>dynamic_reconfigure</exec_depend>
  <exec_depend>roscpp</exec_depend>


  <!-- The export tag contains other, unspecified, tags -->
  <export>
    <!-- Other tools can request additional information be placed here -->

  </export>
</package>

回答: 1. 在 CLion 中首先构建 "dynamic_tutorials_gencfg"。 2. 现在您可以 build/debug 节点 "my_server_node".

按照 Ros Wiki

中的说明将 add_dependencies(my_server_node ${PROJECT_NAME}_gencfg) 添加到您的 CMakeLists.txt