Ask Your Question
1

VSCode debug cpp ROS node

asked 2019-01-22 08:00:31 -0600

Hi,

I am trying to debug my cpp ROS node, based on the microepsilon_scancontrol (I am porting it to the latest driver). I can build with catkin, I can start it, but ofc not perfect (why would it..).

Therefor, I would like to debug it. I am using:

When I start debug I select ROS debugger and run my code with roslaunch (or rosrun, doesn't matter... same result). My node starts in the built-in console, but basically that's it, nothing more. Even if I add some brakepoints, doesn't matter, won't stop, keep running.

What am I missing? Also this automatic include generator doesn't seem to work. glibconfig.h is missing for some reason (I can build my code with catkin_make, so it has to be somewhere). And to be honest it is not really generating all of the includes, vscode offers me to add this and that, but when it comes to glibconfig.h it stops and ask me to add it manually.

Do you guys have some advice how to debug nodes in the given environment?

Thanks!

edit retag flag offensive close merge delete

Comments

run my code with roslaunch (or rosrun, doesn't matter... same result).

Do you mean you type roslaunch/rosrun in the built-in terminal?

Isha Dijcks gravatar imageIsha Dijcks ( 2019-01-22 08:34:09 -0600 )edit

ofc not. debug screen -> play button (or pressing F5), then I select ROS -> roslaunch (or rosrun) -> my package -> launch file. and then it starts a new console.

balint.tahi gravatar imagebalint.tahi ( 2019-01-22 11:15:55 -0600 )edit

2 Answers

Sort by ยป oldest newest most voted
0

answered 2019-01-22 16:07:06 -0600

borgman_jeremy gravatar image

It literally says in the notes for that VS Code extension that breakpoints are not enabled when using Ros Launch or Ros Run.

If you are developing in C++ you can configure VS code to just use GDB: https://code.visualstudio.com/docs/la...

I assume the same can be done for a python debugger but I have not done this.

edit flag offensive delete link more

Comments

Thanks, I was blind ... I have no problems debugging a python code, it is working just fine... but c++ with it tons of includes and catkin_make, then try again, not working, start over was a bit "hassle" for me, so I ended up porting the whole thing to Python... now it is working.

balint.tahi gravatar imagebalint.tahi ( 2019-01-22 16:25:03 -0600 )edit

No problem....BTW if you want to use c++ there is nothing special about ROS with respect to VSCode and the GDB plugin. You can use debug it the same way you would any c++ program with GDB.

borgman_jeremy gravatar imageborgman_jeremy ( 2019-01-22 16:59:08 -0600 )edit

GDB is usable, but with workarounds.. You need to programmatically set your environment variables such as ROS_MASTER_URI, since GDB cannot detect them. Also, you have to attach your debugger to the executable file that is located under /devel/.private/<your_package>/lib/<your_package>/<your_node>.

tahsinkose gravatar imagetahsinkose ( 2019-01-24 01:40:31 -0600 )edit
3

answered 2019-02-11 16:23:16 -0600

sai krishna gravatar image

updated 2019-02-11 16:36:38 -0600

I had the same issue where my simple c++ code projects built with cmake works perfectly fine but not the same c++ file in catkin workspace which uses catkin_make. I had the executable run with out the errors but doesn't stop at my break points to debug my code. Later with the following changes in the launch.json and tasks.json, I could debug my executables(the ones I run using roslaunch or rosrun from terminal) in vscode effortlessly.

Please note to use the below fields correctly in respective json files as those commands are the ones that helps to pipe and enable the code with debugger in vscode and terminal.

*In launch.json--*

  1. "preLaunchTask": "prerun"
  2. "avoidWindowsConsoleRedirection": true
  3. "stopAtEntry": false

In tasks.json --

  1. in Prerun task a. "command": "source ./devel/setup.bash && export ROS_MASTER_URI=http://localhost:11311/ "
  2. In build task a. "command": "catkin config --extend /opt/ros/kinetic && catkin build -DCMAKE_BUILD_TYPE = Debug -j8"

The above changes would hopefully work for anyone struggling with a similar issue. The changes are considered to work assuming the ROS environment is setup with the required extensions and catkin_make is executed without any errors.


************** 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": "${workspaceFolder}/devel/lib/project_folder/executable_file",
            "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
                }
            ]
        }
    ]
}

***************** tasks.json ****************

    {
        // 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",
                "command": "source ./devel/setup.bash && export ROS_MASTER_URI=http://localhost:11311/ "
            },
            {
                "label": "build",
                "type": "shell",
                "command": "catkin config --extend /opt/ros/kinetic && catkin build -DCMAKE_BUILD_TYPE = Debug -j8",
                "group": {
                    "kind": "build",
                    "isDefault": true
                },
                "problemMatcher": []
            },
            {
                "label": "clean",
                "type": "shell",
                "command": "catkin clean --yes"
            },
            {
                "label": "release",
                "type": "shell",
                "command": "sudo checkinstall --install=no catkin build -j4 --cmake--args -DCMAKE_BUILD_TYPE=Release"
            }
        ]

}
edit flag offensive delete link more

Comments

Then I guess when can not use other atributes in ROSLAUNCH like param right?

onlytailei gravatar imageonlytailei ( 2019-12-20 01:26:48 -0600 )edit

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: 2019-01-22 08:00:31 -0600

Seen: 2,956 times

Last updated: Feb 11 '19