trajectory_cost.cc 2.5 KB
Newer Older
Y
Yifei Jiang 已提交
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 trjactory_cost.h
 **/

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

J
jiangyifei 已提交
23
#include <algorithm>
Y
Yifei Jiang 已提交
24 25
#include <cmath>

26
#include "modules/common/math/vec2d.h"
27
#include "modules/common/proto/pnc_point.pb.h"
Z
Zhang Liangliang 已提交
28
#include "modules/planning/common/planning_gflags.h"
Y
Yifei Jiang 已提交
29 30 31 32

namespace apollo {
namespace planning {

Z
zhuweicheng 已提交
33 34 35 36
using Box2d = ::apollo::common::math::Box2d;
using Vec2d = ::apollo::common::math::Vec2d;
using TrajectoryPoint = ::apollo::common::TrajectoryPoint;

Z
Zhang Liangliang 已提交
37
TrajectoryCost::TrajectoryCost(const DpPolyPathConfig &config,
38
                               const ReferenceLine &reference_line,
D
Dong Li 已提交
39
                               const common::VehicleParam &vehicle_param,
D
Dong Li 已提交
40
                               const SpeedData &heuristic_speed_data)
Z
zhuweicheng 已提交
41 42 43 44
    : config_(config),
      reference_line_(&reference_line),
      vehicle_param_(vehicle_param),
      heuristic_speed_data_(heuristic_speed_data) {
Y
Yifei Jiang 已提交
45
  const double total_time =
46
      std::min(heuristic_speed_data_.TotalTime(), FLAGS_prediction_total_time);
Y
Yajia Zhang 已提交
47 48

  num_of_time_stamps_ = static_cast<uint32_t>(
D
Dong Li 已提交
49
      std::floor(total_time / config.eval_time_interval()));
Y
Yifei Jiang 已提交
50 51
}

A
Aaron Xiao 已提交
52
double TrajectoryCost::Calculate(const QuinticPolynomialCurve1d &curve,
53 54
                                 const double start_s,
                                 const double end_s) const {
Y
Yifei Jiang 已提交
55
  double total_cost = 0.0;
D
Dong Li 已提交
56
  // path_cost
Z
zhuweicheng 已提交
57 58
  double path_s = 0.0;
  while (path_s < (end_s - start_s)) {
59
    double l = std::fabs(curve.Evaluate(0, path_s));
Z
zhuweicheng 已提交
60
    total_cost += l;
Y
Yifei Jiang 已提交
61

62
    double dl = std::fabs(curve.Evaluate(1, path_s));
Z
zhuweicheng 已提交
63
    total_cost += dl;
64 65
    // TODO(all): add the 5.0 as a parameter into config
    path_s += config_.path_resolution() / 5.0;
D
Dong Li 已提交
66 67
  }
  // obstacle cost
Y
Yifei Jiang 已提交
68 69 70 71
  return total_cost;
}

}  // namespace planning
Z
Zhang Liangliang 已提交
72
}  // namespace apollo