Baidu Apollo代码解析之s-t图的创建与采样(path_time_graph)

百度Apollo中使用Frenet坐标系下的s-t图来帮助分析障碍物的状态(静态、动态)对于自车轨迹规划的影响。典型的如Lattice Planner中,在s-t图中绘制出障碍物占据的s-t区间范围,便可以在范围外采样无碰撞的轨迹点(end condition),然后拟合和评估轨迹,选取最优的输出。

在s-t图中,静态障碍物是矩形块表示,因为直观的,随着时间推移,其s轴位置始终不变;动态障碍物是四边形表示(如果是匀速运动,则是平行四边形),因为随着时间推移,障碍物的s轴位置不断朝着s轴正方向移动,且斜率就是移动的速度。

当感知模块输出检测到的障碍物、预测模块输出预测的n秒内的障碍物可能轨迹后,应该如何创建s-t图呢?path_time_graph类就是解决这个问题的。文件路径:apollo\modules\planning\lattice\behavior\path_time_graph.cc。原理比较简单,就直接贴代码和注释了。

PathTimeGraph::PathTimeGraph(...) {
  ...
  //在构造函数中,给S-T graph添加所有的动静态障碍物
  SetupObstacles(obstacles, discretized_ref_points);
}
void PathTimeGraph::SetupObstacles(
    const std::vector<const Obstacle*>& obstacles,
    const std::vector<PathPoint>& discretized_ref_points) {
  for (const Obstacle* obstacle : obstacles) {
    if (obstacle->IsVirtual()) {
      continue;
    }
    if (!obstacle->HasTrajectory()) {
      //plot a rectangle on s-t graph, representing the static obstacle
      SetStaticObstacle(obstacle, discretized_ref_points);
    } else {
      //plot a parallelogram on s-t graph, representing a dynamic obstacle
      SetDynamicObstacle(obstacle, discretized_ref_points);
    }
  }

  //对静态障碍物的占据范围,按s坐标升序排列
  std::sort(static_obs_sl_boundaries_.begin(), static_obs_sl_boundaries_.end(),
            [](const SLBoundary& sl0, const SLBoundary& sl1) {
              return sl0.start_s() < sl1.start_s();
            });

  for (auto& path_time_obstacle : path_time_obstacle_map_) {
    path_time_obstacles_.push_back(path_time_obstacle.second);
  }
}
/**
 * @brief plot a rectangle on s-t graph, representing the static obstacle
 * @param obstacle
 * @param discretized_ref_points, used to transform the obstacle's polygon(in x-y) to frenet
 */
