Vscode中使用Romote远程开发调试Ros2环境

首先,成功安装ros2环境,参考官方文档中的教程,能用运行出来此处的代码

Writing a simple publisher and subscriber (Python) — ROS 2 Documentation: Iron documentation

下载vscode,进行远程开发,具体参考:Vscode进行远程开发-CSDN博客

在vscode中安装调试ros2所需要的插件,有Python、Pylance、C/C++、CMake Tools、ROS

Vscode中使用Romote远程开发调试Ros2环境_第1张图片

这些插件安装完成之后,我们已经可以在Vscode中自由跳转Python代码和Ros环境中的rclpy包了

Vscode中使用Romote远程开发调试Ros2环境_第2张图片

 之所以能跳转ros环境的包,是因为我们项目文件夹下面的./vscode中settings.json中成功导入了ros环境的位置

Vscode中使用Romote远程开发调试Ros2环境_第3张图片

除了.settings.json文件夹,安装Ros插件后,.vscode文件中会自动有一个c_cpp_properties.json文件,里面也是已经自动填充了内容

Vscode中使用Romote远程开发调试Ros2环境_第4张图片

接下来在.vscode中创建tasks.json文件

Vscode中使用Romote远程开发调试Ros2环境_第5张图片

Vscode中使用Romote远程开发调试Ros2环境_第6张图片

会自动生成tasks.json文件,并且插入内容

Vscode中使用Romote远程开发调试Ros2环境_第7张图片

然后继续在.vscode创建一个文件launch.json文件

{
  // 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": [
    // Example launch of a python file
    {
      "name": "Launch",
      "type": "python",
      "request": "launch",
      "program": "/opt/demo_ws/src/py_pubsub/py_pubsub/publisher_member_function.py", #注意此处改成你自己的要调试的文件路径
      "console": "integratedTerminal",
    },
    // Example gdb launch of a ros executable
    {
      "name": "(gdb) Launch",
      "type": "cppdbg",
      "request": "launch",
      "program": "/opt/demo_ws/py_pubsub/lib/py_pubsub/talker",#此处暂时不太清楚
      "args": [],
      "stopAtEntry": true,
      "cwd": "/opt/demo_ws",
      "externalConsole": false,
      "MIMode": "gdb",
      "setupCommands": [
        {
          "description": "Enable pretty-printing for gdb",
          "text": "-enable-pretty-printing",
          "ignoreFailures": true
        }
      ]
    }
  ],
  "inputs": [
    {
      "id": "package",
      "type": "promptString",
      "description": "Package name",
      "default": "learning_ros2"
    },
    {
      "id": "program",
      "type": "promptString",
      "description": "Program name",
      "default": "ros2_talker"
    }
  ]
}

我们目前只能调试python文件,无法调试 ros executable 。打上断点,即可调试了

Vscode中使用Romote远程开发调试Ros2环境_第8张图片

 

你可能感兴趣的:(vscode,编辑器,机器人)