ROS——vscode配置

一、概述

相关扩展

  • 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 or catkin build build tasks.
  • Create catkin packages using catkin_create_pkg script or catkin create pkg.
  • Run rosrun or roslaunch (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:调用

NameCommandDescription
Create Catkin Packageros.createCatkinPackageCreate a catkin package. You can right click on a folder in the explorer to create it in a specific location.
Create Terminalros.createTerminalCreate a terminal with ROS sourced.
Show Core Statusros.showCoreStatusOpen a detail view showing ROS core runtime status.
Start Coreros.startCoreSpawn a ROS core
Stop Coreros.stopCoreTerminate the ROS core
Update C++ Propertiesros.updateCppPropertiesUpdate the C++ include path to include ROS.
Update Python Pathros.updatePythonPathUpdate the Python path to include ROS.
Preview URDFros.previewUrdfPreview URDF and Xacro files. Updates after changes are saved.

三、使用

3.1 导入工作空间

  1. 创建工作空间

    通过makdir -p catkin_ws/src创建工作空间并通过catkin_make编译生成。

  2. 加载工作空间

    必须先生成编译工作空间。

3.2 环境配置

  • 代码提示
  1. 编译输出信息文件
catkin_make -DCMAKE_EXPORT_COMPILE_COMMANDS=Yes
  1. 添加信息文件到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
    • Ctrl+Shift+P键入tasks: Configure Task
    • 选择catkin_make:build
    • Ctrl+Shift+B编译

3.3 调试

3.3.1 单程序调试

调试使用attach模式

Attach toprocess:用于和进程绑定

  1. 新建configuration设置

  2. .vscodelaunch.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. .vscodelaunch.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

  • 29
    点赞
  • 155
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
以下是在VSCode配置ROS环境的步骤: 1. 安装VSCode:首先,你需要下载并安装VSCode编辑器。你可以从VSCode官方网站上下载适用于你的操作系统的安装程序。 2. 安装ROS:接下来,你需要安装ROSROS是一个机器人操作系统,提供了一系列工具和库,用于构建机器人应用程序。你可以从ROS官方网站上找到适用于你的操作系统的安装指南。 3. 安装ROS插件:在VSCode中,你需要安装ROS插件以便与ROS进行集成。打开VSCode,点击左侧的扩展图标(四个方块组成的正方形),在搜索栏中输入"ROS",然后选择"ROS"插件并点击安装。 4. 配置ROS工作区:在VSCode中,你需要创建一个ROS工作区来管理你的ROS项目。在VSCode的菜单栏中,选择"文件" -> "打开文件夹",然后选择一个文件夹作为你的ROS工作区。 5. 配置ROS环境变量:在VSCode中,你需要配置ROS环境变量,以便VSCode能够正确地识别ROS命令和库。在VSCode的菜单栏中,选择"文件" -> "首选项" -> "设置",然后在右侧的设置面板中搜索"环境变量"。点击"编辑 in settings.json",然后在打开的settings.json文件中添加以下代码: ```json "terminal.integrated.env.linux": { "ROS_DISTRO": "your_ros_distro", "ROS_PACKAGE_PATH": "/opt/ros/your_ros_distro/share", "ROS_MASTER_URI": "http://localhost:11311" } ``` 请将"your_ros_distro"替换为你正在使用的ROS发行版的名称(例如"melodic")。 6. 构建和运行ROS项目:在VSCode中,你可以使用ROS插件提供的命令来构建和运行ROS项目。你可以在VSCode的终端中使用ROS命令(例如"catkin_make")来构建你的ROS项目,并使用ROS插件提供的调试功能来调试你的ROS应用程序。 希望这些步骤能帮助你在VSCode中成功配置ROS环境。如果你有任何进一步的问题,请随时提问。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值