dp_poly_path_optimizer.cc 2.6 KB
Newer Older
J
jiangyifei 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/******************************************************************************
 * 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.
 *****************************************************************************/

/**
18
 * @file
J
jiangyifei 已提交
19
 **/
20 21 22

#include "modules/planning/optimizer/dp_poly_path/dp_poly_path_optimizer.h"

J
jiangyifei 已提交
23
#include <string>
J
jiangyifei 已提交
24

25
#include "modules/common/util/file.h"
D
Dong Li 已提交
26
#include "modules/planning/common/planning_gflags.h"
J
jiangyifei 已提交
27 28 29 30 31
#include "modules/planning/optimizer/dp_poly_path/dp_road_graph.h"

namespace apollo {
namespace planning {

32 33 34
using apollo::common::ErrorCode;
using apollo::common::Status;

35 36 37
DpPolyPathOptimizer::DpPolyPathOptimizer(const std::string &name)
    : PathOptimizer(name) {}

38 39 40 41 42 43 44 45 46 47
bool DpPolyPathOptimizer::Init() {
  if (!common::util::GetProtoFromFile(FLAGS_dp_poly_path_config_file,
                                      &config_)) {
    AERROR << "failed to load config file " << FLAGS_dp_poly_path_config_file;
    return false;
  }
  is_init_ = true;
  return true;
}

48 49 50 51 52
Status DpPolyPathOptimizer::Process(const SpeedData &speed_data,
                                    const ReferenceLine &reference_line,
                                    const common::TrajectoryPoint &init_point,
                                    DecisionData *const decision_data,
                                    PathData *const path_data) {
53 54 55 56
  if (!is_init_) {
    AERROR << "Please call Init() before Process().";
    return Status(ErrorCode::PLANNING_ERROR, "Not inited.");
  }
J
jiangyifei 已提交
57 58
  CHECK_NOTNULL(decision_data);
  CHECK_NOTNULL(path_data);
Y
Yajia Zhang 已提交
59
  DPRoadGraph dp_road_graph(config_, init_point, speed_data);
D
Dong Li 已提交
60
  if (!dp_road_graph.FindPathTunnel(reference_line, path_data)) {
D
Dong Li 已提交
61
    AERROR << "Failed to find tunnel in road graph";
D
Dong Li 已提交
62 63 64 65 66 67
    return Status(ErrorCode::PLANNING_ERROR, "dp_road_graph path generation");
  }
  if (!dp_road_graph.ComputeObjectdecision(*path_data, speed_data,
                                           reference_line, decision_data)) {
    AERROR << "Failed to make decision based on tunnel";
    return Status(ErrorCode::PLANNING_ERROR, "dp_road_graph decision ");
D
Dong Li 已提交
68
  }
69
  return Status::OK();
J
jiangyifei 已提交
70 71 72 73
}

}  // namespace planning
}  // namespace apollo