ROS2 搭建vscode的debug调试环境
【摘要】 0. 前言随着ROS在机器人行业的越来越普及,机器人领域已经和ROS密不可分,无论是单体机器人还是群体机器人。而最近大热的自动驾驶行业也是以ROS为基础进行改动和开发的,但是由于ROS1自身的不足,越来越多的企业开始转投ROS2的怀抱(当然ROS1和ROS2的编程思想类似,所以转起来还是挺方便的)。最近本人也开始转ROS2,而如何科学有效地对ROS2代码的debug调试,看了全网发现都没有...
0. 前言
随着ROS在机器人行业的越来越普及,机器人领域已经和ROS密不可分,无论是单体机器人还是群体机器人。而最近大热的自动驾驶行业也是以ROS为基础进行改动和开发的,但是由于ROS1自身的不足,越来越多的企业开始转投ROS2的怀抱(当然ROS1和ROS2的编程思想类似,所以转起来还是挺方便的)。最近本人也开始转ROS2,而如何科学有效地对ROS2代码的debug调试,看了全网发现都没有合适的,所以作者自行摸索填上了这个坑。
1. vscode安装
这里我们可以借鉴安装ros环境的操作,先进行vscode的安装。
code . #启动vscode
然后在vscode装下以下扩展,并创建文件夹catkin_ws/src
同时此时会出现一个文件夹.vscode,并存在两个json文件:
2. 文件修改
并将下面的代码替换到这两个文件夹中
c_cpp_properties.json
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"/opt/ros/foxy/include/**"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "c99",
"cppStandard": "c++14",
"intelliSenseMode": "clang-x64"
}
],
"version": 4
}
setting.json
{
"editor.tabSize": 8,
"editor.rulers": [
100
],
"files.associations": {
"*.repos": "yaml",
"*.world": "xml",
"*.xacro": "xml",
"chrono": "cpp"
},
// Autocomplete from ros python packages
"python.autoComplete.extraPaths": [
"/opt/ros/foxy/lib/python3.8/site-packages/"
],
// Environment file lets vscode find python files within workspace
"python.envFile": "${workspaceFolder}/.env",
// Use the system installed version of autopep8
"python.formatting.autopep8Path": "/usr/bin/autopep8",
"python.formatting.autopep8Args": [
"--max-line-length=100"
],
"C_Cpp.default.intelliSenseMode": "clang-x64",
"C_Cpp.formatting": "Disabled",
"uncrustify.useReplaceOption": true,
"uncrustify.configPath.linux": "/opt/ros/foxy/lib/python3.8/site-packages/ament_uncrustify/configuration/ament_code_style.cfg",
"cSpell.words": [
"RTPS",
"athackst",
"autopep",
"cmake",
"cppcheck",
"cpplint",
"deque",
"devcontainer",
"ints",
"noqa",
"pytest",
"rclcpp",
"rclpy",
"repos",
"rosdistro",
"rosidl",
"uncrustify",
"xmllint"
],
"search.exclude": {
"**/node_modules": true,
"**/bower_components": true,
"**/*.code-search": true,
"**/build": true,
"**/install": true,
"**/log": true
},
"python.analysis.extraPaths": [
"/opt/ros/foxy/lib/python3.8/site-packages/"
],
"cSpell.allowCompoundWords": true,
"cSpell.ignorePaths": [
"**/package-lock.json",
"**/node_modules/**",
"**/vscode-extension/**",
"**/.git/objects/**",
".vscode",
".vscode-insiders",
".devcontainer/devcontainer.json"
]
}
此时使用Ctrl+Shift+B进行编译即可
然后在Terminal->Configure Default Build Task->catkin_make:build
…详情请参照古月居
【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)