reference_line_info.h 5.4 KB
Newer Older
D
Dong Li 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/******************************************************************************
 * 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
 **/

#ifndef MODULES_PLANNING_COMMON_REFERENCE_LINE_INFO_H_
#define MODULES_PLANNING_COMMON_REFERENCE_LINE_INFO_H_

24
#include <limits>
D
Dong Li 已提交
25
#include <list>
D
Dong Li 已提交
26
#include <memory>
D
Dong Li 已提交
27
#include <string>
28
#include <unordered_set>
D
Dong Li 已提交
29 30
#include <vector>

31
#include "modules/common/proto/pnc_point.pb.h"
32
#include "modules/common/proto/vehicle_state.pb.h"
33 34
#include "modules/planning/proto/planning.pb.h"

35
#include "modules/map/pnc_map/pnc_map.h"
D
Dong Li 已提交
36 37 38
#include "modules/planning/common/path/path_data.h"
#include "modules/planning/common/path_decision.h"
#include "modules/planning/common/speed/speed_data.h"
39
#include "modules/planning/common/trajectory/discretized_trajectory.h"
D
Dong Li 已提交
40 41 42 43 44 45

namespace apollo {
namespace planning {

class ReferenceLineInfo {
 public:
46 47
  explicit ReferenceLineInfo(const common::VehicleState& vehicle_state,
                             const common::TrajectoryPoint& adc_planning_point,
48
                             const ReferenceLine& reference_line,
49
                             const hdmap::RouteSegments& segments);
50

51 52
  bool Init();

D
Dong Li 已提交
53
  bool AddObstacles(const std::vector<const Obstacle*>& obstacles);
D
Dong Li 已提交
54 55
  PathObstacle* AddObstacle(const Obstacle* obstacle);

56 57 58
  PathDecision* path_decision();
  const PathDecision& path_decision() const;
  const ReferenceLine& reference_line() const;
59
  const common::TrajectoryPoint& AdcPlanningPoint() const;
60

61
  bool ReachedDestination() const;
D
Dong Li 已提交
62

63
  void SetTrajectory(const DiscretizedTrajectory& trajectory);
64

65
  const DiscretizedTrajectory& trajectory() const;
66
  double TrajectoryLength() const;
67

68
  double Cost() const { return cost_; }
69
  void AddCost(double cost) { cost_ += cost; }
70
  void SetCost(double cost) { cost_ = cost; }
71

72
  /**
D
Dong Li 已提交
73 74 75
   * @brief check if current reference line is started from another reference
   *line info line. The method is to check if the start point of current
   *reference line is on previous reference line info.
76 77 78
   * @return returns true if current reference line starts on previous reference
   *line, otherwise false.
   **/
D
Dong Li 已提交
79
  bool IsStartFrom(const ReferenceLineInfo& previous_reference_line_info) const;
80

81 82 83 84
  planning_internal::Debug* mutable_debug() { return &debug_; }
  const planning_internal::Debug& debug() const { return debug_; }
  LatencyStats* mutable_latency_stats() { return &latency_stats_; }
  const LatencyStats& latency_stats() const { return latency_stats_; }
85

86 87 88 89 90 91
  const PathData& path_data() const;
  const SpeedData& speed_data() const;
  PathData* mutable_path_data();
  SpeedData* mutable_speed_data();
  // aggregate final result together by some configuration
  bool CombinePathAndSpeedProfile(
92
      const double relative_time, const double start_s,
93
      DiscretizedTrajectory* discretized_trajectory);
94

95
  const SLBoundary& AdcSlBoundary() const;
96 97
  std::string PathSpeedDebugString() const;

D
Dong Li 已提交
98 99 100 101 102 103 104 105 106 107 108 109
  /**
   * Check if the current reference line is a change lane reference line, i.e.,
   * ADC's current position is not on this reference line.
   */
  bool IsChangeLanePath() const;
  /**
   * Set if the vehicle can drive following this reference line
   * A planner need to set this value to true if the reference line is OK
   */
  void SetDriable(bool drivable);
  bool IsDrivable() const;

110
  const hdmap::RouteSegments& Lanes() const;
111
  const std::list<hdmap::Id> TargetLaneId() const;
112

113 114
  void ExportDecision(DecisionResult* decision_result) const;

115 116 117
  void SetJunctionRightOfWay(double junction_s, bool is_protected);

  ADCTrajectory::RightOfWayStatus GetRightOfWayStatus() const;
118

D
Dong Li 已提交
119
 private:
120 121
  void ExportTurnSignal(common::VehicleSignal* signal) const;

122
  bool IsUnrelaventObstacle(PathObstacle* path_obstacle);
D
Dong Li 已提交
123

124 125 126 127 128
  void MakeDecision(DecisionResult* decision_result) const;
  int MakeMainStopDecision(DecisionResult* decision_result) const;
  void MakeMainMissionCompleteDecision(DecisionResult* decision_result) const;
  void MakeEStopDecision(DecisionResult* decision_result) const;
  void SetObjectDecisions(ObjectDecisions* object_decisions) const;
129
  const common::VehicleState vehicle_state_;
130
  const common::TrajectoryPoint adc_planning_point_;
131
  const ReferenceLine reference_line_;
132

133 134
  /**
   * @brief this is the number that measures the goodness of this reference
135
   * line. The lower the better.
136
   */
D
Dong Li 已提交
137
  double cost_ = 0.0;
138

D
Dong Li 已提交
139 140
  bool is_drivable_ = false;

D
Dong Li 已提交
141
  PathDecision path_decision_;
142 143 144 145

  PathData path_data_;
  SpeedData speed_data_;

146
  DiscretizedTrajectory discretized_trajectory_;
147

148
  SLBoundary adc_sl_boundary_;
149

150 151
  planning_internal::Debug debug_;
  LatencyStats latency_stats_;
152

153 154
  hdmap::RouteSegments lanes_;

155 156
  bool is_on_reference_line_ = false;

157 158
  ADCTrajectory::RightOfWayStatus status_ = ADCTrajectory::UNPROTECTED;

159
  DISALLOW_COPY_AND_ASSIGN(ReferenceLineInfo);
D
Dong Li 已提交
160 161 162 163 164 165
};

}  // namespace planning
}  // namespace apollo

#endif  // MODULES_PLANNING_COMMON_REFERENCE_LINE_INFO_H_