How to setup breakpoints in python scritps for ROS

Hi,
I haved created nodes in pythons scripts and made lanuch directory and modifed the setup files. However, I want to debug the code using Vscode or pycharm. but I do not know how to make the break points work? can you please help in the steps to debug the ros in vscode or pycharm. Thanks

Check this video to learn how to do it with VSCode: Visual Studio Code ROS Extension - Season 1 Episode 5 - Debugging Python - YouTube

1 Like

Is it possible to debug the launch file itself in VS code when we are in ROS2?

It should be possible, since it’s a Python file. How about trying it out and letting us know?

The reason that I ask is that I have tried it before, and it will not work.

The following example is the famous ‘Add two ints example.’
We have the launch.josn.

{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: Debugging in Visual Studio Code
“version”: “0.2.0”,
“configurations”: [
{
“name”: “ROS: Launch debug_go_to_goal_action”,
“type”: “ros”,
“request”: “launch”,
“target”: “/home/bluebird/Documents/InClassProjects/ros3_stu/src/robot_bringup/launch/debug_go_to_goal_action.launch.py”
},
{
“name”: “ROS: add_two_ints_client1_official”,
“type”: “ros”,
“request”: “launch”,
“target”: “/home/bluebird/Documents/InClassProjects/ros3_stu/src/robot_bringup/launch/debug_add_two_ints_official_example.py”
},
]
}

I put two breaking points. One is on the launch file, and the other is on the CPP file.


After we launch it under the support of the ROS plug, it will jump to the breaking point of the CPP file, rather than the launch file.

You may consider that the launch file is a relative simp program. Why bother to debug it?
Well, we are novices. We like the program goes step by step; then, we can check every object that we are interested in.

Ah, I see.

I’m don’t know ros2 processes this launch file internally, but I suspect that it’s being processed in such a way that breakpoints do not work. Are you able debug a regular Python node?

Yes, I can debug regular python files and ament_python files.

By the way, there is a naughty parameter in the ROS plugin of the VS code that I almost forget.

“-DCMAKE_BUILD_TYPE=RelWithDebInfo”

is suggested to be ‘Debug.’ Otherwise, some breakpoints will have no effect.

the video that provided in the first reply was very helpful, I followed the same instructions and worked for me.
in the launch file I have the following code
“version”: “0.2.0”,
“configurations”: [
{
“name”: “ROS: Launch”,
“type”: “ros”,
“request”: “launch”,
“target”: “your path to .launch.py”
}

]

}

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.