Apollo 11.0
自动驾驶开放平台
apollo::planning::PlanningTestBase类 参考

#include <planning_test_base.h>

类 apollo::planning::PlanningTestBase 继承关系图:
apollo::planning::PlanningTestBase 的协作图:

Public 成员函数

virtual ~PlanningTestBase ()=default
 
virtual void SetUp ()
 
void UpdateData ()
 
bool RunPlanning (const std::string &test_case_name, int case_num, bool no_trajectory_point)
 Execute the planning code.
 
std::shared_ptr< TrafficRule > GetTrafficRuleConfig (const std::string &rule_id)
 

静态 Public 成员函数

static void SetUpTestCase ()
 

Protected 成员函数

void TrimPlanning (ADCTrajectory *origin, bool no_trajectory_point)
 
bool FeedTestData ()
 
bool IsValidTrajectory (const ADCTrajectory &trajectory)
 

Protected 属性

std::unique_ptr< PlanningBase > planning_ = nullptr
 
std::set< std::string > rule_enabled_
 
ADCTrajectory adc_trajectory_
 
LocalView local_view_
 
PlanningConfig config_
 
std::shared_ptr< DependencyInjector > injector_
 

详细描述

在文件 planning_test_base.h 第 69 行定义.

构造及析构函数说明

◆ ~PlanningTestBase()

virtual apollo::planning::PlanningTestBase::~PlanningTestBase ( )
virtualdefault

成员函数说明

◆ FeedTestData()

bool apollo::planning::PlanningTestBase::FeedTestData ( )
protected

在文件 planning_test_base.cc 第 76 行定义.

76 {
77 // chassis
78 Chassis chassis;
79 if (FLAGS_test_chassis_file.empty()) {
80 AERROR << "Requires FLAGS_test_chassis_file to be set";
81 return false;
82 }
84 FLAGS_test_data_dir + "/" + FLAGS_test_chassis_file, &chassis)) {
85 AERROR << "failed to load file: " << FLAGS_test_chassis_file;
86 return false;
87 }
88 // localization
89 if (FLAGS_test_localization_file.empty()) {
90 AERROR << "Requires FLAGS_test_localization_file to be set";
91 return false;
92 }
93 LocalizationEstimate localization;
95 FLAGS_test_data_dir + "/" + FLAGS_test_localization_file,
96 &localization)) {
97 AERROR << "failed to load file: " << FLAGS_test_localization_file;
98 return false;
99 }
101 Clock::SetNowInSeconds(localization.header().timestamp_sec());
102
103 // prediction
104 if (FLAGS_test_prediction_file.empty()) {
105 AERROR << "Requires FLAGS_test_prediction_file to be set";
106 return false;
107 }
108 PredictionObstacles prediction;
110 FLAGS_test_data_dir + "/" + FLAGS_test_prediction_file,
111 &prediction)) {
112 AERROR << "failed to load file: " << FLAGS_test_prediction_file;
113 return false;
114 }
115 // routing_response
116 if (FLAGS_test_routing_response_file.empty()) {
117 AERROR << "Requires FLAGS_test_routing_response_file";
118 return false;
119 }
120 RoutingResponse routing_response;
122 FLAGS_test_data_dir + "/" + FLAGS_test_routing_response_file,
123 &routing_response)) {
124 AERROR << "failed to load file: " << FLAGS_test_routing_response_file;
125 return false;
126 }
127 // traffic_light_detection
128 // optional
129 TrafficLightDetection traffic_light_detection;
131 FLAGS_test_data_dir + "/" + FLAGS_test_traffic_light_file,
132 &traffic_light_detection)) {
133 AERROR << "failed to load file: " << FLAGS_test_traffic_light_file;
134 return false;
135 }
136
138 std::make_shared<PredictionObstacles>(prediction);
139 local_view_.chassis = std::make_shared<Chassis>(chassis);
141 std::make_shared<LocalizationEstimate>(localization);
143 std::make_shared<TrafficLightDetection>(traffic_light_detection);
144
145 AINFO << "Successfully feed proto files.";
146 return true;
147}
static void SetNowInSeconds(const double seconds)
This is for mock clock mode only.
Definition clock.h:84
static void SetMode(ClockMode mode)
Definition clock.cc:58
#define AERROR
Definition log.h:44
#define AINFO
Definition log.h:42
bool GetProtoFromFile(const std::string &file_name, google::protobuf::Message *message)
Parses the content of the file specified by the file_name as a representation of protobufs,...
Definition file.cc:132
std::shared_ptr< localization::LocalizationEstimate > localization_estimate
Definition local_view.h:43
std::shared_ptr< prediction::PredictionObstacles > prediction_obstacles
Definition local_view.h:41
std::shared_ptr< canbus::Chassis > chassis
Definition local_view.h:42
std::shared_ptr< perception::TrafficLightDetection > traffic_light
Definition local_view.h:44

