VScode配置Ros环境

VScode配置Ros环境

VScode配置Ros环境

1. VSCode下载

直接百度搜索VScode,去官网安装Ubuntu版本的VScode,下载完成之后用Ububtu Software进行安装。

2. VScode配置

2.1 功能包配置

下载完成之后直接打开ROS的工作目录,之后安装ROS包。
在这里插入图片描述
  C++包
在这里插入图片描述

Cmake tools包
在这里插入图片描述
  如果想配置成汉语的话可以安装Chines(simplifiled)包。
在这里插入图片描述
  安装好中文包之后需要使用快捷键ctrl + shift + p调出命令行工具,搜索Configure Display Language,配置成汉语

2.2 json文件配置

之后需要配置.json文件,点击调试一下,.vscode目录下面会生成四个.json文件:c_cpp_properties.jsonlaunch.jsonsettings.jsontasks.json,不用配置settings.json也可以调试C的代码。

2.2.1 c_cpp_properties.json
{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**",
                "/opt/ros/noetic/include"
            ],
            "defines": [],
            "compilerPath": "/usr/bin/gcc",
            "cStandard": "c11",
            "cppStandard": "c++17",
            "intelliSenseMode": "linux-gcc-x64",
            "compileCommands": "${workspaceFolder}/build/compile_commands.json"
        }
    ],
    "version": 4
}

其中includePath配置中,noetic为ros的版本类型,根据自己的安装版本填写。
  compileCommands中可能会报错,需要在你的src文件目录下的CMakeLists.txt中添加一句话Set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

2.2.2 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}/devel/lib/learning_topic/pose_subscriber",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "为 gdb 启用整齐打印",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}

program中存放的是你需要调试的可执行文件的路径,pose_subscriber是我想要调试的ROS节点,这里可以更改为你想调试的任何一个ros节点。

2.2.4 tasks.json配置
{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "catkin_make", //代表提示的描述性信息
            "type": "shell",  //可以选择shell或者process,如果是shell代码是在shell里面运行一个命令,如果是process代表作为一个进程来运行
            "command": "catkin_make",//这个是我们需要运行的命令
            "args": [],//如果需要在命令后面加一些后缀,可以写在这里,比如-DCATKIN_WHITELIST_PACKAGES=“pac1;pac2”
            "group": {"kind":"build","isDefault":true},
            "presentation": {
                "reveal": "always"//可选always或者silence,代表是否输出信息
            },
            "problemMatcher": "$msCompile"
        },
    ]
}

配置完成后就可以调试ROS节点了。
  ps:如果换成中文之后终端的字体为全角,间隔特别大,在设置里面找Terminal Font Family 里面如果为空的,设置成"monospace" ,需要加引号的!

猜你喜欢

转载自blog.csdn.net/feichangyanse/article/details/132865389