Ask Your Question
2

How to add ROS to path in VS Code?

asked 2017-03-09 01:56:18 -0500

updated 2017-11-23 02:11:39 -0500

Hello,

Is anyone using VS Code to program in ROS? I kind of like this IDE ( haven't used it earlier ) and want to use it as it comes with a lot of features which I like.

My question is when I include <ros/ros.h> it puts a green squiggle below it, and also for service file generated headers it can't really locate them. Any suggestions on how to add on to the path to avoid this.

To be noted, there is no problem in building it as it is already in the path of Linux terminal...

edit retag flag offensive close merge delete

Comments

1

There isn't a section for VS Code on the ROS IDE wiki, but the instructions for one of the other IDEs might provide some hints.

ahendrix gravatar image ahendrix  ( 2017-04-10 01:46:28 -0500 )edit

3 Answers

Sort by » oldest newest most voted
5

answered 2017-11-11 13:08:02 -0500

clyde gravatar image

The IDE wiki now includes an entry for VSCode, which points to a ROS extension. Among other things, this extension will add the appropriate include paths. I tried this and it works nicely.

edit flag offensive delete link more

Comments

If the task provided by the VSCode ROS extension does not work (in my experience that feature is brittle), you might find this answer helpful.

samarth.robo gravatar image samarth.robo  ( 2020-12-14 14:19:27 -0500 )edit
5

answered 2018-07-15 18:14:40 -0500

amer gravatar image

In addition to clyde answer:

1- Open VSCode and (Ctrl+Shift+X) and search for ROS

2- Install ( ROS VSCode Extension )

3- Restart VSCode

4- Make sure to open your workspace ex: file ->openfolder ->catkin_ws

5- The extension will pop up a msg to configure your ROS distro if it cants configure it automatically

6- Also you can use the terminal from VSCode (Ctrl+~) as usual ubuntu terminal

7- Build your catkin workspace at least once from this terminal

8- You can include <ros/ros.h> in your files and you shouldn't see green squiggle below if everything is configured properly.

9- At the left bottom of VSCode you will find [x ROS Master] that's mean ROS core is not running try to run $ roscore from the terminal in VSCode and notice [✔ ROS Master]

edit flag offensive delete link more

Comments

I am trying with simple talker.cpp program. I could not find a way to RUN it. I have followed all your steps. When I debug I get this following error: Unable to start debugging. Program path '/home/catkin_ws/src/beginner_tutorials/scripts/talker.cpp' is missing or invalid.

murali1842 gravatar image murali1842  ( 2018-10-26 16:23:57 -0500 )edit

GDB failed with message: "/home/catkin_ws/src/beginner_tutorials/scripts/talker.cpp": not in executable format: File format not recognized

murali1842 gravatar image murali1842  ( 2018-10-26 16:25:06 -0500 )edit

This may occur if the process's executable was changed after the process was started, such as when installing an update. Try re-launching the application or restarting the machine.

murali1842 gravatar image murali1842  ( 2018-10-26 16:25:20 -0500 )edit

Can you give me some suggestions please...

murali1842 gravatar image murali1842  ( 2018-10-26 16:25:38 -0500 )edit

Im sorry but my vscode cannot configure automatically as well as dont pop up the msg to configure ROS distro. Is there any way to fix this? Anyone helps me!

chrishuynh gravatar image chrishuynh  ( 2020-05-17 12:18:48 -0500 )edit
5

answered 2020-11-30 13:18:05 -0500

Diogo42 gravatar image

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

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2017-03-09 01:56:18 -0500

Seen: 18,559 times

Last updated: Nov 30 '20