◆ GetTrafficRuleConfig()

std::shared_ptr< TrafficRule > apollo::planning::PlanningTestBase::GetTrafficRuleConfig ( const std::string &  rule_id)

◆ IsValidTrajectory()

bool apollo::planning::PlanningTestBase::IsValidTrajectory ( const ADCTrajectory &  trajectory)
protected

在文件 planning_test_base.cc 第 238 行定义.

238 {
239 for (int i = 0; i < trajectory.trajectory_point_size(); ++i) {
240 const auto& point = trajectory.trajectory_point(i);
241
242 const double kMaxAccelThreshold =
243 FLAGS_longitudinal_acceleration_upper_bound;
244 const double kMinAccelThreshold =
245 FLAGS_longitudinal_acceleration_lower_bound;
246 if (point.a() > kMaxAccelThreshold || point.a() < kMinAccelThreshold) {
247 AERROR << "Invalid trajectory point because accel out of range: "
248 << point.DebugString();
249 return false;
250 }
251
252 if (!point.has_path_point()) {
253 AERROR << "Invalid trajectory point because NO path_point in "
254 "trajectory_point: "
255 << point.DebugString();
256 return false;
257 }
258
259 if (i > 0) {
260 const double kPathSEpsilon = 1e-3;
261 const auto& last_point = trajectory.trajectory_point(i - 1);
262 if (point.path_point().s() + kPathSEpsilon <
263 last_point.path_point().s()) {
264 AERROR << "Invalid trajectory point because s value error. last point: "
265 << last_point.DebugString()
266 << ", curr point: " << point.DebugString();
267 return false;
268 }
269 }
270 }
271 return true;
272}

◆ RunPlanning()

bool apollo::planning::PlanningTestBase::RunPlanning ( const std::string &  test_case_name,
int  case_num,
bool  no_trajectory_point 
)

Execute the planning code.

返回
true if planning is success. The ADCTrajectory will be used to store the planing results. Otherwise false.

在文件 planning_test_base.cc 第 190 行定义.

191 {
192 const std::string golden_result_file =
193 absl::StrCat("result_", test_case_name, "_", case_num, ".pb.txt");
194
195 std::string full_golden_path = FLAGS_test_data_dir + "/" + golden_result_file;
196
197 ADCTrajectory adc_trajectory_pb;
198 planning_->RunOnce(local_view_, &adc_trajectory_pb);
199
200 if (!IsValidTrajectory(adc_trajectory_pb)) {
201 AERROR << "Fail to pass trajectory check.";
202 return false;
203 }
204
205 adc_trajectory_ = adc_trajectory_pb;
206 TrimPlanning(&adc_trajectory_, no_trajectory_point);
207 if (FLAGS_test_update_golden_log) {
208 AINFO << "The golden file is regenerated:" << full_golden_path;
210 } else {
211 ADCTrajectory golden_result;
212 bool load_success =
213 cyber::common::GetProtoFromASCIIFile(full_golden_path, &golden_result);
214 TrimPlanning(&golden_result, no_trajectory_point);
215 if (!load_success ||
217 char tmp_fname[100] = "/tmp/XXXXXX";
218 int fd = mkstemp(tmp_fname);
219 if (fd < 0) {
220 AERROR << "Failed to create temporary file: " << tmp_fname;
221 return false;
222 }
224 AERROR << "Failed to write to file: " << tmp_fname;
225 }
226 AERROR << "found error\ndiff -y " << tmp_fname << " " << full_golden_path;
227 AERROR << "to override error\nmv " << tmp_fname << " "
228 << full_golden_path;
229 AERROR << "to visualize\n/usr/bin/python "
230 "modules/tools/plot_trace/plot_planning_result.py "
231 << tmp_fname << " " << full_golden_path;
232 return false;
233 }
234 }
235 return true;
236}
void TrimPlanning(ADCTrajectory *origin, bool no_trajectory_point)
bool IsValidTrajectory(const ADCTrajectory &trajectory)
std::unique_ptr< PlanningBase > planning_
bool IsProtoEqual(const ProtoA &a, const ProtoB &b)
Definition util.h:47
bool GetProtoFromASCIIFile(const std::string &file_name, google::protobuf::Message *message)
Parses the content of the file specified by the file_name as ascii representation of protobufs,...
Definition file.cc:89
bool SetProtoToASCIIFile(const google::protobuf::Message &message, int file_descriptor)
Definition file.cc:43

