当前位置: 首页 > news >正文

c++下的ros通信(cmake的报错问题多)

1.自定义msg

这里的自定义msg和python的其实是一样的:
首先在src目录下

catkin_create_pkg car_interfaces rospy roscpp std_msgs message_runtime message_generation

然后新建一个msg文件夹,然后建立相应的msg文件,接着就可以修改编译所需的东西了
定义的msg就自己想怎么写就怎么写吧
首先是CMakeLists.txt:

cmake_minimum_required(VERSION 3.0.2)
project(car_interfaces)## Compile as C++11, supported in ROS Kinetic and newer
# add_compile_options(-std=c++11)## Find catkin macros and libraries
## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz)
## is used, also find other catkin packages
find_package(catkin REQUIRED COMPONENTSmessage_generationmessage_runtimeroscpprospystd_msgs
)add_message_files(FILESGlobalPathPlanningInterface.msgGpsImuInterface.msg
)generate_messages(DEPENDENCIESstd_msgs
)catkin_package(
#  INCLUDE_DIRS include
#  LIBRARIES car_interfacesCATKIN_DEPENDS message_generation message_runtime roscpp rospy std_msgs
#  DEPENDS system_lib
)include_directories(
# include${catkin_INCLUDE_DIRS}
)

然后是package.xml:

<?xml version="1.0"?>
<package format="2"><name>car_interfaces</name><version>0.0.0</version><description>The car_interfaces package</description><!-- One maintainer tag required, multiple allowed, one person per tag --><!-- Example:  --><!-- <maintainer email="jane.doe@example.com">Jane Doe</maintainer> --><maintainer email="cyun@todo.todo">cyun</maintainer><!-- One license tag required, multiple allowed, one license per tag --><!-- Commonly used license strings: --><!--   BSD, MIT, Boost Software License, GPLv2, GPLv3, LGPLv2.1, LGPLv3 --><license>TODO</license><!-- Url tags are optional, but multiple are allowed, one per tag --><!-- Optional attribute type can be: website, bugtracker, or repository --><!-- Example: --><!-- <url type="website">http://wiki.ros.org/car_interfaces</url> --><!-- Author tags are optional, multiple are allowed, one per tag --><!-- Authors do not have to be maintainers, but could be --><!-- Example: --><!-- <author email="jane.doe@example.com">Jane Doe</author> --><!-- The *depend tags are used to specify dependencies --><!-- Dependencies can be catkin packages or system dependencies --><!-- Examples: --><!-- Use depend as a shortcut for packages that are both build and exec dependencies --><!--   <depend>roscpp</depend> --><!--   Note that this is equivalent to the following: --><!--   <build_depend>roscpp</build_depend> --><!--   <exec_depend>roscpp</exec_depend> --><!-- Use build_depend for packages you need at compile time: --><!--   <build_depend>message_generation</build_depend> --><!-- Use build_export_depend for packages you need in order to build against this package: --><!--   <build_export_depend>message_generation</build_export_depend> --><!-- Use buildtool_depend for build tool packages: --><!--   <buildtool_depend>catkin</buildtool_depend> --><!-- Use exec_depend for packages you need at runtime: --><!--   <exec_depend>message_runtime</exec_depend> --><!-- Use test_depend for packages you need only for testing: --><!--   <test_depend>gtest</test_depend> --><!-- Use doc_depend for packages you need only for building documentation: --><!--   <doc_depend>doxygen</doc_depend> --><buildtool_depend>catkin</buildtool_depend><build_depend>message_generation</build_depend><build_depend>message_runtime</build_depend><build_depend>roscpp</build_depend><build_depend>rospy</build_depend><build_depend>std_msgs</build_depend><build_export_depend>roscpp</build_export_depend><build_export_depend>rospy</build_export_depend><build_export_depend>std_msgs</build_export_depend><exec_depend>message_runtime</exec_depend><exec_depend>message_generation</exec_depend><exec_depend>roscpp</exec_depend><exec_depend>rospy</exec_depend><exec_depend>std_msgs</exec_depend><!-- The export tag contains other, unspecified, tags --><export><!-- Other tools can request additional information be placed here --></export>
</package>

基本上就按照这个结构来写,然后正常编译就可以了

2.ros c++联合编程语言

