一、概述
相关扩展
- C/C++
- Python
- CMake
- CMake Tools
- vscode-icons:给不同类型文件设置图标
- ROS
vscode-ros vscode-ros是在vscode上用于辅助ros开发的插件,因roboware不再更新所以切换到vscode平台。
- 不会修改工作空间文件目录结构(roboware会改变目录结构,手动创建的无法导入roboware,roboware创建的也无法通过
catkin_make
手动编译) - 可以断点调试(测试存在局限性)
- 支持ros2.0
- 提供ros代码对齐(
Ctrl+Shift+I
选择ros) - 需要手动修改
CMakeList.txt
官方说明
Getting Started
The extension will automatically start when you open a catkin workspace. The build system (e.g. catkin_make or catkin build) will automatically be confirmed from the hidden files associated with each system. The ROS distro will automatically be confirmed from the parent environment, or you will be prompted to select a ROS distro if this can’t be done automatically. You must build the catkin workspace at least once before the extension will recognise it. To start ROS core, use the “ROS: Start Core” command. The “ROS Core” indicator in the bottom left will show if the core is currently running, and you can click on this to view parameters etc. The first time you open the workspace the extension will automatically create build and test tasks and update the C++ and Python paths. You can re-run this process later using the appropriate commands.
Features
- Automatic ROS environment configuration.
- Allows starting, stopping and viewing the ROS core status.
- Automatically discover
catkin_make
orcatkin build
build tasks. - Create catkin packages using
catkin_create_pkg
script orcatkin create pkg
. - Run
rosrun
orroslaunch
(breakpoints currently not supported). - Syntax highlighting for
.msg
,.urdf
and other ROS files. - Automatically add the ROS C++ include and Python import paths.
- Format C++ using the ROS
clang-format
style. - Preview URDF and Xacro files.
- Debug a single ROS node (C++ or Python) by attaching to the process.
- Debug ROS nodes (C++ or Python) launched from a
.launch
file.
二、命令
Ctrl+p
打开指令面板,>ros:
调用
Name | Command | Description |
---|---|---|
Create Catkin Package | ros.createCatkinPackage |
Create a catkin package. You can right click on a folder in the explorer to create it in a specific location. |
Create Terminal | ros.createTerminal |
Create a terminal with ROS sourced. |
Show Core Status | ros.showCoreStatus |
Open a detail view showing ROS core runtime status. |
Start Core | ros.startCore |
Spawn a ROS core |
Stop Core | ros.stopCore |
Terminate the ROS core |
Update C++ Properties | ros.updateCppProperties |
Update the C++ include path to include ROS. |
Update Python Path | ros.updatePythonPath |
Update the Python path to include ROS. |
Preview URDF | ros.previewUrdf |
Preview URDF and Xacro files. Updates after changes are saved. |
三、使用
3.1 导入工作空间
1.创建工作空间 通过makdir -p catkin_ws/src
创建工作空间并通过catkin_make
编译生成。 2.加载工作空间 必须先生成编译工作空间。
3.2 环境配置
- 代码提示
- 编译输出信息文件
catkin_make -DCMAKE_EXPORT_COMPILE_COMMANDS=Yes
2.添加信息文件到c_cpp_properties.json
文件中(最后一句)
"name": "ROS",
"intelliSenseMode": "gcc-x64",
"compilerPath": "/usr/bin/g++",
"cStandard": "c11",
"cppStandard": "c++11",
"compileCommands": "${workspaceFolder}/build/compile_commands.json"
注意:若无代码提示显示,使用Ctrl+space
- 编译
1.手动编译 2.创建task 1.Ctrl+Shift+P
键入tasks: Configure Task
2.选择catkin_make:build
3.Ctrl+Shift+B
编译
3.3 调试
3.3.1 单程序调试
调试使用attach
模式
Attach toprocess:用于和进程绑定
1.新建configuration
设置 2.在.vscode
的launch.josn
添加ROS: Attach
3.编译程序(生成类型必须为RelWithDebInfo
) SET(CMAKE_BUILD_TYPE "RelWithDebInfo")
4.通过>ros::run
运行程序(也可以手动运行,需要加载环境) 5.运行ROS:Attach
,选择运行程序进入断点调试模式
- 创建
ROS:Attach
- 调试python
- 调试c++
3.3.2 多程序调试
1.创建launch文件,调用调试的节点
<launch>
<node pkg = "beginner_tutorials" type = "talker" name="talker_cpp"/>
<node pkg = "beginner_tutorials" type = "listener" name="listener_cpp"/>
</launch>
2.在.vscode
的launch.josn
添加ROS: Launch
,"target"
设置为launch文件的绝对路径 3.运行ROS:Launch
,选择运行程序进入断点调试模式
- 创建
ROS:Launch
实际测试时需要手动修改路径,不会有选项出现。
- 启动并检查master
- 调试节点
参考
VS调试技巧 之 attach to process ros项目调试:vscode下配置开发ROS项目 A Decent Integration of VSCode to ROS