1、使用VSCODE 调试ros2具体设置
1、在下列目录同层级找到.vscode文件夹
├── build
├── install
├── log
└── src
2、 安装ros插件
3、创建tasks.json文件,添加下列内容
{ "version": "2.0.0", "tasks": [ { "label": "catkin_make", //代表提示的描述性信息 "type": "shell", //可以选择shell或者process,如果是shell代码是在shell里面运行一个命令,如果是process代表作为一个进程来运行 // "command": "catkin_make",//这个是我们需要运行的命令 "command": "source /mnt/wenjun.zhao_docker/.wenjun.zhao_docker/code/app/install/setup.bash && colcon build --paths /mnt/wenjun.zhao_docker/.wenjun.zhao_docker/code/app/src/perception/perception_map_engine/tools/mcap_to_geojson --cmake-args -DCMAKE_BUILD_TYPE=Debug", //这个是我们需要运行的命令 // "command": "catkin_make -DCMAKE_TYPE=Release",//这个是我们需要运行的命令 "args": [], //如果需要在命令后面加一些后缀,可以写在这里,比如-DCATKIN_WHITELIST_PACKAGES=“pac1;pac2” "group": { "kind": "build", "isDefault": true }, "presentation": { "reveal": "always" //可选always或者silence,代表是否输出信息 }, "problemMatcher": "$msCompile" } ] }
4、创建launch.json文件,添加下列内容,主要把program对应的文件改成自己的
{ // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "name": "run_mcap_to_geojson", "type": "cppdbg", "request": "launch", "program": "${workspaceFolder}/install/mcap_to_geojson/lib/mcap_to_geojson/mcap_to_geojson_node", "args": [], "stopAtEntry": false, "cwd": "${workspaceFolder}/install/mcap_to_geojson/lib", "environment": [ { "name": "LD_LIBRARY_PATH", "value": "$LD_LIBRARY_PATH:/opt/ros/humble/lib:${workspaceFolder}/install/foxglove_msgs/lib:${workspaceFolder}/install/juefei_shp_check/lib" } ], "externalConsole": false, "MIMode": "gdb", "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true }, { "description": "Set Disassembly Flavor to Intel", "text": "-gdb-set disassembly-flavor intel", "ignoreFailures": true } ] } ] }
5、CMakeList.txt 增加debug编译模式
set(CMAKE_BUILD_TYPE debug)#debug模式,程序不会被优化,速度非常慢
6、编译 ctrl+shift+B 编译
7、在这个界面,选择自己的launch.json 文件中的调试文件名,然后点击运行即可
111