◆ SetUp()

void apollo::planning::PlanningTestBase::SetUp ( )
virtual

在文件 planning_test_base.cc 第 149 行定义.

149 {
150 injector_ = std::make_shared<DependencyInjector>();
151
152 if (FLAGS_use_navigation_mode) {
153 // TODO(all)
154 // planning_ = std::unique_ptr<PlanningBase>(new NaviPlanning());
155 } else {
156 planning_ = std::unique_ptr<PlanningBase>(new OnLanePlanning(injector_));
157 }
158
159 ACHECK(FeedTestData()) << "Failed to feed test data";
160
161 ACHECK(cyber::common::GetProtoFromFile(FLAGS_test_planning_config_file,
162 &config_))
163 << "failed to load planning config file "
164 << FLAGS_test_planning_config_file;
165
166 ACHECK(planning_->Init(config_).ok()) << "Failed to init planning module";
167}
std::shared_ptr< DependencyInjector > injector_
#define ACHECK(cond)
Definition log.h:80

◆ SetUpTestCase()

void apollo::planning::PlanningTestBase::SetUpTestCase ( )
static

在文件 planning_test_base.cc 第 53 行定义.

53 {
54 FLAGS_use_multi_thread_to_add_obstacles = false;
55 FLAGS_traffic_rule_config_filename =
56 "/apollo/modules/planning/planning_component/conf/"
57 "traffic_rule_config.pb.txt";
58 FLAGS_smoother_config_filename =
59 "/apollo/modules/planning/planning_component/conf/"
60 "qp_spline_smoother_config.pb.txt";
61 FLAGS_map_dir = "/apollo/modules/planning/planning_base/testdata";
62 FLAGS_test_localization_file = "";
63 FLAGS_test_chassis_file = "";
64 FLAGS_test_routing_response_file = "";
65 FLAGS_test_planning_config_file =
66 "/apollo/modules/planning/planning_component/conf/planning_config.pb.txt";
67 FLAGS_test_previous_planning_file = "";
68 FLAGS_test_prediction_file = "";
69 FLAGS_align_prediction_time = false;
70 FLAGS_enable_reference_line_provider_thread = false;
71 // FLAGS_enable_trajectory_check is temporarily disabled, otherwise EMPlanner
72 // and LatticePlanner can't pass the unit test.
73 FLAGS_enable_trajectory_check = false;
74}

◆ TrimPlanning()

void apollo::planning::PlanningTestBase::TrimPlanning ( ADCTrajectory *  origin,
bool  no_trajectory_point 
)
protected

在文件 planning_test_base.cc 第 173 行定义.

174 {
175 origin->clear_latency_stats();
176 origin->clear_debug();
177 // origin->mutable_header()->clear_radar_timestamp();
178 // origin->mutable_header()->clear_lidar_timestamp();
179 // origin->mutable_header()->clear_timestamp_sec();
180 // origin->mutable_header()->clear_camera_timestamp();
181 // origin->mutable_header()->clear_sequence_num();
182
183 if (no_trajectory_point) {
184 origin->clear_total_path_length();
185 origin->clear_total_path_time();
186 origin->clear_trajectory_point();
187 }
188}

◆ UpdateData()

void apollo::planning::PlanningTestBase::UpdateData ( )

在文件 planning_test_base.cc 第 169 行定义.

169 {
170 ACHECK(FeedTestData()) << "Failed to feed test data";
171}

类成员变量说明

◆ adc_trajectory_

ADCTrajectory apollo::planning::PlanningTestBase::adc_trajectory_
protected

在文件 planning_test_base.h 第 95 行定义.

◆ config_

PlanningConfig apollo::planning::PlanningTestBase::config_
protected

在文件 planning_test_base.h 第 97 行定义.

◆ injector_

std::shared_ptr<DependencyInjector> apollo::planning::PlanningTestBase::injector_
protected

在文件 planning_test_base.h 第 98 行定义.

◆ local_view_

LocalView apollo::planning::PlanningTestBase::local_view_
protected

在文件 planning_test_base.h 第 96 行定义.

◆ planning_

std::unique_ptr<PlanningBase> apollo::planning::PlanningTestBase::planning_ = nullptr
protected

在文件 planning_test_base.h 第 93 行定义.

◆ rule_enabled_

std::set<std::string> apollo::planning::PlanningTestBase::rule_enabled_
protected

在文件 planning_test_base.h 第 94 行定义.


该类的文档由以下文件生成: