ubuntu18 vscode ros 配置

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

ubuntu18 vscode ros 配置

cczyd   2021-01-28 我要评论

ubuntu18.04 下ros melodic vscode配置开发环境记录

首先准备可以通过命令行编译通过的ros工作空间及其相应节点并配置好txt文件等。

vscode 插件选择如下 (第一个 ROS 0.6.6)

 

1)在ros工作空间下启动输入 code .启动scode.

2)选择Terminal->configue default build Task打开task.json文件

task.json内容要配置为如下: 

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "shell",
            "command": "catkin_make -DCMAKE_BUILD_TYPE=Debug",
            "problemMatcher": [
                "$catkin-gcc"
            ],
            "group": "build",
            "label": "build",
            "detail": "compiler :  /usr/bin/g++"
        },
    ]
}


c_cpp_properties.json

"cppStandard": "c++17"配置的正确与否直接决定C++ intelligence的代码自动补全功能是否有效

"includePath" 里面包含头文件路径

{
  "configurations": [
    {
      "browse": {
        "databaseFilename": "",
        "limitSymbolsToIncludedHeaders": true
      },
      "includePath": [
        "/opt/ros/melodic/include/**",
        "/usr/include/**"
      ],
      "name": "ROS",
      "intelliSenseMode": "gcc-x64",
      "compilerPath": "/usr/bin/gcc",
      "cStandard": "gnu11",
      "cppStandard": "c++17"
    }
  ],
  "version": 4
}

ctrl+shift+P: Task Run Build Task编译

 

调试:debug选项下create a launch.json file(c++ GDB 调试)注意创建launch.json file文件之后要检查下你之前配置的tasks.json文件有没有被ide修改了,修改了就改回来。

launch.json改为如下,主要制定两个:

"program" :自己工作空间下workspace/devel/lib/节点名/可执行文件

"preLaunchTask":要填成跟tasks.json文件中“label"标签一样的内容。其实直接把这个标签删除也可以。

{
    // 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": "g++ - 生成和调试活动文件",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/devel/lib/myros/myros_node",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "为 gdb 启用整齐打印",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "build",
            "miDebuggerPath": "/usr/bin/gdb"
        }
    ]
}

后面在要调试的cpp文件打断点,在debug选项卡下点击run and Debug就可以开始调试了。

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们