您当前的位置: 首页 >  ar
  • 0浏览

    0关注

    483博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

ROS-Tutorials:rviz之Markers: Sending Basic Shapes (C++,附vscode调试说明)

高精度计算机视觉 发布时间:2022-02-12 10:54:41 ,浏览量:0

官方的教程在这里:rviz/Tutorials/Markers: Basic Shapes - ROS Wikihttps://wiki.ros.org/rviz/Tutorials/Markers%3A%20Basic%20Shapes

我自己在ubuntu20.04上运行时碰到了一些问题,所以记录一下,

mkdir -p prj001/src
cd prj002/src
catkin_create_pkg using_markers roscpp visualization_msgs

这时候会生成下面这样的目录结构:

~/prj001/src/using_markers/src
~/prj001/src/using_markers/include
~/prj001/src/using_markers/CMakeLists.txt

然后建立一个叫basic_shapes.cpp的文件,放在这里,

~/prj001/src/using_markers/src/basic_shapes.cpp

文件内容如下,

#include 
#include 

int main( int argc, char** argv )
{
  ros::init(argc, argv, "basic_shapes");
  ros::NodeHandle n;
  ros::Rate r(1);
  ros::Publisher marker_pub = n.advertise("visualization_marker", 1);

  // Set our initial shape type to be a cube
  uint32_t shape = visualization_msgs::Marker::CUBE;

  while (ros::ok())
  {
    visualization_msgs::Marker marker;
    // Set the frame ID and timestamp.  See the TF tutorials for information on these.
    marker.header.frame_id = "my_frame"; // MandatoryClangd (Alternative intellisense provhttps://blog.csdn.net/tanmx219/article/details/122799015

快捷键ctrl+shift+p,找到C/C++ :Edit configurations (JSON),添加c_cppproperties.json文件,这个文件应该是指定一些路径和语言标准,如下,

c_cpp_properties.json

{
    "configurations": [
        {
            "browse": {
                "databaseFilename": "${workspaceFolder}/.vscode/browse.vc.db",
                "limitSymbolsToIncludedHeaders": false
            },
            "includePath": [
                "/opt/ros/noetic/include/**",
                "/home/matthew/projects/prj001/src/using_markers/include/**",
                "/usr/include/**"
            ],
            "name": "ROS",
            "intelliSenseMode": "gcc-x64",
            "compilerPath": "/usr/bin/gcc",
            "cStandard": "c11",
            "cppStandard": "c++14",
            "configurationProvider": "ms-vscode.cmake-tools"
        }
    ],
    "version": 4
}

快捷键ctrl+shift+p,找到Tasks:Configure Task,添加tasks.json文件,这个文件指定一些catkin_make的编译参数。

注意这里的定义"-DCMAKE_BUILD_TYPE=Debug", 

tasks.json

{
    "tasks": [
        {
            "type": "shell",
            "label": "prerun",
            "command": "source ./devel/setup.sh && export ROS_MASTER_URI=http://localhost:11311/",            
        },
        {
            "type": "shell",
            "label": "catkin_make",
            "command": "catkin_make",
            "args": [
                "--directory",
				"~/projects/prj001/",
				"-DCMAKE_BUILD_TYPE=Debug"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$msCompile"
            ],
            "group": "build",
            "detail": "调试器生成的任务。"
        },
        {
            "label": "Build",
            "dependsOn": [
                "catkin_make",
                "prerun"
            ]
        }
    ],
    "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": "basic_shapes",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/devel/lib/using_markers/basic_shapes",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${fileDirname}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "为 gdb 启用整齐打印",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "catkin_make",
            "miDebuggerPath": "/usr/bin/gdb"
        }
    ]
}

附加说明

如果需要在launch之前运行tasks.json里的任务,就可以加上preLaunchTask这一条,比如这里tasks.json里有一个名字叫"catkin_make",可以通过

"preLaunchTask": "catkin_make"

这样的语句使程序在启动前都编译一次源码。

这样,启动vscode,选择basic_shapes,就可以调试源码了。

 

关注
打赏
1661664439
查看更多评论
0.0395s