基于VScode调试ROS2功能包
1.安装ROS的vscode插件
2.创建功能包并用vscode插件方式编译
1 2 3 4 5 6 7 8 9 10 11 12
| $ cd ~
$ mkdir -p ros2_ws/src
$ cd ros2_ws/src
$ ros2 pkg create cpp__pubsub --build-type ament_cmake --dependencies rclcpp std_msgs
$ cd ~/ros2_ws
$ code .
|
3.配置task.json
通过vscode配置 task.json,task.json将位于ros2_ws/.vscode/,快捷键Ctrl+Shift+B编译功能包或者点击Terminal-> Run Build Task.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| { "version": "2.0.0", "tasks": [ { "type": "colcon", "args": [ "build", "--symlink-install", "--event-handlers", "console_cohesion+", "--base-paths", "/home/linux/learn_ros2_ws", "--cmake-args", "-DCMAKE_BUILD_TYPE=RelWithDebInfo" ], "problemMatcher": [ "$catkin-gcc" ], "group": "build", "label": "colcon: build" } ] }
|
4.配置launch.json
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
| { // 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": "(gdb) Launch", "type": "cppdbg", "request": "launch", "program": "${workspaceFolder}/install/${input:package_name}/lib/${input:package_name}/${input:package_executable}", "args": [], "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [], "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 // } ] } ], "inputs": [ { "id": "package_name", "type": "promptString", "description": "ros2 package name", "default": "cpp_primer_pubsub" }, { "id": "package_executable", "type": "promptString", "description": "ros2 package executable", "default": "talker" } ] }
|
其中
1
| "program": "${workspaceFolder}/install/${input:package_name}/lib/${input:package_name}/${input:package_executable}",
|
“program”为节点路径,如果自动填充出现问题启动不了节点,可以手动填入节点的绝对路径
5.source
在VScode的TERMINAL下cd 到工作空间并source
1
| source install/setup.bash
|
6.开始调试
按快捷键F5开始调试