简体   繁体   English

将Protobuf转换为具有类似功能的ROS消息

[英]Converting Protobuf to ROS messages with similar functionality

I recently inherited a large codebase at work utilizing MOOS & Protobuf messages. 我最近在使用MOOS和Protobuf消息的工作中继承了一个大型代码库。

At the request of my project lead, I am porting it to use exclusively ROS where ROS messages are used instead of protobuf. 在我的项目负责人的要求下,我将其移植到仅使用ROS,其中使用ROS消息而不是protobuf。 The code base heavily relies on utilizing protobuf functionality such as enumerator min / max, extracting a string from the variable field, ->has_variable() function, ->isValid(), etc. 代码库在很大程度上依赖于使用protobuf功能,例如枚举器min / max,从变量字段中提取字符串, - > has_variable()函数, - > isValid()等。

So far I have only been able to find very basic ROS message functionality from the wiki. 到目前为止,我只能从wiki中找到非常基本的ROS消息功能。

Are there any 'hacks' or the like to have this type of pliability? 是否有任何'黑客'或类似的东西具有这种柔韧性?

Example: Protbufs support enumerators, but ROS messages don't, so I have: 示例:Protbufs支持枚举器,但ROS消息没有,所以我有:

  uint8 TYPE_FAILED        = 0
  uint8 TYPE_OPERATIONAL   = 1
  uint8 TYPE_INITIALIZING  = 2

  uint8 health_state_type

My health_state_type is my 'enumerator' but I don't have a min or max unless I hardcode one, and I can't extract TYPE_FAILED as a string. 我的health_state_type是我的'枚举器',但我没有min或max,除非我硬编码,我不能将TYPE_FAILED提取为字符串。 I've been slowly finding workarounds for this by using 我一直在慢慢地通过使用找到解决方法

my_message::custom_msg health;
health.health_state_type = health.TYPE_FAILED

But I'm having to modify many different areas that use it as a string, not integer. 但是我必须修改许多不同的区域,将它用作字符串,而不是整数。

Yes there is a hack. 是的,有一个黑客。 But you need to input a some work into it. 但是你需要输入一些工作。 For using the publisher/subscriber methods in ROS you need to define messages for all topics in .msg files. 要在ROS中使用发布者/订阅者方法,您需要为.msg文件中的所有主题定义消息。

From this file then a C++ class is automatically generated. 从该文件中,将自动生成C ++类。 But you don't want to touch that autogenerated file! 但是你不想触摸那个自动生成的文件! What you could do instead is define your class and associate it with the autogenerated class. 您可以做的是定义您的类并将其与自动生成的类相关联。

Look here for an example how to do it. 在这里查看如何执行此操作的示例。 You could then expand your custom class with desired methods like isValid . 然后,您可以使用isValid等所需方法扩展自定义类。

Another (perhaps simpler) way would be to declare a helper class that would do the desired work for each type in messages. 另一种(也许更简单)的方法是声明一个帮助器类,它将为消息中的每个类型执行所需的工作。

Or you could simply continue to use protobuf. 或者你可以继续使用protobuf。 It is also used at least in Gazebo if not also in ROS. 如果不是在ROS中,它也至少在Gazebo中使用。

Sometime ago I wrote some auto generation scripts that consume Protobufs and produce ROS headers ( not the msg files) to transmit Protobuf blobs over ROS comms. 前段时间我写了一些自动生成脚本,它们使用Protobufs并生成ROS头( 而不是 msg文件)来通过ROS通信传输Protobuf blob。 This would satisfy your need without having to duplicate a Protobuf definition with a supporting ROS msg definition. 这将满足您的需求,而无需复制具有支持ROS msg定义的Protobuf定义。 Code . 代码

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM