qp_spline_st_speed_optimizer.cc 4.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/******************************************************************************
 * Copyright 2017 The Apollo Authors. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *****************************************************************************/

/**
 * @file qp_spline_st_speed_optimizer.cc
 **/

D
Dong Li 已提交
21
#include "modules/planning/tasks/qp_spline_st_speed/qp_spline_st_speed_optimizer.h"
22

A
Aaron Xiao 已提交
23 24 25
#include <algorithm>
#include <vector>

26 27
#include "modules/common/proto/pnc_point.pb.h"

28 29 30 31
#include "modules/common/configs/vehicle_config_helper.h"
#include "modules/common/util/file.h"
#include "modules/common/vehicle_state/vehicle_state.h"
#include "modules/planning/common/planning_gflags.h"
D
Dong Li 已提交
32 33
#include "modules/planning/tasks/qp_spline_st_speed/qp_spline_st_graph.h"
#include "modules/planning/tasks/st_graph/st_graph_data.h"
34 35 36 37 38 39 40 41

namespace apollo {
namespace planning {

using Status = apollo::common::Status;
using ErrorCode = apollo::common::ErrorCode;
using TrajectoryPoint = apollo::common::TrajectoryPoint;

42 43
QpSplineStSpeedOptimizer::QpSplineStSpeedOptimizer()
    : SpeedOptimizer("QpSplineStSpeedOptimizer") {}
44

45
bool QpSplineStSpeedOptimizer::Init(const PlanningConfig& config) {
46 47 48
  qp_spline_st_speed_config_ =
      config.em_planner_config().qp_spline_st_speed_config();
  st_boundary_config_ = qp_spline_st_speed_config_.st_boundary_config();
49 50 51
  is_init_ = true;
  return true;
}
52

53
Status QpSplineStSpeedOptimizer::Process(const PathData& path_data,
54
                                         const TrajectoryPoint& init_point,
55
                                         const ReferenceLine& reference_line,
56
                                         PathDecision* const path_decision,
57
                                         SpeedData* const speed_data) {
58 59 60 61
  if (!is_init_) {
    AERROR << "Please call Init() before Process.";
    return Status(ErrorCode::PLANNING_ERROR, "Not init.");
  }
62 63 64 65 66 67 68

  if (path_data.discretized_path().NumOfPoints() == 0) {
    std::string msg("Empty path data");
    AERROR << msg;
    return Status(ErrorCode::PLANNING_ERROR, msg);
  }

69
  StBoundaryMapper boundary_mapper(
70
      st_boundary_config_, reference_line, path_data,
71 72
      qp_spline_st_speed_config_.total_path_length(),
      qp_spline_st_speed_config_.total_time());
73

74
  for (const auto* path_obstacle : path_decision->path_obstacles().Items()) {
75
    DCHECK(path_obstacle->HasLongitudinalDecision());
76
  }
77
  // step 1 get boundaries
78
  std::vector<StBoundary> boundaries;
79 80
  if (boundary_mapper.GetGraphBoundary(*path_decision, &boundaries).code() ==
      ErrorCode::PLANNING_ERROR) {
81
    return Status(ErrorCode::PLANNING_ERROR,
82
                  "Mapping obstacle for qp st speed optimizer failed!");
83
  }
84

85 86
  for (const auto& boundary : boundaries) {
    ADEBUG << "QPST mapped boundary: " << boundary.DebugString() << std::endl;
87
    DCHECK(boundary.boundary_type() != StBoundary::BoundaryType::UNKNOWN);
88 89
  }

90
  SpeedLimit speed_limits;
91
  if (boundary_mapper.GetSpeedLimits(&speed_limits) != Status::OK()) {
92
    return Status(ErrorCode::PLANNING_ERROR,
93
                  "GetSpeedLimits for dp st speed optimizer failed!");
94 95 96
  }

  // step 2 perform graph search
97
  const auto& veh_param =
D
Dong Li 已提交
98
      common::VehicleConfigHelper::GetConfig().vehicle_param();
99
  QpSplineStGraph st_graph(qp_spline_st_speed_config_, veh_param);
100 101

  StGraphData st_graph_data(boundaries, init_point, speed_limits,
102
                            path_data.discretized_path().Length());
103
  if (st_graph.Search(st_graph_data, path_data, speed_data) != Status::OK()) {
104
    RecordSTGraphDebug(boundaries, speed_limits, *speed_data);
105
    return Status(ErrorCode::PLANNING_ERROR,
106 107
                  "Failed to search graph with dynamic programming!");
  }
108
  RecordSTGraphDebug(boundaries, speed_limits, *speed_data);
109 110 111 112 113
  return Status::OK();
}

}  // namespace planning
}  // namespace apollo