#include<ros/ros.h>
#include<car_interfaces/GlobalPathPlanningInterface.h>
// #include<car_interfaces/GpsImuInterface.h>int main(int argc, char *argv[])
{   ros::init(argc, argv, "plan_node") ;ros::NodeHandle nh;ros::Publisher pub = nh.advertise<car_interfaces::GlobalPathPlanningInterface>("global",10);// ros::Publisher pub2 = nh.advertise<car_interfaces::GpsImuInterface>("gps",10);ros::Rate loop_rate(10);while (ros::ok()){ ROS_INFO("SUCCESS");car_interfaces::GlobalPathPlanningInterface msg1;// car_interfaces::GpsImuInterface msg2;msg1.timestamp = 1000; msg1.process_time = 230;// msg2.gps_time = 10000;pub.publish(msg1);// pub2.publish(msg2);ros::spinOnce(); loop_rate.sleep();} return 0;}

这个是发布的部分,注意思路,将接收的全部开成一个线程,将发布的话题每个都写成一个线程。
然后是发布的数据

#include <ros/ros.h>
#include <car_interfaces/GlobalPathPlanningInterface.h>
#include <car_interfaces/GpsImuInterface.h>// 回调函数
void plan_message_callback(const car_interfaces::GlobalPathPlanningInterface::ConstPtr& msg)
{double timestamp = msg->timestamp;float process_time = msg->process_time;ROS_INFO("Received plan");
}int main(int argc, char* argv[])
{ros::init(argc, argv, "plan_sub");ros::NodeHandle nh;ros::Publisher pub = nh.advertise<car_interfaces::GpsImuInterface>("pub2", 10);ros::Subscriber sub = nh.subscribe("global", 10, plan_message_callback);ros::Rate loop_rate(10);while (ros::ok()){car_interfaces::GpsImuInterface msg;msg.gps_time = 10000;pub.publish(msg);ros::spinOnce();loop_rate.sleep();}return 0;
}

然后修改相应的CMameLists.txt:

cmake_minimum_required(VERSION 3.0.2)
project(planning)## Compile as C++11, supported in ROS Kinetic and newer
# add_compile_options(-std=c++11)## Find catkin macros and libraries
## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz)
## is used, also find other catkin packages
find_package(catkin REQUIRED COMPONENTScar_interfacesroscpprospystd_msgs
)catkin_package(
#  INCLUDE_DIRS include
#  LIBRARIES planning
#  CATKIN_DEPENDS car_interfaces roscpp rospy std_msgs
#  DEPENDS system_lib
)## Specify additional locations of header files
## Your package locations should be listed before other locations
include_directories(
# include${catkin_INCLUDE_DIRS}
)add_executable(${PROJECT_NAME}_node src/plan.cpp)
add_executable(plan_sub_node src/plan_sub.cpp)add_dependencies(${PROJECT_NAME}_node car_interfaces_generate_messages_cpp)# Specify libraries to link a library or executable target against
target_link_libraries(${PROJECT_NAME}_node${catkin_LIBRARIES}
)target_link_libraries(plan_sub_node${catkin_LIBRARIES}
)

package.xml:

<?xml version="1.0"?>
<package format="2"><name>planning</name><version>0.0.0</version><description>The planning package</description><!-- One maintainer tag required, multiple allowed, one person per tag --><!-- Example:  --><!-- <maintainer email="jane.doe@example.com">Jane Doe</maintainer> --><maintainer email="cyun@todo.todo">cyun</maintainer><!-- One license tag required, multiple allowed, one license per tag --><!-- Commonly used license strings: --><!--   BSD, MIT, Boost Software License, GPLv2, GPLv3, LGPLv2.1, LGPLv3 --><license>TODO</license><!-- Url tags are optional, but multiple are allowed, one per tag --><!-- Optional attribute type can be: website, bugtracker, or repository --><!-- Example: --><!-- <url type="website">http://wiki.ros.org/planning</url> --><!-- Author tags are optional, multiple are allowed, one per tag --><!-- Authors do not have to be maintainers, but could be --><!-- Example: --><!-- <author email="jane.doe@example.com">Jane Doe</author> --><!-- The *depend tags are used to specify dependencies --><!-- Dependencies can be catkin packages or system dependencies --><!-- Examples: --><!-- Use depend as a shortcut for packages that are both build and exec dependencies --><!--   <depend>roscpp</depend> --><!--   Note that this is equivalent to the following: --><!--   <build_depend>roscpp</build_depend> --><!--   <exec_depend>roscpp</exec_depend> --><!-- Use build_depend for packages you need at compile time: --><!--   <build_depend>message_generation</build_depend> --><!-- Use build_export_depend for packages you need in order to build against this package: --><!--   <build_export_depend>message_generation</build_export_depend> --><!-- Use buildtool_depend for build tool packages: --><!--   <buildtool_depend>catkin</buildtool_depend> --><!-- Use exec_depend for packages you need at runtime: --><!--   <exec_depend>message_runtime</exec_depend> --><!-- Use test_depend for packages you need only for testing: --><!--   <test_depend>gtest</test_depend> --><!-- Use doc_depend for packages you need only for building documentation: --><!--   <doc_depend>doxygen</doc_depend> --><buildtool_depend>catkin</buildtool_depend><build_depend>car_interfaces</build_depend><build_depend>roscpp</build_depend><build_depend>rospy</build_depend><build_depend>std_msgs</build_depend><build_export_depend>car_interfaces</build_export_depend><build_export_depend>roscpp</build_export_depend><build_export_depend>rospy</build_export_depend><build_export_depend>std_msgs</build_export_depend><exec_depend>car_interfaces</exec_depend><exec_depend>roscpp</exec_depend><exec_depend>rospy</exec_depend><exec_depend>std_msgs</exec_depend><!-- The export tag contains other, unspecified, tags --><export><!-- Other tools can request additional information be placed here --></export>
</package>

以上完成后就可以建立c++的ros通信了

后面要做的事:
1.把这个结构给完全理解并深入掌握
2.按照相应的规则重新写线程

相关文章:

c++下的ros通信(cmake的报错问题多)

1.自定义msg 这里的自定义msg和python的其实是一样的&#xff1a; 首先在src目录下 catkin_create_pkg car_interfaces rospy roscpp std_msgs message_runtime message_generation然后新建一个msg文件夹&#xff0c;然后建立相应的msg文件&#xff0c;接着就可以修改编译所需…...

测试必备 | 测试工程师必知的Linux命令有哪些?

在日常的测试工作中&#xff0c;涉及到测试环境搭建及通过查看日志来定位相关问题时经常会用到Linux&#xff0c;在测试工程师的面试中也经常会有笔试或面试的题目来考查测试人员对Linux的熟悉程度&#xff0c;这里分享下测试工程师需知的 Linux 命令有哪些。 Linux 作为一种常…...

成集云 | 药师帮集成英克ERP接口 | 解决方案

源系统成集云目标系统 业务背景 药师帮是一家专注于医药行业的电商平台&#xff0c;提供医药产品在线采购、销售和物流等一站式服务。药师帮致力于用数字化赋能院外医药市场的参与者&#xff0c;包括药企、药品分销商、药店及基层医疗机构&#xff0c;努力以安全高效…...

ICPC 2022 网络赛 d ( 数位dp + 二分

#include<bits/stdc.h> using namespace std; using VI vector<int>; using ll long long; const int mod 998244353;ll n; int d[100]; int dp[60][40][40][2]; set<int> s; //枚举数位&#xff0c;枚举这一位余数是几 //每一位的限制&#xff0c; int d…...

透视俄乌网络战之二:Conti勒索软件集团(下)

透视俄乌网络战之一&#xff1a;数据擦除软件 透视俄乌网络战之二&#xff1a;Conti勒索软件集团&#xff08;上&#xff09; Conti勒索软件集团&#xff08;下&#xff09; 1. 管理面板源代码2. Pony凭证窃取恶意软件3. TTPs4. Conti Locker v2源代码5. Conti团伙培训材料6. T…...

网络安全深入学习第一课——热门框架漏洞(RCE-命令执行)

文章目录 一、RCE二、命令执行/注入-概述三、命令执行-常见函数四、PHP命令执行-常见函数1、exec&#xff1a;2、system3、passthru4、shell_exec5、反引号 backquote 五、PHP命令执行-常见函数总结六、命令执行漏洞成因七、命令执行漏洞利用条件八、命令执行漏洞分类1、代码层…...

应用在电子体温计中的国产温度传感芯片

电子体温计由温度传感芯片&#xff0c;液晶显示器&#xff0c;纽扣电池&#xff0c;专用集成电路及其他电子元器件组成。能快速准确地测量人体体温&#xff0c;与传统的水银玻璃体温计相比&#xff0c;具有读数方便&#xff0c;测量时间短&#xff0c;测量精度高&#xff0c;能…...

JVM 虚拟机 ----> Java 内存模型(JMM)

文章目录 Java 内存模型&#xff08;JMM&#xff09;一、运行时数据区域划分二、程序计数器&#xff08;Program Counter Register&#xff09;计数器的作用 三、Java 虚拟机栈&#xff08;VM Stack&#xff09;四、本地方法栈&#xff08;Native Method Stack&#xff09;五、…...

指针-字符串替换

任务描述 从标准输入读入数据&#xff0c;每行中最多包含一个字符串 “_xy_”&#xff0c;且除了字符串“_xy_”外&#xff0c;输入数据中不包括下划线字符&#xff0c;请将输入行中的 “_xy_” 替换为 “_ab_”, 在标准输出上输出替换后的结果&#xff1b;若没有进行过满足条…...

docker 网络(单机环境)

文章目录 深入理解 Namespace什么是NamespaceNamespace当中的 Network Namespace Libcontainerdocker 网络基础创建两个命名空间创建网络接口 veth pair命名空间添加 veth 接口为 veth 接口分配 IP启动 veth 接口相互 ping bridge 网络搭建网络环境查看docker0 网桥创建网桥 br…...

14、二叉树的morris遍历等

统计热词 有一个包含100亿个URL的大文件&#xff0c;假设每个URL占用64B&#xff0c;请找出其中所有重复的URL 【补充】 某搜索公司一天的用户搜索词汇是海量的(百亿数据量)&#xff0c;请设计一种求出每天热门Top100 词汇的可行办法 多个小文件的大根堆&#xff0c;然后把每…...

BeanFactory与ApplicationContext

BeanFactory与ApplicationContext的区别 使用Alt Ctrl U查看java类图 什么是BeanFactory接口 他是ApplicationContext的父接口他才是Spring 的核心容器&#xff0c;主要的ApplicationContext功能的实现都间接通过BeanFactory接口来实现 在ApplicationContext类中方法的实现是…...

【计算机网络】 粘包问题

文章目录 为什么会产生粘包问题&#xff1f;解决办法先发包大小再发包内容代码示例 为什么会产生粘包问题&#xff1f; tcp是数据流传输&#xff0c;是一种没有边界的&#xff0c;可以合并的传输数据方式。合并就要能拆开&#xff0c;拆不开就是粘包。 解决办法 设置标志位&a…...

valgrind massif 详解(内存分配释放分析)

参考 https://valgrind.org/docs/manual/ms-manual.html 使用格式 valgrind --toolmassif [--massif-opts] prog [prog-args]目的 记录每一次的malloc, free; 概念: malloc申请内存, 实际分配内存(字节对齐, 分配器的记录头, 等等原因) 对内存进行分析, 优化, 以达到资源…...

使用命令行创建一个vue项目卡住不动如何解决

问题 在使用命令去创建一个vue项目&#xff0c; 出现下面卡住不动的一个状态。 解决方案一 首先先ctrlc停止进入创建好的项目文件手动输入npm install 、npm run dev如果npm run dev 的时候 出现 ‘vite’ 相关的错误查看node版本是否是最新的稳定版本node -v查看安装源是否…...

七天学会C语言-第一天(C语言基本语句)

一、固定格式 这个是C程序的基本框架&#xff0c;需要记住&#xff01;&#xff01;&#xff01; #include<stdio.h>int main(){return 0; }二、printf 语句 简单输出一句C程序&#xff1a; #include<stdio.h> int main(){printf("大家好&#xff0c;&quo…...

vue项目部署,出现两个ip的原因

我宁愿靠自己的力量打开我的前途,而不愿求有力者的垂青。——雨果 tags: 篇首语&#xff1a;本文由小常识网(cha138.com)小编为大家整理&#xff0c;主要介绍了vue项目部署&#xff0c;出现两个ip的原因相关的知识&#xff0c;希望对你有一定的参考价值。 参考技术A 在部署v…...

无涯教程-JavaScript - ASIN函数

描述 ASIN函数返回给定数字的反正弦或反正弦,并返回以弧度表示的Angular,介于-π/2和π/2之间。 语法 ASIN (number)争论 Argument描述Required/OptionalNumberThe sine of the angle you want and must be from -1 to 1.Required Notes 如果您希望ASIN函数返回的Angular以…...

MYSQL的SQL优化

insert语句 开启事务 手动控制事务 start transaction; insert into tb_test values(1,Tom),(2,Cat),(3,Jerry); insert into tb_test values(4,Tom),(5,Cat),(6,Jerry); insert into tb_test values(7,Tom),(8,Cat),(9,Jerry); commit; 内存插入 load命令中用 fields te…...

lintcode 553 · 炸弹袭击【中等 数组+bfs+模拟】

题目 https://www.lintcode.com/problem/553 给定一个二维矩阵, 每一个格子可能是一堵墙 W,或者 一个敌人 E 或者空 0 (数字 0), 返回你可以用一个炸弹杀死的最大敌人数. 炸弹会杀死所有在同一行和同一列没有墙阻隔的敌人。 由于墙比较坚固&#xff0c;所以墙不会被摧毁.你只…...

【JavaEE】-- HTTP

1. HTTP是什么&#xff1f; HTTP&#xff08;全称为"超文本传输协议"&#xff09;是一种应用非常广泛的应用层协议&#xff0c;HTTP是基于TCP协议的一种应用层协议。 应用层协议&#xff1a;是计算机网络协议栈中最高层的协议&#xff0c;它定义了运行在不同主机上…...

通过Wrangler CLI在worker中创建数据库和表

官方使用文档&#xff1a;Getting started Cloudflare D1 docs 创建数据库 在命令行中执行完成之后&#xff0c;会在本地和远程创建数据库&#xff1a; npx wranglerlatest d1 create prod-d1-tutorial 在cf中就可以看到数据库&#xff1a; 现在&#xff0c;您的Cloudfla…...

CMake基础:构建流程详解

目录 1.CMake构建过程的基本流程 2.CMake构建的具体步骤 2.1.创建构建目录 2.2.使用 CMake 生成构建文件 2.3.编译和构建 2.4.清理构建文件 2.5.重新配置和构建 3.跨平台构建示例 4.工具链与交叉编译 5.CMake构建后的项目结构解析 5.1.CMake构建后的目录结构 5.2.构…...

2.Vue编写一个app

1.src中重要的组成 1.1main.ts // 引入createApp用于创建应用 import { createApp } from "vue"; // 引用App根组件 import App from ./App.vue;createApp(App).mount(#app)1.2 App.vue 其中要写三种标签 <template> <!--html--> </template>…...

vue3 字体颜色设置的多种方式

在Vue 3中设置字体颜色可以通过多种方式实现&#xff0c;这取决于你是想在组件内部直接设置&#xff0c;还是在CSS/SCSS/LESS等样式文件中定义。以下是几种常见的方法&#xff1a; 1. 内联样式 你可以直接在模板中使用style绑定来设置字体颜色。 <template><div :s…...

相机从app启动流程

一、流程框架图 二、具体流程分析 1、得到cameralist和对应的静态信息 目录如下: 重点代码分析: 启动相机前,先要通过getCameraIdList获取camera的个数以及id,然后可以通过getCameraCharacteristics获取对应id camera的capabilities(静态信息)进行一些openCamera前的…...

项目部署到Linux上时遇到的错误(Redis,MySQL,无法正确连接,地址占用问题)

Redis无法正确连接 在运行jar包时出现了这样的错误 查询得知问题核心在于Redis连接失败&#xff0c;具体原因是客户端发送了密码认证请求&#xff0c;但Redis服务器未设置密码 1.为Redis设置密码&#xff08;匹配客户端配置&#xff09; 步骤&#xff1a; 1&#xff09;.修…...

使用 Streamlit 构建支持主流大模型与 Ollama 的轻量级统一平台

🎯 使用 Streamlit 构建支持主流大模型与 Ollama 的轻量级统一平台 📌 项目背景 随着大语言模型(LLM)的广泛应用,开发者常面临多个挑战: 各大模型(OpenAI、Claude、Gemini、Ollama)接口风格不统一;缺乏一个统一平台进行模型调用与测试;本地模型 Ollama 的集成与前…...

服务器--宝塔命令

一、宝塔面板安装命令 ⚠️ 必须使用 root 用户 或 sudo 权限执行&#xff01; sudo su - 1. CentOS 系统&#xff1a; yum install -y wget && wget -O install.sh http://download.bt.cn/install/install_6.0.sh && sh install.sh2. Ubuntu / Debian 系统…...

深入浅出深度学习基础:从感知机到全连接神经网络的核心原理与应用

文章目录 前言一、感知机 (Perceptron)1.1 基础介绍1.1.1 感知机是什么&#xff1f;1.1.2 感知机的工作原理 1.2 感知机的简单应用&#xff1a;基本逻辑门1.2.1 逻辑与 (Logic AND)1.2.2 逻辑或 (Logic OR)1.2.3 逻辑与非 (Logic NAND) 1.3 感知机的实现1.3.1 简单实现 (基于阈…...