VScode中配置ROS开发环境

本文介绍了如何在Visual Studio Code(VScode)中配置ROS开发环境,包括安装ROS插件、创建工作空间、新建ROS功能包以及配置launch.json和tasks.json文件,以实现代码编译、运行和调试。通过VScode,可以更便捷地进行ROS功能包的开发和调试。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

VScode中配置ROS开发环境

前言

目前机器人领域很多开源代码都是基于 r o s ros ros 下功能包的形式,所以需要一个好的 I D E IDE IDE 来方便阅读和编译。
以前有个 I D E IDE IDE R o b o w a r e Roboware Roboware,是专门为 r o s ros ros 工作空间开发的一个 I D E IDE IDE,但是用起来不是很方便,而且现在已经停止维护了。
经搜索得知, V S c o d e VScode VScode 中可以非常方便地安装 r o s ros ros 插件,用于基于 r o s ros ros 的功能包开发。
下面就记录一下配置过程。

配置过程

首先,安装好 V S c o d e VScode VScode r o s ros ros,我现在使用的是 u b u n t u 18.04 ubuntu18.04 ubuntu18.04,安装的是 r o s − m e l o d i c ros-melodic rosmelodic 版本。

VScode中安装插件

首先在 V S c o d e VScode VScode 中点击左侧栏中的 E x t e n s i o n s Extensions Extensions
在这里插入图片描述
在搜索栏里搜索 r o s ros ros,点击安装。
在这里插入图片描述
用同样的方式,安装以下插件。其中 Chinese(Simplified)是字体转换插件,可以自由选择变不变字体。
在这里插入图片描述

脚本配置

V S c o d e VScode VScode 开发 r o s ros ros 功能包时,工作空间还是得提前建好,然后用 V S c o d e VScode VScode
打开。这里新建一个工作空间进行说明。

新建工作空间
mkdir -p ~/catkin_ws/src
cd ~/catkin_ws/src
catkin_init_workspace
cd ~/catkin_ws/
catkin_make
V S c o d e VScode VScode 打开该文件夹

点击 V S c o d e VScode VScode 下的打开文件夹,选中新建立的工作空间,打开。
打开以后,点击到 s r c src src上,右键选择 C r e a t e    C a t k i n    P a c k a g e Create\;Catkin\;Package CreateCatkinPackage,即可新建一功能包。
在这里插入图片描述
这里就不介绍怎么建立功能包了,建立过程可以参考这篇博客 link

配置

V S c o d e VScode VScode 中打开工作空间后,会看到目录中有个 . v s c o d e .vscode .vscode 文件夹,里面有两个 j s o n json json 文件:

c_cpp_properties.json
settings.json

这时还需要在 . v s c o d e .vscode .vscode 文件夹下新建两个 j s o n json json 文件。
首先新建 l a u n c h . j s o n launch.json 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}/*",
            "args": [],
            "stopAtEntry": true,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        },
    ]
}

新建 t a s k s . j s o n tasks.json tasks.json 文件,在这个文件中键入以下内容:

{
	"version": "2.0.0",
	"tasks": [
		{
			"label": "source",
			"type": "shell",
			"command": "source /opt/ros/melodic/setup.bash;"
		},
		{
			"label": "catkin_make",
			"type": "shell",
			"command": "echo $PATH; source /opt/ros/melodic/setup.bash; echo $PATH;whereis catkin_make; catkin_make",
			"group": {
				"kind": "build",
				"isDefault": true
			},
			"dependsOrder": "sequence",
			"dependsOn": [
				"source"
			],
			"problemMatcher": []
		}
	]
}

添加完这些文件,就可以利用 V S c o d e VScode VScode 进行对工作空间进行编译,对功能包代码运行,调试了。
例如,打开终端,启动节点即可看到节点运行结果。
在这里插入图片描述

总结

V S c o d e VScode VScode 调试 r o s ros ros 功能包过程如下:首先用 V S c o d e VScode VScode 打开工作空间所在文件及,然后在 . v s c o d e .vscode .vscode 文件夹下新建 l a u n c h . j s o n launch.json launch.json 文件和 t a s k s . j s o n tasks.json tasks.json 文件这两个 j s o n json json 文件。完成后就可以在 . v s c o d e .vscode .vscode 中打开终端运行了。
发现跳转是太方便啦!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值