1. map_file模块介绍及代码解析

在这里插入图片描述map_file模块主要负责读取pcd点云文件和csv语义地图文件,解析并将其转换成描述地图信息的topic发送给rviz和其他功能模块
在这里插入图片描述

1. points_map_loader源码解析

根据话题points_map搜索,找到pcd_pub

pcd_pub = nh.advertise<sensor_msgs::PointCloud2>("points_map", 1, true);
void publish_pcd(sensor_msgs::PointCloud2 pcd, const int* errp = NULL)
{
  if (pcd.width != 0)
  {
    pcd.header.frame_id = "map";
    pcd_pub.publish(pcd);

    if (errp == NULL || *errp == 0)
    {
      stat_msg.data = true;
      stat_pub.publish(stat_msg);
    }
  }
}
  if (area == "noupdate")
    margin = -1;

由于 area == “noupdate” 故 margin = -1

  if (margin < 0)
  {
    int err = 0;
    publish_pcd(create_pcd(pcd_file_paths, &err), &err);
  }

通过读取pcd文件来实现points_map的发布

2. vector_map_loader源码解析

以cross_walk_pub为例

 //完成csv文件的解析后将各种矢量信息发布出去
 ros::Publisher cross_walk_pub = nh.advertise<CrossWalkArray>("vector_map_info/cross_walk", 1, true);
else if (file_name == "crosswalk.csv")
{
  // 读取"crosswalk.csv"文件中数据,创建一个ObjectArray,并且通过cross_walk_pub发布
  cross_walk_pub.publish(createObjectArray<CrossWalk, CrossWalkArray>(file_path));
  category |= Category::CROSS_WALK;
}
U createObjectArray(const std::string& file_path)
{
  U obj_array;
  // NOTE: Autoware want to use map messages with or without /use_sim_time.
  // Therefore we don't set obj_array.header.stamp.
  // obj_array.header.stamp = ros::Time::now();
  obj_array.header.frame_id = "map";
  obj_array.data = vector_map::parse<T>(file_path);// 通过这个函数来解析读取csv文件中的元素信息,返回一个array结构的变量
  return obj_array;
}
template <class T>
std::vector<T> parse(const std::string& csv_file)
{
  std::ifstream ifs(csv_file.c_str());
  std::string line;
  std::getline(ifs, line);  // 第一行是标题,所以移除它 remove first line
  std::vector<T> objs;
  while (std::getline(ifs, line))
  {
    T obj;
    std::istringstream iss(line);
    iss >> obj;
    objs.push_back(obj);
  }
  return objs;
}

读取csv文件中的数值,将数值转存到中CrossWalk.msg

# type
uint8 CLOSURE_LINE=0
uint8 STRIPE_PATTERN=1
uint8 BICYCLE_LANE=2

# Ver 1.00
int32 id
int32 aid
int32 type
int32 bdid
int32 linkid
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值