ICode9

精准搜索请尝试: 精确搜索
首页 > 系统相关> 文章详细

Ubuntu20.04 + vscode调试ROS-noetic程序

2022-02-03 21:03:56  阅读:375  来源: 互联网

标签:Ubuntu20.04 noetic vscode apt euroc workspaceFolder vins config


因为经常跨平台开发,所以自从习惯了vscode后,很少换IDE,对于c/c++直接用gdb的情况相对要少了很多。

这里假设各种依赖和相关要调试的程序已经安装好了。算法以VINS-mono为例讲解,其他的其实也是一样的。

安装vscode

Ubuntu上安装vscode可参考官网,

Running Visual Studio Code on Linux我

我把其实的安装那段摘录如下,

Debian and Ubuntu based distributions#

The easiest way to install Visual Studio Code for Debian/Ubuntu based distributions is to download and install the .deb package (64-bit), either through the graphical software center if it's available, or through the command line with:

sudo apt install ./<file>.deb

# If you're on an older Linux distribution, you will need to run this instead:
# sudo dpkg -i <file>.deb
# sudo apt-get install -f # Install dependencies

Note that other binaries are also available on the VS Code download page.

Installing the .deb package will automatically install the apt repository and signing key to enable auto-updating using the system's package manager. Alternatively, the repository and key can also be installed manually with the following script:

wget -qO- https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > packages.microsoft.gpg
sudo install -o root -g root -m 644 packages.microsoft.gpg /etc/apt/trusted.gpg.d/
sudo sh -c 'echo "deb [arch=amd64,arm64,armhf signed-by=/etc/apt/trusted.gpg.d/packages.microsoft.gpg] https://packages.microsoft.com/repos/code stable main" > /etc/apt/sources.list.d/vscode.list'
rm -f packages.microsoft.gpg

Then update the package cache and install the package using:

sudo apt install apt-transport-https
sudo apt update
sudo apt install code # or code-insiders

 使用vscode调试node

我的vins-estimator下面euroc.launch的内容如下,

<launch>
    <arg name="config_path" default = "$(find feature_tracker)/../config/euroc/euroc_config.yaml" />
	  <arg name="vins_path" default = "$(find feature_tracker)/../config/../" />
    
    <node name="feature_tracker" pkg="feature_tracker" type="feature_tracker" output="log">
        <param name="config_file" type="string" value="$(arg config_path)" />
        <param name="vins_folder" type="string" value="$(arg vins_path)" />
    </node>

    <node name="vins_estimator" pkg="vins_estimator" type="vins_estimator" output="screen">
       <param name="config_file" type="string" value="$(arg config_path)" />
       <param name="vins_folder" type="string" value="$(arg vins_path)" />
    </node>

    <node name="pose_graph" pkg="pose_graph" type="pose_graph" output="screen">
        <param name="config_file" type="string" value="$(arg config_path)" />
        <param name="visualization_shift_x" type="int" value="0" />
        <param name="visualization_shift_y" type="int" value="0" />
        <param name="skip_cnt" type="int" value="0" />
        <param name="skip_dis" type="double" value="0" />
    </node>

</launch>

 可以看到有3个节点,vs这个IDE大家应该都会用,配置C++配置文件的过程就不多讲了,直接给结果,如下,

c_cpp_properties.json

{
    "configurations": [
        {
            "name": "Linux",
            "browse": {
                "databaseFilename": "",
                "limitSymbolsToIncludedHeaders": true
            },
            "includePath": [
                "${workspaceFolder}/**",
                "/opt/ros/noetic/include/**",
                "/usr/include/**"
            ],
            "defines": [],
            "compilerPath": "/usr/bin/gcc",
            "cStandard": "gnu17",
            "cppStandard": "gnu++14",
            "intelliSenseMode": "linux-gcc-x64"
        }
    ],
    "version": 4
}

tasks.json

{
    "tasks": [
        {
            "label": "prerun",
            "type": "shell",
            "command": "source ./devel/setup.sh && export ROS_MASTER_URI=http://localhost:11311/ "
        },
        {
            "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"
        }
    ],
    "version": "2.0.0"
}

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": "feature_tracker",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/devel/lib/feature_tracker/feature_tracker",
            "args": ["_config_file:=${workspaceFolder}/src/VINS-Mono/config/euroc/euroc_config.yaml", "_vins_folder:=${workspaceFolder}/src/vins-mono/"],
            "stopAtEntry": false,
            "cwd": "${fileDirname}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "C/C++: g++ 生成活动文件",
            "miDebuggerPath": "/usr/bin/gdb"
        },
        {
            "name": "vins_estimator",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/devel/lib/vins_estimator/vins_estimator",
            "args": ["_config_file:=${workspaceFolder}/src/VINS-Mono/config/euroc/euroc_config.yaml", "_vins_folder:=${workspaceFolder}/src/vins-mono/"],
            "stopAtEntry": false,
            "cwd": "${fileDirname}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        },
        {
            "name": "pose_graph",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/devel/lib/pose_graph/pose_graph",
            "args": ["_config_file:=${workspaceFolder}/src/VINS-Mono/config/euroc/euroc_config.yaml", "_visualization_shift_x:=0", "_visualization_shift_y:=0", "_skip_cnt:=0", "_skip_dis:=0"],
            "stopAtEntry": false,
            "cwd": "${fileDirname}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}

这里要注意,如果老是碰到下面的错误,

Unable to open 'raise.c': Unable to read file '/build/glibc-eX1tMB/glibc-2.31/sysdeps/unix/sysv/linux/raise.c'
 (Error: Unable to resolve nonexistent file '/build/glibc-eX1tMB/glibc-2.31/sysdeps/unix/sysv/linux/raise.c').

    config_file = readParam<std::string>(n, "config_file");
"/home/matthew/projects/vinsmono/src/vins-mono/config/euroc/euroc_config.yaml"

那十有八九是配置不正确,例如在参考贴里用的vins-mono,但我的地址是VINS-Mono,所以就报错了,总之就是要和实际使用的地址一致。

最后,启动的时候,只有那个euroc.launch通过vscode启动,其他的两个直接通过终端启动即可。

roslaunch vins_estimator vins_rviz.launch

roslaunch vins_estimator euroc.launch

rosbag play YOUR_PATH_TO_DATASET/MH_01_easy.bag

这里play最后实际运行的是文件包,以我自己的运行为例,

rosbag play ~/downloads/vinsmono/machine_hall/MH_01_easy/MH_01_easy.bag

参考资料

ROS在线调试(使用GDB) - 古月居

利用vscode调试VINS-FUSION - 知乎

VS Code 调试 VINS-Mono 环境配置_Barry_123的博客-CSDN博客_vscode调试vins

 如何配置VSCode来调试ROS节点_白夜行的狼-CSDN博客_vscode调试ros

标签:Ubuntu20.04,noetic,vscode,apt,euroc,workspaceFolder,vins,config
来源: https://blog.csdn.net/tanmx219/article/details/122772531

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有