本文介绍: 3. 以调试ROS程序为例,可以选择ROS: Attach 或 ROS: Launch。其中,ROS: Attach 表示对一个可执行节点(node) debug,ROS: Launch 表示对一个launch 文件 debug。然后点击这个三角按钮,程序运行,若出现bug, 可自动捕获异常。

具体操作

  1. 修改CMakeList.txt
# set(CMAKE_BUILD_TYPE "Release")//注释Release模式
set(CMAKE_BUILD_TYPE "Debug")//设置为Debug模式
# set(CMAKE_CXX_FLAGS_RELEASE "-O3 -Wall -g")//注释

*这行代码是用来设置 CMake 构建系统中 Release 模式下 C++ 编译器的标志(flags)。
set: 这是 CMake 中用于设置变量的命令,它将一个变量设置为指定的值。
CMAKE_CXX_FLAGS_RELEASE: 这是一个预定义的 CMake 变量,用于存储 Release 模式下 C++ 编译器的标志。
"-O3 -Wall -g": 这是被设置的值,它是一个字符串,包含了一系列的编译器标志。具体解释如下:
-O3: 启用高级优化级别,这通常会提高代码的执行速度。
-Wall: 启用警告信息,让编译器产生更多的警告,帮助开发者发现潜在的问题。
-g: 在生成的可执行文件中包含调试信息,以便在调试时能够获取更多的信息。
因此,这行代码的作用是在 Release 模式下,为 C++ 编译器设置了一些优化和调试相关的标志,以提高代码性能并帮助调试。*
  1. 点击 creat a launch .json file. 在vscdoe右下角会出现一个蓝色按钮“Add Configuration”,点击这个蓝色按钮,创建一个launch.json文件,该文件位于工作空间的.vscode隐藏文件夹下。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": []
}

在这里插入图片描述在这里插入图片描述
3. 以调试ROS程序为例,可以选择ROS: Attach 或 ROS: Launch。其中,ROS: Attach 表示对一个可执行节点(node) debug,ROS: Launch 表示对一个launch 文件 debug。

自动补全选择 ROS: Launch 后的launch.json文件如下,在target: 粘贴launch文件的绝对路径
{
    // 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": "ROS: Launch",
        "type": "ros",
        "request": "launch",
        "target": "absolute path to launch file"
    }]
}

然后点击这个三角按钮,程序运行,若出现bug, 可自动捕获异常
在这里插入图片描述

自动补全选择 ROS: Attach 后的launch.json文件如下,这是需要rosrun pkg type,而后点击三角按钮 attach/连接 到这个节点, 程序运行,若出现bug,  可自动捕获异常
{
    // 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": "ROS: Attach",
        "type": "ros",
        "request": "attach"
    }]
}

原文地址:https://blog.csdn.net/weixin_45736684/article/details/135845156

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。

如若转载,请注明出处:http://www.7code.cn/show_62107.html

如若内容造成侵权/违法违规/事实不符,请联系代码007邮箱:suwngjj01@126.com进行投诉反馈,一经查实,立即删除!

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注