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

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 < 3003000
#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 3003000 < 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

// =====================
  • 11
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值