基于VS code调试ROS2功能包教程

您所在的位置:网站首页 json调试工具 基于VS code调试ROS2功能包教程

基于VS code调试ROS2功能包教程

2023-04-02 16:34| 来源: 网络整理| 查看: 265

基于VS code调试ROS2功能包教程 1. 安装ROS的vscode插件2. 创建功能包并用vscode插件方式编译3. 调试(基于VScode Debug)4. 示例仓库:5.参考资料

1. 安装ROS的vscode插件

image.png额外可以安装插件:CMake C/C++ 等等

2. 创建功能包并用vscode插件方式编译

编译方式不仅有VScode插件这一种方式,可以通过命令行在终端中进行编译。

$ cd ~ $ mkdir -p learn_ros2_ws/src $ cd learn_ros2_ws/src $ ros2 pkg create cpp_primer_pubsub --build-type ament_cmake --dependencies rclcpp std_msgs $ cd ~/learn_ros2_ws $ code . 方法1:

通过vscode配置 task.json,task.json将位于learn_ros2_ws/.vscode/,快捷键Ctrl+Shift+B编译功能包或者点击Terminal-> Run Build Task.image.pngimage.png

方法二:

按照方式一任意选择配置风格,然后做如下修改:

{ "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" } ] }

3. 调试(基于VScode Debug) 在learn_ros2_ws/.vscode/下创建launch.json

单节点(进程) 调试 – 选择GDB launch方式

image.png

{ // 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": true, "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" } ] }

4. 示例仓库:

https://gitee.com/mingdonghu/vscode-debugger-ros1_2

5.参考资料 ROS2 搭建vscode的debug调试环境 - 古月居Writing a simple publisher and subscriber (C++) — ROS 2 Documentation: Foxy documentation


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3