一、修改CMakeLists.txt文件
分别在/src、/src/cartographer、/src/cartographer_ros/cartographer_ros、
/src/cartographer_ros/cartographer_ros_msgs、/src/cartographer_ros/cartographer_rviz目录下的CMakeLists.txt文件的project下添加:SET(CMAKE_BUILD_TYPE Debug)。
二、编译
编译命令使用:
catkin_make_isolated --install --use-ninja -DFORCE_DEBUG_BUILD=True
若编译报错,可尝试删除所有过程文件、重启。
三、VSCode配置文件
c_cpp_properties.json和settings.json文件会通过ROS插件自动生成。launch.json文件
通过点击Debug图标、Add Configuration、ROS: Launch自动生成:
{
"name": "ROS: Launch",
"request": "launch",
"target": "/home/jzq/catkin_ws/install_isolated/share/cartographer_ros/launch/mylaunch.launch",
"launch": ["rviz", "gz", "gzclient", "gzserver"],
"type": "ros",
}
task.json文件使情况选择是否配置(Terminal、Configure Default Build Task),如果每次改动之后手动编译则不需要,否则需要在其中设置编译命令:
{
"version": "2.0.0",
"tasks": [
{
"type": "catkin_make_isolated",
"args": [
"--install",
"--use-ninja",
"-DFORCE_DEBUG_BUILD=True",
],
"problemMatcher": [
"$catkin-gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"label": "catkin_make_isolated: build"
},
// 下面的task按需使用
{
"label": "make_debug_and_core",
"dependsOn": [
"catkin_make_isolated: build",
"roscore: roscore", // This task is provided by vscode-ros,开启主节点
]
},
]
}
然后就可以打断点开始调试了,通过这种方式可以同时调试多个node。