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