提交 3c77ff2f 编写于 作者: D Dong Li 提交者: Jiangtao Hu

planning: prepare planning_test_base for end-to-end planning integration tests

上级 0a2fbf32
...@@ -33,6 +33,7 @@ DEFINE_string(test_localization_file, ...@@ -33,6 +33,7 @@ DEFINE_string(test_localization_file,
DEFINE_string(test_chassis_file, DEFINE_string(test_chassis_file,
"modules/planning/testdata/garage_chassis.pb.txt", "modules/planning/testdata/garage_chassis.pb.txt",
"The chassis test file"); "The chassis test file");
DEFINE_string(test_prediction_file, "", "The prediction module test file");
void PlanningTestBase::SetDataConfigs() { void PlanningTestBase::SetDataConfigs() {
FLAGS_qp_spline_path_config_file = FLAGS_qp_spline_path_config_file =
...@@ -82,35 +83,24 @@ bool PlanningTestBase::SetUpAdapters() { ...@@ -82,35 +83,24 @@ bool PlanningTestBase::SetUpAdapters() {
AERROR << "Failed to load chassis file: " << FLAGS_test_chassis_file; AERROR << "Failed to load chassis file: " << FLAGS_test_chassis_file;
return false; return false;
} }
AdapterManager::Observe(); if (!FLAGS_test_prediction_file.empty() &&
AdapterManager::FeedPredictionFile(FLAGS_test_prediction_file)) {
AERROR << "Failed to load prediction file: " << FLAGS_test_prediction_file;
return false;
}
return true; return true;
} }
void PlanningTestBase::SetUp() { void PlanningTestBase::SetUp() {
SetDataConfigs(); SetDataConfigs();
adc_trajectory_ = nullptr;
SetUpAdapters();
planning_.Init(); planning_.Init();
if (!SetUpAdapters()) { }
AERROR << "Failed to setup adapters";
return; void PlanningTestBase::RunPlanning() {
} planning_.RunOnce();
common::VehicleState::instance()->Update( adc_trajectory_ = AdapterManager::GetPlanning()->GetLatestPublished();
AdapterManager::GetLocalization()->GetLatestObserved(),
AdapterManager::GetChassis()->GetLatestObserved());
pose_ = common::VehicleState::instance()->pose();
if (!common::util::GetProtoFromFile(FLAGS_dp_poly_path_config_file,
&dp_poly_path_config_)) {
AERROR << "Failed to load file " << FLAGS_dp_poly_path_config_file;
return;
}
if (!common::util::GetProtoFromFile(FLAGS_dp_st_speed_config_file,
&dp_st_speed_config_)) {
AERROR << "Failed to load file " << FLAGS_dp_st_speed_config_file;
return;
}
if (!planning_.InitFrame(1)) {
AERROR << "planning init frame failed";
return;
}
} }
void PlanningTestBase::export_sl_points( void PlanningTestBase::export_sl_points(
......
...@@ -37,6 +37,7 @@ using common::adapter::AdapterManager; ...@@ -37,6 +37,7 @@ using common::adapter::AdapterManager;
DECLARE_string(test_routing_response_file); DECLARE_string(test_routing_response_file);
DECLARE_string(test_localization_file); DECLARE_string(test_localization_file);
DECLARE_string(test_chassis_file); DECLARE_string(test_chassis_file);
DECLARE_string(test_prediction_file);
class PlanningTestBase : public ::testing::Test { class PlanningTestBase : public ::testing::Test {
public: public:
...@@ -56,6 +57,13 @@ class PlanningTestBase : public ::testing::Test { ...@@ -56,6 +57,13 @@ class PlanningTestBase : public ::testing::Test {
virtual void SetDataConfigs(); virtual void SetDataConfigs();
virtual void SetUp(); virtual void SetUp();
/**
* Execute the planning code.
* @return true if planning is success. The ADCTrajectory will be used to
* store the planing results. Otherwise false.
*/
void RunPlanning();
/** /**
* @brief Print out the points to a file for debug and visualization purpose. * @brief Print out the points to a file for debug and visualization purpose.
* User can see the file, or feed it * User can see the file, or feed it
...@@ -74,6 +82,7 @@ class PlanningTestBase : public ::testing::Test { ...@@ -74,6 +82,7 @@ class PlanningTestBase : public ::testing::Test {
DpStSpeedConfig dp_st_speed_config_; DpStSpeedConfig dp_st_speed_config_;
localization::Pose pose_; localization::Pose pose_;
Planning planning_; Planning planning_;
ADCTrajectory* adc_trajectory_ = nullptr;
}; };
} // namespace planning } // namespace planning
......
...@@ -67,6 +67,7 @@ class DpRoadGraphTest : public PlanningTestBase { ...@@ -67,6 +67,7 @@ class DpRoadGraphTest : public PlanningTestBase {
virtual void SetUp() { virtual void SetUp() {
google::InitGoogleLogging("DpRoadGraphTest"); google::InitGoogleLogging("DpRoadGraphTest");
PlanningTestBase::SetUp(); PlanningTestBase::SetUp();
RunPlanning();
SetInitPoint(); SetInitPoint();
SetSpeedDataWithConstVeolocity(10.0); SetSpeedDataWithConstVeolocity(10.0);
const auto* frame = planning_.GetFrame(); const auto* frame = planning_.GetFrame();
...@@ -86,9 +87,9 @@ TEST_F(DpRoadGraphTest, speed_road_graph) { ...@@ -86,9 +87,9 @@ TEST_F(DpRoadGraphTest, speed_road_graph) {
ASSERT_TRUE(reference_line_ != nullptr); ASSERT_TRUE(reference_line_ != nullptr);
bool result = road_graph.FindPathTunnel(init_point_, &path_data_); bool result = road_graph.FindPathTunnel(init_point_, &path_data_);
EXPECT_TRUE(result); EXPECT_TRUE(result);
EXPECT_EQ(648, path_data_.discretized_path().num_of_points()); EXPECT_EQ(765, path_data_.discretized_path().num_of_points());
EXPECT_EQ(648, path_data_.frenet_frame_path().number_of_points()); EXPECT_EQ(765, path_data_.frenet_frame_path().number_of_points());
EXPECT_FLOAT_EQ(70.450378, EXPECT_FLOAT_EQ(75.900002,
path_data_.frenet_frame_path().points().back().s()); path_data_.frenet_frame_path().points().back().s());
EXPECT_FLOAT_EQ(0.0, path_data_.frenet_frame_path().points().back().l()); EXPECT_FLOAT_EQ(0.0, path_data_.frenet_frame_path().points().back().l());
// export_path_data(path_data_, "/tmp/path.txt"); // export_path_data(path_data_, "/tmp/path.txt");
......
...@@ -88,7 +88,9 @@ Status Planning::Init() { ...@@ -88,7 +88,9 @@ Status Planning::Init() {
"failed to load planning config file: " + FLAGS_planning_config_file); "failed to load planning config file: " + FLAGS_planning_config_file);
} }
AdapterManager::Init(FLAGS_adapter_config_path); if (!AdapterManager::Initialized()) {
AdapterManager::Init(FLAGS_adapter_config_path);
}
if (AdapterManager::GetLocalization() == nullptr) { if (AdapterManager::GetLocalization() == nullptr) {
std::string error_msg("Localization is not registered"); std::string error_msg("Localization is not registered");
AERROR << error_msg; AERROR << error_msg;
...@@ -195,7 +197,8 @@ void Planning::RunOnce() { ...@@ -195,7 +197,8 @@ void Planning::RunOnce() {
const double time_diff_ms = (end_timestamp - start_timestamp) * 1000; const double time_diff_ms = (end_timestamp - start_timestamp) * 1000;
auto trajectory_pb = frame_->MutableADCTrajectory(); auto trajectory_pb = frame_->MutableADCTrajectory();
trajectory_pb->mutable_latency_stats()->set_total_time_ms(time_diff_ms); trajectory_pb->mutable_latency_stats()->set_total_time_ms(time_diff_ms);
ADEBUG << "Planning latency: " << trajectory_pb->latency_stats().DebugString(); ADEBUG << "Planning latency: "
<< trajectory_pb->latency_stats().DebugString();
if (res_planning) { if (res_planning) {
AdapterManager::FillPlanningHeader("planning", trajectory_pb); AdapterManager::FillPlanningHeader("planning", trajectory_pb);
...@@ -211,10 +214,8 @@ void Planning::RunOnce() { ...@@ -211,10 +214,8 @@ void Planning::RunOnce() {
void Planning::Stop() {} void Planning::Stop() {}
bool Planning::Plan(const bool is_on_auto_mode, bool Planning::Plan(const bool is_on_auto_mode, const double current_time_stamp,
const double current_time_stamp,
const double planning_cycle_time) { const double planning_cycle_time) {
const auto& stitching_trajectory = const auto& stitching_trajectory =
TrajectoryStitcher::compute_stitching_trajectory( TrajectoryStitcher::compute_stitching_trajectory(
is_on_auto_mode, current_time_stamp, planning_cycle_time, is_on_auto_mode, current_time_stamp, planning_cycle_time,
...@@ -223,8 +224,8 @@ bool Planning::Plan(const bool is_on_auto_mode, ...@@ -223,8 +224,8 @@ bool Planning::Plan(const bool is_on_auto_mode,
frame_->SetPlanningStartPoint(stitching_trajectory.back()); frame_->SetPlanningStartPoint(stitching_trajectory.back());
PublishableTrajectory publishable_trajectory; PublishableTrajectory publishable_trajectory;
auto status = planner_->Plan(stitching_trajectory.back(), auto status = planner_->Plan(stitching_trajectory.back(), frame_.get(),
frame_.get(), &publishable_trajectory); &publishable_trajectory);
if (status != Status::OK()) { if (status != Status::OK()) {
AERROR << "planner failed to make a driving plan"; AERROR << "planner failed to make a driving plan";
......
...@@ -75,17 +75,17 @@ class Planning : public apollo::common::ApolloApp { ...@@ -75,17 +75,17 @@ class Planning : public apollo::common::ApolloApp {
* @brief Plan the trajectory given current vehicle state * @brief Plan the trajectory given current vehicle state
* @param is_on_auto_mode whether the current system is on auto-driving mode * @param is_on_auto_mode whether the current system is on auto-driving mode
*/ */
bool Plan(const bool is_on_auto_mode, bool Plan(const bool is_on_auto_mode, const double current_time_stamp,
const double current_time_stamp,
const double planning_cycle_time); const double planning_cycle_time);
const Frame* GetFrame() const; const Frame* GetFrame() const;
const hdmap::PncMap* GetPncMap() const; const hdmap::PncMap* GetPncMap() const;
bool InitFrame(const uint32_t sequence_num); bool InitFrame(const uint32_t sequence_num);
void RunOnce();
private: private:
void RegisterPlanners(); void RegisterPlanners();
void RunOnce();
apollo::common::util::Factory<PlanningConfig::PlannerType, Planner> apollo::common::util::Factory<PlanningConfig::PlannerType, Planner>
planner_factory_; planner_factory_;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册