自动驾驶的一种数据采集(mcap格式)

自动驾驶的一种数据采集(mcap格式)使用 mcap 存储 proto 序列化文件案例 mcap

大家好,欢迎来到IT知识分享网。

MCAP存储格式是一种用于机器人数据的标准化容器格式。MCAP(发音为“em-cap”),可以用于异构时间戳数据的模块化容器文件格式。它非常适用于机器人应用,因为它可以在单个文件中记录多个流的结构化和非结构化数据(例如ROS、Protobuf、JSON Schema等)。

使用MCAP存储格式优点:

  1. 用于在多种序列化格式(Protobuf、MessagePack、JSON等)中存储数据。
  2. 高性能写入。(采用追加结构,数据可以流式传输到磁盘或网络,无需回溯)
  3. 解码不需要额外的依赖项。(自包含消息模式)
  4. 高效的读取和定位。
  5. 能够轻松集成现有的第三方工具(如Foxglove Studio、Foxglove Data Platform等)。

这里以Protobuf数据保存作为案例:

1. 先给出一个简单的结构体, speed代表车速, acc代表加速度

#include <cstdint> struct Head{ int id; int index; uint64_t timestamp; }; struct Data{ Head head; int speed; float acc; };

2. 接下来用写一个proto存储

syntax = "proto3"; message Head { int32 id = 1; int32 index = 2; uint64 timestamp = 3; } message Data { Head head = 1; int32 speed = 2; float acc = 3; }

3. 用protobuf序列化, 这里序列化为cpp的

// Generated by the protocol buffer compiler. DO NOT EDIT! // source: mcapTest/data.proto #ifndef PROTOBUF_mcapTest_2fdata_2eproto__INCLUDED #define PROTOBUF_mcapTest_2fdata_2eproto__INCLUDED #include <string> #include <google/protobuf/stubs/common.h> #if GOOGLE_PROTOBUF_VERSION <  #error This file was generated by a newer version of protoc which is #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif #if  < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION #error This file was generated by an older version of protoc which is #error incompatible with your Protocol Buffer headers. Please #error regenerate this file with a newer version of protoc. #endif #include <google/protobuf/io/coded_stream.h> #include <google/protobuf/arena.h> #include <google/protobuf/arenastring.h> #include <google/protobuf/generated_message_table_driven.h> #include <google/protobuf/generated_message_util.h> #include <google/protobuf/metadata.h> #include <google/protobuf/message.h> #include <google/protobuf/repeated_field.h> // IWYU pragma: export #include <google/protobuf/extension_set.h> // IWYU pragma: export #include <google/protobuf/unknown_field_set.h> // @@protoc_insertion_point(includes) class Data; class DataDefaultTypeInternal; extern DataDefaultTypeInternal _Data_default_instance_; class Head; class HeadDefaultTypeInternal; extern HeadDefaultTypeInternal _Head_default_instance_; namespace protobuf_mcapTest_2fdata_2eproto { // Internal implementation detail -- do not call these. struct TableStruct { static const ::google::protobuf::internal::ParseTableField entries[]; static const ::google::protobuf::internal::AuxillaryParseTableField aux[]; static const ::google::protobuf::internal::ParseTable schema[]; static const ::google::protobuf::uint32 offsets[]; static void InitDefaultsImpl(); static void Shutdown(); }; void AddDescriptors(); void InitDefaults(); } // namespace protobuf_mcapTest_2fdata_2eproto // ======================

免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。 本文来自网络,若有侵权,请联系删除,如若转载,请注明出处:https://haidsoft.com/129307.html

(0)
上一篇 2025-08-25 13:45
下一篇 2025-08-25 14:00

相关推荐

发表回复

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

关注微信