ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

For ROS to work completely in Vscode, without an external plugin.

First. change "C_Cpp.intelliSenseEngine": "Tag Parser" for autocomplete: image description

in .vscode folder, make or change tasks.json for build, clean and prepare for debug.

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "prerun",
            "type": "shell",
            "dependsOn": [
                "build package only"
            ],
            "command": "source ../../devel/setup.bash && export ROS_MASTER_URI=http://localhost:11311/ "
        },
        {
            "label": "build all packages",
            "type": "shell",
            "command": "cd ~/catkin_ws/ && catkin config --extend /opt/ros/noetic && catkin build -DCMAKE_BUILD_TYPE=Debug -j8",
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "problemMatcher": []
        },
        {
            "label": "build package only",
            "type": "shell",
            "command": "cd ~/catkin_ws/ && catkin config --extend /opt/ros/noetic && catkin build ${workspaceFolderBasename} -DCMAKE_BUILD_TYPE=Debug -j8",
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "problemMatcher": []
        },
        {
            "label": "clean",
            "type": "shell",
            "command": "cd ~/catkin_ws/ && catkin clean --yes"
        },
        {
            "label": "release",
            "type": "shell",
            "command": "sudo checkinstall --install=no catkin build -j4 --cmake--args -DCMAKE_BUILD_TYPE=Release"
        }
    ]
}

In the file c_cpp_properties.json add include files propriety

{
    "configurations": [
        {
            "browse": {
                "databaseFilename": "",
                "limitSymbolsToIncludedHeaders": true
            },
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**",
                "/opt/ros/noetic/include/**",
                "~/catkin_ws/devel/include/**"
            ],
            "defines": [],
            "compilerPath": "/usr/bin/gcc",
            "cStandard": "gnu17",
            "cppStandard": "gnu++14",
            "intelliSenseMode": "gcc-x64"
        }
    ],
    "version": 4
}

For debug, make ou change 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": [
        {
            "name": "(gdb) launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${env:HOME}/catkin_ws/devel/lib/${workspaceFolderBasename}/${fileBasenameNoExtension}",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "preLaunchTask": "prerun",
            "MIMode": "gdb",
            "targetArchitecture": "x64",
            "avoidWindowsConsoleRedirection": true,
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}

Final result:

image description