void PathTimeGraph::SetStaticObstacle(
    const Obstacle* obstacle,
    const std::vector<PathPoint>& discretized_ref_points) {
  const Polygon2d& polygon = obstacle->PerceptionPolygon();

  std::string obstacle_id = obstacle->Id();
  //get the start and end of s&l direction, polygon is in x-y, 
  //so reference line is used to transform the polygon to frenet
  SLBoundary sl_boundary =
      ComputeObstacleBoundary(polygon.GetAllVertices(), discretized_ref_points);

  ...
  //check if the obstacle is in lane, if not in lane, ignore it
  ...

  //plot a static obstacle's occupancy graph on s-t graph, actually a rectangle,
  //so it's ok if the 4 corners are confirmed
  path_time_obstacle_map_[obstacle_id].set_id(obstacle_id);
  path_time_obstacle_map_[obstacle_id].set_bottom_left_point(
      SetPathTimePoint(obstacle_id, sl_boundary.start_s(), 0.0));
  path_time_obstacle_map_[obstacle_id].set_bottom_right_point(SetPathTimePoint(
      obstacle_id, sl_boundary.start_s(), FLAGS_trajectory_time_length));
  path_time_obstacle_map_[obstacle_id].set_upper_left_point(
      SetPathTim
echer@echer:~/application-core$ aem start [INFO] Determine whether host GPU is available ... [INFO] USE_GPU_HOST: 1 [INFO] Start pulling docker image registry.baidubce.com/apollo/apollo-env-gpu:10.0-u22 ... 10.0-u22: Pulling from apollo/apollo-env-gpu Digest: sha256:7c33b27bf30bccf5c13f4d1058c72437930681b646ee0b7bfece979f482a2530 Status: Image is up to date for registry.baidubce.com/apollo/apollo-env-gpu:10.0-u22 registry.baidubce.com/apollo/apollo-env-gpu:10.0-u22 [INFO] Remove existing Apollo Development container ... [INFO] Starting Docker container "apollo_neo_dev_10.0.0_pkg" ... + docker run --gpus all -itd --privileged --name apollo_neo_dev_10.0.0_pkg --label owner=echer -e DISPLAY=:0 -e CROSS_PLATFORM=0 -e DOCKER_USER=echer -e USER=echer -e DOCKER_USER_ID=1000 -e HISTFILE=/apollo_workspace/.cache/.bash_history -e DOCKER_GRP=echer -e DOCKER_GRP_ID=1000 -e DOCKER_IMG=registry.baidubce.com/apollo/apollo-env-gpu:10.0-u22 -e USE_GPU_HOST=1 -e NVIDIA_VISIBLE_DEVICES=all -e NVIDIA_DRIVER_CAPABILITIES=compute,video,graphics,utility -e APOLLO_ENV_CONTAINER_IMAGE=registry.baidubce.com/apollo/apollo-env-gpu:10.0-u22 -e APOLLO_ENV_CONTAINER_PREFIX=apollo_neo_dev_ -e APOLLO_ENV_CONTAINER_REPO=registry.baidubce.com/apollo/apollo-env-gpu -e APOLLO_ENV_CONTAINER_REPO_ARM=registry.baidubce.com/apollo/apollo-env-arm -e APOLLO_ENV_CONTAINER_REPO_X86=registry.baidubce.com/apollo/apollo-env-gpu -e APOLLO_ENV_CONTAINER_TAG=10.0-u22 -e APOLLO_ENV_NAME=10.0.0_pkg -e APOLLO_ENV_WORKLOCAL=1 -e APOLLO_ENV_WORKROOT=/apollo_workspace -e APOLLO_ENV_WORKSPACE=/home/echer/application-core -v /home/echer/.apollo:/home/echer/.apollo -v /dev:/dev -v /media:/media -v /tmp/.X11-unix:/tmp/.X11-unix:rw -v /etc/localtime:/etc/localtime:ro -v /usr/src:/usr/src -v /lib/modules:/lib/modules -v apollo_neo_dev_10.0.0_pkg_apollo:/apollo -v apollo_neo_dev_10.0.0_pkg_opt:/opt -v /home/echer/application-core:/apollo_workspace -v /home/echer/application-core/data:/apollo/data -v /home/echer/application-core/output:/apollo/output -v /home/echer/application-core/data/log:/opt/apollo/neo/data/log -v /home/echer/application-core/data/calibration_data:/apollo/modules/calibration/data -v /home/echer/application-core/data/map_data:/apollo/modules/map/data -v /opt/apollo/neo/packages/env-manager-dev/9.0.0-rc1:/opt/apollo/neo/packages/env-manager-dev/9.0.0-rc1 --net host -w /apollo_workspace --add-host in-dev-docker:127.0.0.1 --add-host echer:127.0.0.1 --hostname in-dev-docker --shm-size 2G --pid=host -v /dev/null:/dev/raw1394 registry.baidubce.com/apollo/apollo-env-gpu:10.0-u22 /bin/bash f2c09881a3913965f5d928b261e2089da4be2f24406b7e69d7b62cb93f40b171 + '[' 0 -ne 0 ']' + set +x Error response from daemon: container f2c09881a3913965f5d928b261e2089da4be2f24406b7e69d7b62cb93f40b171 is not running Error response from daemon: container f2c09881a3913965f5d928b261e2089da4be2f24406b7e69d7b62cb93f40b171 is not running Error response from daemon: container f2c09881a3913965f5d928b261e2089da4be2f24406b7e69d7b62cb93f40b171 is not running Error response from daemon: container f2c09881a3913965f5d928b261e2089da4be2f24406b7e69d7b62cb93f40b171 is not running Error response from daemon: container f2c09881a3913965f5d928b261e2089da4be2f24406b7e69d7b62cb93f40b171 is not running
03-29
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值