Apollo6.0代码Lattice算法详解——Part1:离散化参考线

0.前置知识

        要理解该部分代码需要了解一下protobuf中定义的PathPoint具体内容, 如下:

message PathPoint {
  // coordinates
  optional double x = 1;
  optional double y = 2;
  optional double z = 3;

  // direction on the x-y plane
  optional double theta = 4;
  // curvature on the x-y planning
  optional double kappa = 5;
  // accumulated distance from beginning of the path
  optional double s = 6;

  // derivative of kappa w.r.t s.
  optional double dkappa = 7;
  // derivative of derivative of kappa w.r.t s.
  optional double ddkappa = 8;
  // The lane ID where the path point is on
  optional string lane_id = 9;

  // derivative of x and y w.r.t parametric parameter t in CosThetareferenceline
  optional double x_derivative = 10;
  optional double y_derivative = 11;
}

        代码位置: modules/common/proto/pnc_point.proto

1.涉及主要函数

        1) 函数名: ToDiscretizedReferenceLine(const std::vector< ReferencePoint >& ref_points)
            函数位置: modules/planning/planner/lattice/lattice_planner.cc
            函数作用: 离散化参考线的点

2.函数关系

        该部分主要涉及函数就一个 ToDiscretizedReferenceLine, 故没有画关系图.

3.函数代码详解

    3.1 lattice_planner.cc中代码部分

  // 离散化参考线的点
  // 1. obtain a reference line and transform it to the PathPoint format.
  auto ptr_reference_line =
      std::make_shared<std::vector<PathPoint>>(ToDiscretizedReferenceLine(
          reference_line_info->reference_line().reference_points()));

    3.2 函数-ToDiscretizedReferenceLine

// 相当于把referenceLine的点放到vector<PathPoint>中去,顺带计算了总长度
std::vector<PathPoint> ToDiscretizedReferenceLine(
    const std::vector<ReferencePoint>& ref_points) {
  double s = 0.0;
  std::vector<PathPoint> path_points;
  for (const auto& ref_point : ref_points) { // 把参考线上的很多点都拿出来放到path_points容器中
    PathPoint path_point;
    // 下面这几个貌似是跟据高精地图算的,B站视频提到的
    path_point.set_x(ref_point.x());
    path_point.set_y(ref_point.y());
    path_point.set_theta(ref_point.heading());
    path_point.set_kappa(ref_point.kappa());
    path_point.set_dkappa(ref_point.dkappa());

    // 如果不是第一次在path_points压入点的话, 累计一下s值
    if (!path_points.empty()) {
      double dx = path_point.x() - path_points.back().x();
      double dy = path_point.y() - path_points.back().y();
      s += std::sqrt(dx * dx + dy * dy);
    }
    path_point.set_s(s);
    path_points.push_back(std::move(path_point));
  }
  return path_points;
}

4.参考资料

         1.参考视频: Lattice.
         2.参考文章: Apollo中Lattice规划器结构梳理.

  • 4
    点赞
  • 35
    收藏
    觉得还不错? 一键收藏
  • 9
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值