repo_id
stringlengths
19
138
file_path
stringlengths
32
200
content
stringlengths
1
12.9M
__index_level_0__
int64
0
0
apollo_public_repos/apollo/modules/planning/scenarios/park
apollo_public_repos/apollo/modules/planning/scenarios/park/pull_over/stage_retry_approach_parking.cc
/****************************************************************************** * Copyright 2019 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 **/ #include "modules/planning/scenarios/park/pull_over/stage_retry_approach_parking.h" #include <memory> #include "modules/common/configs/vehicle_config_helper.h" #include "modules/common/vehicle_state/vehicle_state_provider.h" namespace apollo { namespace planning { namespace scenario { namespace pull_over { using apollo::common::TrajectoryPoint; PullOverStageRetryApproachParking::PullOverStageRetryApproachParking( const ScenarioConfig::StageConfig& config, const std::shared_ptr<DependencyInjector>& injector) : Stage(config, injector) {} Stage::StageStatus PullOverStageRetryApproachParking::FinishStage() { next_stage_ = StageType::PULL_OVER_RETRY_PARKING; return Stage::FINISHED; } Stage::StageStatus PullOverStageRetryApproachParking::Process( const TrajectoryPoint& planning_init_point, Frame* frame) { ADEBUG << "stage: RetryApproachParking"; CHECK_NOTNULL(frame); scenario_config_.CopyFrom(GetContext()->scenario_config); bool plan_ok = ExecuteTaskOnReferenceLine(planning_init_point, frame); if (!plan_ok) { AERROR << "PullOverStageRetryApproachParking planning error"; } if (CheckADCStop(*frame)) { return FinishStage(); } return StageStatus::RUNNING; } bool PullOverStageRetryApproachParking::CheckADCStop(const Frame& frame) { const auto& reference_line_info = frame.reference_line_info().front(); const double adc_speed = injector_->vehicle_state()->linear_velocity(); const double max_adc_stop_speed = common::VehicleConfigHelper::Instance() ->GetConfig() .vehicle_param() .max_abs_speed_when_stopped(); if (adc_speed > max_adc_stop_speed) { ADEBUG << "ADC not stopped: speed[" << adc_speed << "]"; return false; } // check stop close enough to stop line of the stop_sign const double adc_front_edge_s = reference_line_info.AdcSlBoundary().end_s(); const double stop_fence_start_s = frame.open_space_info().open_space_pre_stop_fence_s(); const double distance_stop_line_to_adc_front_edge = stop_fence_start_s - adc_front_edge_s; if (distance_stop_line_to_adc_front_edge > scenario_config_.max_valid_stop_distance()) { ADEBUG << "not a valid stop. too far from stop line."; return false; } return true; } } // namespace pull_over } // namespace scenario } // namespace planning } // namespace apollo
0
apollo_public_repos/apollo/modules/planning/scenarios/park
apollo_public_repos/apollo/modules/planning/scenarios/park/pull_over/BUILD
load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test") load("//third_party/gpus:common.bzl", "if_cuda", "if_rocm") load("//tools:cpplint.bzl", "cpplint") package(default_visibility = ["//visibility:public"]) cc_library( name = "pull_over_scenario", srcs = [ "pull_over_scenario.cc", "stage_approach.cc", "stage_retry_approach_parking.cc", "stage_retry_parking.cc", ], hdrs = [ "pull_over_scenario.h", "stage_approach.h", "stage_retry_approach_parking.h", "stage_retry_parking.h", ], copts = ["-DMODULE_NAME=\\\"planning\\\""], deps = [ "//cyber", "//modules/common/util:util_tool", "//modules/common/vehicle_state:vehicle_state_provider", "//modules/planning/common:planning_common", "//modules/planning/common/util:common_lib", "//modules/planning/common/util:util_lib", "//modules/common_msgs/planning_msgs:planning_cc_proto", "//modules/planning/scenarios:scenario", "//modules/planning/scenarios/util:scenario_util_lib", "@com_github_gflags_gflags//:gflags", "@eigen", ] + if_cuda([ "@local_config_cuda//cuda:cudart", ]) + if_rocm([ "@local_config_rocm//rocm:hip", ]), ) cc_test( name = "pull_over_scenario_test", size = "small", srcs = ["pull_over_scenario_test.cc"], data = [ "//modules/planning:planning_conf", ], linkopts = ["-lgomp"], deps = [ ":pull_over_scenario", "@com_google_googletest//:gtest_main", ] + if_cuda([ "@local_config_cuda//cuda:cudart", ]) + if_rocm([ "@local_config_rocm//rocm:hip", ]), linkstatic = True, ) cc_test( name = "stage_approach_test", size = "small", srcs = ["stage_approach_test.cc"], data = [ "//modules/planning:planning_conf", ], linkopts = ["-lgomp"], deps = [ ":pull_over_scenario", "@com_google_googletest//:gtest_main", ] + if_cuda([ "@local_config_cuda//cuda:cudart", ]) + if_rocm([ "@local_config_rocm//rocm:hip", ]), linkstatic = True, ) cc_test( name = "stage_retry_approach_parking_test", size = "small", srcs = ["stage_retry_approach_parking_test.cc"], data = [ "//modules/planning:planning_conf", ], linkopts = ["-lgomp"], deps = [ ":pull_over_scenario", "@com_google_googletest//:gtest_main", ], linkstatic = True, ) cc_test( name = "stage_retry_parking_test", size = "small", srcs = ["stage_retry_parking.cc"], data = [ "//modules/planning:planning_conf", ], linkopts = ["-lgomp"], deps = [ ":pull_over_scenario", "@com_google_googletest//:gtest_main", ], linkstatic = True, ) cpplint()
0
apollo_public_repos/apollo/modules/planning/scenarios/park
apollo_public_repos/apollo/modules/planning/scenarios/park/pull_over/pull_over_scenario.h
/****************************************************************************** * Copyright 2019 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 **/ #pragma once #include <memory> #include "modules/common/util/factory.h" #include "modules/planning/common/frame.h" #include "modules/planning/scenarios/scenario.h" namespace apollo { namespace planning { namespace scenario { namespace pull_over { // stage context struct PullOverContext { ScenarioPullOverConfig scenario_config; }; class PullOverScenario : public Scenario { public: PullOverScenario(const ScenarioConfig& config, const ScenarioContext* scenario_context, const std::shared_ptr<DependencyInjector>& injector) : Scenario(config, scenario_context, injector) {} void Init() override; std::unique_ptr<Stage> CreateStage( const ScenarioConfig::StageConfig& stage_config, const std::shared_ptr<DependencyInjector>& injector); PullOverContext* GetContext() { return &context_; } private: static void RegisterStages(); bool GetScenarioConfig(); private: static apollo::common::util::Factory< StageType, Stage, Stage* (*)(const ScenarioConfig::StageConfig& stage_config, const std::shared_ptr<DependencyInjector>& injector)> s_stage_factory_; bool init_ = false; PullOverContext context_; }; } // namespace pull_over } // namespace scenario } // namespace planning } // namespace apollo
0
apollo_public_repos/apollo/modules/planning/scenarios/park
apollo_public_repos/apollo/modules/planning/scenarios/park/pull_over/stage_retry_approach_parking_test.cc
/****************************************************************************** * Copyright 2019 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. *****************************************************************************/ #include "modules/planning/scenarios/park/pull_over/stage_retry_approach_parking.h" #include "cyber/common/file.h" #include "cyber/common/log.h" #include "gtest/gtest.h" #include "modules/planning/common/planning_gflags.h" namespace apollo { namespace planning { namespace scenario { namespace pull_over { class PullOverStageRetryApproachParkingTest : public ::testing::Test { public: virtual void SetUp() { config_.set_stage_type(StageType::PULL_OVER_RETRY_APPROACH_PARKING); injector_ = std::make_shared<DependencyInjector>(); } protected: ScenarioConfig::StageConfig config_; std::shared_ptr<DependencyInjector> injector_; }; TEST_F(PullOverStageRetryApproachParkingTest, Init) { PullOverStageRetryApproachParking pull_over_stage_retry_approach_parking( config_, injector_); EXPECT_EQ(pull_over_stage_retry_approach_parking.Name(), StageType_Name( StageType::PULL_OVER_RETRY_APPROACH_PARKING)); } } // namespace pull_over } // namespace scenario } // namespace planning } // namespace apollo
0
apollo_public_repos/apollo/modules/planning/scenarios/park
apollo_public_repos/apollo/modules/planning/scenarios/park/pull_over/stage_retry_parking.h
/****************************************************************************** * Copyright 2019 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 **/ #pragma once #include <memory> #include "modules/planning/proto/planning_config.pb.h" #include "modules/planning/scenarios/park/pull_over/pull_over_scenario.h" #include "modules/planning/scenarios/stage.h" namespace apollo { namespace planning { namespace scenario { namespace pull_over { struct PullOverContext; class PullOverStageRetryParking : public Stage { public: PullOverStageRetryParking( const ScenarioConfig::StageConfig& config, const std::shared_ptr<DependencyInjector>& injector); StageStatus Process(const common::TrajectoryPoint& planning_init_point, Frame* frame) override; PullOverContext* GetContext() { return Stage::GetContextAs<PullOverContext>(); } Stage::StageStatus FinishStage(); private: bool CheckADCPullOverOpenSpace(); private: ScenarioPullOverConfig scenario_config_; }; } // namespace pull_over } // namespace scenario } // namespace planning } // namespace apollo
0
apollo_public_repos/apollo/modules/planning/scenarios/park
apollo_public_repos/apollo/modules/planning/scenarios/park/valet_parking/stage_approaching_parking_spot.h
/****************************************************************************** * Copyright 2019 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 **/ #pragma once #include <memory> #include "modules/planning/scenarios/park/valet_parking/valet_parking_scenario.h" #include "modules/planning/scenarios/stage.h" namespace apollo { namespace planning { namespace scenario { namespace valet_parking { class StageApproachingParkingSpot : public Stage { public: StageApproachingParkingSpot( const ScenarioConfig::StageConfig& config, const std::shared_ptr<DependencyInjector>& injector) : Stage(config, injector) {} private: Stage::StageStatus Process(const common::TrajectoryPoint& planning_init_point, Frame* frame) override; ValetParkingContext* GetContext() { return GetContextAs<ValetParkingContext>(); } bool CheckADCStop(const Frame& frame); private: ScenarioValetParkingConfig scenario_config_; }; } // namespace valet_parking } // namespace scenario } // namespace planning } // namespace apollo
0
apollo_public_repos/apollo/modules/planning/scenarios/park
apollo_public_repos/apollo/modules/planning/scenarios/park/valet_parking/stage_parking_test.cc
/****************************************************************************** * Copyright 2019 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 **/ #include "modules/planning/scenarios/park/valet_parking/stage_parking.h" #include "gtest/gtest.h" #include "modules/planning/proto/planning_config.pb.h" namespace apollo { namespace planning { namespace scenario { namespace valet_parking { class StageParkingTest : public ::testing::Test { public: virtual void SetUp() { config_.set_stage_type(StageType::VALET_PARKING_PARKING); injector_ = std::make_shared<DependencyInjector>(); } protected: ScenarioConfig::StageConfig config_; std::shared_ptr<DependencyInjector> injector_; }; TEST_F(StageParkingTest, Init) { StageParking stage_parking(config_, injector_); EXPECT_EQ(stage_parking.Name(), StageType_Name( StageType::VALET_PARKING_PARKING)); } } // namespace valet_parking } // namespace scenario } // namespace planning } // namespace apollo
0
apollo_public_repos/apollo/modules/planning/scenarios/park
apollo_public_repos/apollo/modules/planning/scenarios/park/valet_parking/stage_parking.h
/****************************************************************************** * Copyright 2019 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 **/ #pragma once #include <memory> #include "modules/planning/scenarios/park/valet_parking/valet_parking_scenario.h" #include "modules/planning/scenarios/stage.h" namespace apollo { namespace planning { namespace scenario { namespace valet_parking { class StageParking : public Stage { public: StageParking(const ScenarioConfig::StageConfig& config, const std::shared_ptr<DependencyInjector>& injector) : Stage(config, injector) {} private: Stage::StageStatus Process(const common::TrajectoryPoint& planning_init_point, Frame* frame) override; ValetParkingContext* GetContext() { return GetContextAs<ValetParkingContext>(); } private: Stage::StageStatus FinishStage(); private: ScenarioValetParkingConfig scenario_config_; }; } // namespace valet_parking } // namespace scenario } // namespace planning } // namespace apollo
0
apollo_public_repos/apollo/modules/planning/scenarios/park
apollo_public_repos/apollo/modules/planning/scenarios/park/valet_parking/stage_approaching_parking_spot_test.cc
/****************************************************************************** * Copyright 2019 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 **/ #include "modules/planning/scenarios/park/valet_parking/stage_approaching_parking_spot.h" #include "gtest/gtest.h" #include "modules/planning/proto/planning_config.pb.h" namespace apollo { namespace planning { namespace scenario { namespace valet_parking { class StageApproachingParkingSpotTest : public ::testing::Test { public: virtual void SetUp() { config_.set_stage_type( StageType::VALET_PARKING_APPROACHING_PARKING_SPOT); injector_ = std::make_shared<DependencyInjector>(); } protected: ScenarioConfig::StageConfig config_; std::shared_ptr<DependencyInjector> injector_; }; TEST_F(StageApproachingParkingSpotTest, Init) { StageApproachingParkingSpot stage_approaching_parking_spot(config_, injector_); EXPECT_EQ(stage_approaching_parking_spot.Name(), StageType_Name( StageType::VALET_PARKING_APPROACHING_PARKING_SPOT)); } } // namespace valet_parking } // namespace scenario } // namespace planning } // namespace apollo
0
apollo_public_repos/apollo/modules/planning/scenarios/park
apollo_public_repos/apollo/modules/planning/scenarios/park/valet_parking/valet_parking_scenario_test.cc
/****************************************************************************** * Copyright 2019 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 **/ #include "modules/planning/scenarios/park/valet_parking/valet_parking_scenario.h" #include "cyber/common/file.h" #include "cyber/common/log.h" #include "gtest/gtest.h" #include "modules/planning/common/planning_gflags.h" namespace apollo { namespace planning { namespace scenario { namespace valet_parking { class ValetParkingScenarioTest : public ::testing::Test { public: virtual void SetUp() {} protected: std::unique_ptr<ValetParkingScenario> scenario_; }; TEST_F(ValetParkingScenarioTest, Init) { FLAGS_scenario_valet_parking_config_file = "/apollo/modules/planning/conf/scenario/valet_parking_config.pb.txt"; ScenarioConfig config; EXPECT_TRUE(apollo::cyber::common::GetProtoFromFile( FLAGS_scenario_valet_parking_config_file, &config)); ScenarioContext context; auto injector = std::make_shared<DependencyInjector>(); scenario_.reset(new ValetParkingScenario(config, &context, injector)); EXPECT_EQ(scenario_->scenario_type(), ScenarioType::VALET_PARKING); } } // namespace valet_parking } // namespace scenario } // namespace planning } // namespace apollo
0
apollo_public_repos/apollo/modules/planning/scenarios/park
apollo_public_repos/apollo/modules/planning/scenarios/park/valet_parking/stage_parking.cc
/****************************************************************************** * Copyright 2019 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 **/ #include "modules/planning/scenarios/park/valet_parking/stage_parking.h" namespace apollo { namespace planning { namespace scenario { namespace valet_parking { Stage::StageStatus StageParking::Process( const common::TrajectoryPoint& planning_init_point, Frame* frame) { // Open space planning doesn't use planning_init_point from upstream because // of different stitching strategy frame->mutable_open_space_info()->set_is_on_open_space_trajectory(true); bool plan_ok = ExecuteTaskOnOpenSpace(frame); if (!plan_ok) { AERROR << "StageParking planning error"; return StageStatus::ERROR; } return StageStatus::RUNNING; } Stage::StageStatus StageParking::FinishStage() { return Stage::FINISHED; } } // namespace valet_parking } // namespace scenario } // namespace planning } // namespace apollo
0
apollo_public_repos/apollo/modules/planning/scenarios/park
apollo_public_repos/apollo/modules/planning/scenarios/park/valet_parking/stage_approaching_parking_spot.cc
/****************************************************************************** * Copyright 2019 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 **/ #include "modules/planning/scenarios/park/valet_parking/stage_approaching_parking_spot.h" #include "modules/common/configs/vehicle_config_helper.h" #include "modules/common/vehicle_state/vehicle_state_provider.h" namespace apollo { namespace planning { namespace scenario { namespace valet_parking { Stage::StageStatus StageApproachingParkingSpot::Process( const common::TrajectoryPoint& planning_init_point, Frame* frame) { ADEBUG << "stage: StageApproachingParkingSpot"; CHECK_NOTNULL(frame); GetContext()->target_parking_spot_id.clear(); if (frame->local_view().routing->routing_request().has_parking_info() && frame->local_view() .routing->routing_request() .parking_info() .has_parking_space_id()) { GetContext()->target_parking_spot_id = frame->local_view() .routing->routing_request() .parking_info() .parking_space_id(); } else { AERROR << "No parking space id from routing"; return StageStatus::ERROR; } if (GetContext()->target_parking_spot_id.empty()) { return StageStatus::ERROR; } *(frame->mutable_open_space_info()->mutable_target_parking_spot_id()) = GetContext()->target_parking_spot_id; frame->mutable_open_space_info()->set_pre_stop_rightaway_flag( GetContext()->pre_stop_rightaway_flag); *(frame->mutable_open_space_info()->mutable_pre_stop_rightaway_point()) = GetContext()->pre_stop_rightaway_point; bool plan_ok = ExecuteTaskOnReferenceLine(planning_init_point, frame); GetContext()->pre_stop_rightaway_flag = frame->open_space_info().pre_stop_rightaway_flag(); GetContext()->pre_stop_rightaway_point = frame->open_space_info().pre_stop_rightaway_point(); if (CheckADCStop(*frame)) { next_stage_ = StageType::VALET_PARKING_PARKING; return Stage::FINISHED; } if (!plan_ok) { AERROR << "StopSignUnprotectedStagePreStop planning error"; return StageStatus::ERROR; } return Stage::RUNNING; } bool StageApproachingParkingSpot::CheckADCStop(const Frame& frame) { const auto& reference_line_info = frame.reference_line_info().front(); const double adc_speed = injector_->vehicle_state()->linear_velocity(); const double max_adc_stop_speed = common::VehicleConfigHelper::Instance() ->GetConfig() .vehicle_param() .max_abs_speed_when_stopped(); if (adc_speed > max_adc_stop_speed) { ADEBUG << "ADC not stopped: speed[" << adc_speed << "]"; return false; } // check stop close enough to stop line of the stop_sign const double adc_front_edge_s = reference_line_info.AdcSlBoundary().end_s(); const double stop_fence_start_s = frame.open_space_info().open_space_pre_stop_fence_s(); const double distance_stop_line_to_adc_front_edge = stop_fence_start_s - adc_front_edge_s; if (distance_stop_line_to_adc_front_edge > scenario_config_.max_valid_stop_distance()) { ADEBUG << "not a valid stop. too far from stop line."; return false; } return true; } } // namespace valet_parking } // namespace scenario } // namespace planning } // namespace apollo
0
apollo_public_repos/apollo/modules/planning/scenarios/park
apollo_public_repos/apollo/modules/planning/scenarios/park/valet_parking/BUILD
load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test") load("//tools:cpplint.bzl", "cpplint") load("//third_party/gpus:common.bzl", "if_cuda", "if_rocm") package(default_visibility = ["//visibility:public"]) cc_library( name = "valet_parking", srcs = [ "stage_approaching_parking_spot.cc", "stage_parking.cc", "valet_parking_scenario.cc", ], hdrs = [ "stage_approaching_parking_spot.h", "stage_parking.h", "valet_parking_scenario.h", ], copts = ["-DMODULE_NAME=\\\"planning\\\""], deps = [ "//cyber", "//modules/common_msgs/planning_msgs:planning_cc_proto", "//modules/planning/scenarios:scenario", ], ) cc_test( name = "valet_parking_scenario_test", size = "small", srcs = ["valet_parking_scenario_test.cc"], data = [ "//modules/planning:planning_conf", ], linkopts = ["-lgomp"], deps = [ ":valet_parking", "@com_google_googletest//:gtest_main", ] + if_cuda([ "@local_config_cuda//cuda:cudart", ]) + if_rocm([ "@local_config_rocm//rocm:hip", ]), linkstatic = True, ) cc_test( name = "stage_approaching_parking_spot_test", size = "small", srcs = ["stage_approaching_parking_spot_test.cc"], data = [ "//modules/planning:planning_conf", ], linkopts = ["-lgomp"], deps = [ ":valet_parking", "@com_google_googletest//:gtest_main", ] + if_cuda([ "@local_config_cuda//cuda:cudart", ]) + if_rocm([ "@local_config_rocm//rocm:hip", ]), linkstatic = True, ) cc_test( name = "stage_parking_test", size = "small", srcs = ["stage_parking_test.cc"], data = [ "//modules/planning:planning_conf", ], linkopts = ["-lgomp"], deps = [ ":valet_parking", "@com_google_googletest//:gtest_main", ] + if_cuda([ "@local_config_cuda//cuda:cudart", ]) + if_rocm([ "@local_config_rocm//rocm:hip", ]), linkstatic = True, ) cpplint()
0
apollo_public_repos/apollo/modules/planning/scenarios/park
apollo_public_repos/apollo/modules/planning/scenarios/park/valet_parking/valet_parking_scenario.h
/****************************************************************************** * Copyright 2019 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 **/ #pragma once #include <memory> #include <string> #include "modules/map/hdmap/hdmap_util.h" #include "modules/map/pnc_map/path.h" #include "modules/map/pnc_map/pnc_map.h" #include "modules/common_msgs/map_msgs/map_id.pb.h" #include "modules/planning/scenarios/scenario.h" namespace apollo { namespace planning { namespace scenario { namespace valet_parking { struct ValetParkingContext { ScenarioValetParkingConfig scenario_config; std::string target_parking_spot_id; bool pre_stop_rightaway_flag = false; hdmap::MapPathPoint pre_stop_rightaway_point; }; class ValetParkingScenario : public Scenario { public: ValetParkingScenario(const ScenarioConfig& config, const ScenarioContext* context, const std::shared_ptr<DependencyInjector>& injector) : Scenario(config, context, injector) {} void Init() override; std::unique_ptr<Stage> CreateStage( const ScenarioConfig::StageConfig& stage_config, const std::shared_ptr<DependencyInjector>& injector) override; static bool IsTransferable(const Frame& frame, const double parking_start_range); ValetParkingContext* GetContext() { return &context_; } private: static void RegisterStages(); bool GetScenarioConfig(); static bool SearchTargetParkingSpotOnPath( const hdmap::Path& nearby_path, const std::string& target_parking_id, hdmap::PathOverlap* parking_space_overlap); static bool CheckDistanceToParkingSpot( const Frame& frame, const common::VehicleState& vehicle_state, const hdmap::Path& nearby_path, const double parking_start_range, const hdmap::PathOverlap& parking_space_overlap); private: bool init_ = false; static apollo::common::util::Factory< StageType, Stage, Stage* (*)(const ScenarioConfig::StageConfig& stage_config, const std::shared_ptr<DependencyInjector>& injector)> s_stage_factory_; ValetParkingContext context_; const hdmap::HDMap* hdmap_ = nullptr; }; } // namespace valet_parking } // namespace scenario } // namespace planning } // namespace apollo
0
apollo_public_repos/apollo/modules/planning/scenarios/park
apollo_public_repos/apollo/modules/planning/scenarios/park/valet_parking/valet_parking_scenario.cc
/****************************************************************************** * Copyright 2019 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 **/ #include "modules/planning/scenarios/park/valet_parking/valet_parking_scenario.h" #include "modules/planning/scenarios/park/valet_parking/stage_approaching_parking_spot.h" #include "modules/planning/scenarios/park/valet_parking/stage_parking.h" namespace apollo { namespace planning { namespace scenario { namespace valet_parking { using apollo::common::VehicleState; using apollo::common::math::Vec2d; using apollo::hdmap::ParkingSpaceInfoConstPtr; using apollo::hdmap::Path; using apollo::hdmap::PathOverlap; apollo::common::util::Factory< StageType, Stage, Stage* (*)(const ScenarioConfig::StageConfig& stage_config, const std::shared_ptr<DependencyInjector>& injector)> ValetParkingScenario::s_stage_factory_; void ValetParkingScenario::Init() { if (init_) { return; } Scenario::Init(); if (!GetScenarioConfig()) { AERROR << "fail to get scenario specific config"; return; } hdmap_ = hdmap::HDMapUtil::BaseMapPtr(); CHECK_NOTNULL(hdmap_); } void ValetParkingScenario::RegisterStages() { if (s_stage_factory_.Empty()) { s_stage_factory_.Clear(); } s_stage_factory_.Register( StageType::VALET_PARKING_APPROACHING_PARKING_SPOT, [](const ScenarioConfig::StageConfig& config, const std::shared_ptr<DependencyInjector>& injector) -> Stage* { return new StageApproachingParkingSpot(config, injector); }); s_stage_factory_.Register( StageType::VALET_PARKING_PARKING, [](const ScenarioConfig::StageConfig& config, const std::shared_ptr<DependencyInjector>& injector) -> Stage* { return new StageParking(config, injector); }); } std::unique_ptr<Stage> ValetParkingScenario::CreateStage( const ScenarioConfig::StageConfig& stage_config, const std::shared_ptr<DependencyInjector>& injector) { if (s_stage_factory_.Empty()) { RegisterStages(); } auto ptr = s_stage_factory_.CreateObjectOrNull(stage_config.stage_type(), stage_config, injector); if (ptr) { ptr->SetContext(&context_); } return ptr; } bool ValetParkingScenario::GetScenarioConfig() { if (!config_.has_valet_parking_config()) { AERROR << "miss scenario specific config"; return false; } context_.scenario_config.CopyFrom(config_.valet_parking_config()); return true; } bool ValetParkingScenario::IsTransferable(const Frame& frame, const double parking_start_range) { // TODO(all) Implement available parking spot detection by preception results std::string target_parking_spot_id; if (frame.local_view().routing->routing_request().has_parking_info() && frame.local_view() .routing->routing_request() .parking_info() .has_parking_space_id()) { target_parking_spot_id = frame.local_view() .routing->routing_request() .parking_info() .parking_space_id(); } else { ADEBUG << "No parking space id from routing"; return false; } if (target_parking_spot_id.empty()) { return false; } const auto& nearby_path = frame.reference_line_info().front().reference_line().map_path(); PathOverlap parking_space_overlap; const auto& vehicle_state = frame.vehicle_state(); if (!SearchTargetParkingSpotOnPath(nearby_path, target_parking_spot_id, &parking_space_overlap)) { ADEBUG << "No such parking spot found after searching all path forward " "possible" << target_parking_spot_id; return false; } if (!CheckDistanceToParkingSpot(frame, vehicle_state, nearby_path, parking_start_range, parking_space_overlap)) { ADEBUG << "target parking spot found, but too far, distance larger than " "pre-defined distance" << target_parking_spot_id; return false; } return true; } bool ValetParkingScenario::SearchTargetParkingSpotOnPath( const Path& nearby_path, const std::string& target_parking_id, PathOverlap* parking_space_overlap) { const auto& parking_space_overlaps = nearby_path.parking_space_overlaps(); for (const auto& parking_overlap : parking_space_overlaps) { if (parking_overlap.object_id == target_parking_id) { *parking_space_overlap = parking_overlap; return true; } } return false; } bool ValetParkingScenario::CheckDistanceToParkingSpot( const Frame& frame, const VehicleState& vehicle_state, const Path& nearby_path, const double parking_start_range, const PathOverlap& parking_space_overlap) { // TODO(Jinyun) parking overlap s are wrong on map, not usable // double parking_space_center_s = // (parking_space_overlap.start_s + parking_space_overlap.end_s) / 2.0; const hdmap::HDMap* hdmap = hdmap::HDMapUtil::BaseMapPtr(); hdmap::Id id; id.set_id(parking_space_overlap.object_id); ParkingSpaceInfoConstPtr target_parking_spot_ptr = hdmap->GetParkingSpaceById(id); Vec2d left_bottom_point = target_parking_spot_ptr->polygon().points().at(0); Vec2d right_bottom_point = target_parking_spot_ptr->polygon().points().at(1); const auto &routing_request = frame.local_view().routing->routing_request(); auto corner_point = routing_request.parking_info().corner_point(); left_bottom_point.set_x(corner_point.point().at(0).x()); left_bottom_point.set_y(corner_point.point().at(0).y()); right_bottom_point.set_x(corner_point.point().at(1).x()); right_bottom_point.set_y(corner_point.point().at(1).y()); double left_bottom_point_s = 0.0; double left_bottom_point_l = 0.0; double right_bottom_point_s = 0.0; double right_bottom_point_l = 0.0; nearby_path.GetNearestPoint(left_bottom_point, &left_bottom_point_s, &left_bottom_point_l); nearby_path.GetNearestPoint(right_bottom_point, &right_bottom_point_s, &right_bottom_point_l); double parking_space_center_s = (left_bottom_point_s + right_bottom_point_s) / 2.0; double vehicle_point_s = 0.0; double vehicle_point_l = 0.0; Vec2d vehicle_vec(vehicle_state.x(), vehicle_state.y()); nearby_path.GetNearestPoint(vehicle_vec, &vehicle_point_s, &vehicle_point_l); if (std::abs(parking_space_center_s - vehicle_point_s) < parking_start_range) { return true; } else { return false; } } } // namespace valet_parking } // namespace scenario } // namespace planning } // namespace apollo
0
apollo_public_repos/apollo/modules/planning/scenarios/emergency
apollo_public_repos/apollo/modules/planning/scenarios/emergency/emergency_pull_over/stage_slow_down.cc
/****************************************************************************** * Copyright 2019 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 **/ #include "modules/planning/scenarios/emergency/emergency_pull_over/stage_slow_down.h" #include <memory> #include "cyber/common/log.h" #include "modules/common/vehicle_state/vehicle_state_provider.h" #include "modules/planning/common/frame.h" #include "modules/planning/common/planning_context.h" #include "modules/planning/common/util/common.h" #include "modules/planning/scenarios/util/util.h" #include "modules/planning/tasks/deciders/path_bounds_decider/path_bounds_decider.h" namespace apollo { namespace planning { namespace scenario { namespace emergency_pull_over { using apollo::common::TrajectoryPoint; EmergencyPullOverStageSlowDown::EmergencyPullOverStageSlowDown( const ScenarioConfig::StageConfig& config, const std::shared_ptr<DependencyInjector>& injector) : Stage(config, injector) {} Stage::StageStatus EmergencyPullOverStageSlowDown::Process( const TrajectoryPoint& planning_init_point, Frame* frame) { ADEBUG << "stage: SlowDown"; CHECK_NOTNULL(frame); scenario_config_.CopyFrom(GetContext()->scenario_config); // set cruise_speed to slow down const double adc_speed = injector_->vehicle_state()->linear_velocity(); double target_slow_down_speed = GetContext()->target_slow_down_speed; if (target_slow_down_speed <= 0) { target_slow_down_speed = GetContext()->target_slow_down_speed = std::max( scenario_config_.target_slow_down_speed(), adc_speed - scenario_config_.max_stop_deceleration() * scenario_config_.slow_down_deceleration_time()); } auto& reference_line_info = frame->mutable_reference_line_info()->front(); reference_line_info.SetCruiseSpeed(target_slow_down_speed); bool plan_ok = ExecuteTaskOnReferenceLine(planning_init_point, frame); if (!plan_ok) { AERROR << "EmergencyPullOverStageSlowDown planning error"; } // check slow enough static constexpr double kSpeedTolarence = 1.0; if (adc_speed - target_slow_down_speed <= kSpeedTolarence) { return FinishStage(); } return StageStatus::RUNNING; } Stage::StageStatus EmergencyPullOverStageSlowDown::FinishStage() { auto* pull_over_status = injector_->planning_context() ->mutable_planning_status() ->mutable_pull_over(); pull_over_status->set_plan_pull_over_path(true); next_stage_ = StageType::EMERGENCY_PULL_OVER_APPROACH; return Stage::FINISHED; } } // namespace emergency_pull_over } // namespace scenario } // namespace planning } // namespace apollo
0
apollo_public_repos/apollo/modules/planning/scenarios/emergency
apollo_public_repos/apollo/modules/planning/scenarios/emergency/emergency_pull_over/stage_approach.h
/****************************************************************************** * Copyright 2019 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 **/ #pragma once #include <memory> #include "modules/planning/proto/planning_config.pb.h" #include "modules/planning/scenarios/emergency/emergency_pull_over/emergency_pull_over_scenario.h" #include "modules/planning/scenarios/stage.h" namespace apollo { namespace planning { namespace scenario { namespace emergency_pull_over { struct EmergencyPullOverContext; class EmergencyPullOverStageApproach : public Stage { public: EmergencyPullOverStageApproach( const ScenarioConfig::StageConfig& config, const std::shared_ptr<DependencyInjector>& injector); StageStatus Process(const common::TrajectoryPoint& planning_init_point, Frame* frame) override; EmergencyPullOverContext* GetContext() { return Stage::GetContextAs<EmergencyPullOverContext>(); } Stage::StageStatus FinishStage(); private: ScenarioEmergencyPullOverConfig scenario_config_; }; } // namespace emergency_pull_over } // namespace scenario } // namespace planning } // namespace apollo
0
apollo_public_repos/apollo/modules/planning/scenarios/emergency
apollo_public_repos/apollo/modules/planning/scenarios/emergency/emergency_pull_over/emergency_pull_over_scenario.cc
/****************************************************************************** * Copyright 2019 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 **/ #include "modules/planning/scenarios/emergency/emergency_pull_over/emergency_pull_over_scenario.h" #include <memory> #include "cyber/common/log.h" #include "modules/planning/scenarios/emergency/emergency_pull_over/stage_approach.h" #include "modules/planning/scenarios/emergency/emergency_pull_over/stage_slow_down.h" #include "modules/planning/scenarios/emergency/emergency_pull_over/stage_standby.h" namespace apollo { namespace planning { namespace scenario { namespace emergency_pull_over { apollo::common::util::Factory< StageType, Stage, Stage* (*)(const ScenarioConfig::StageConfig& stage_config, const std::shared_ptr<DependencyInjector>& injector)> EmergencyPullOverScenario::s_stage_factory_; void EmergencyPullOverScenario::Init() { if (init_) { return; } Scenario::Init(); if (!GetScenarioConfig()) { AERROR << "fail to get scenario specific config"; return; } init_ = true; } void EmergencyPullOverScenario::RegisterStages() { if (!s_stage_factory_.Empty()) { s_stage_factory_.Clear(); } s_stage_factory_.Register( StageType::EMERGENCY_PULL_OVER_SLOW_DOWN, [](const ScenarioConfig::StageConfig& config, const std::shared_ptr<DependencyInjector>& injector) -> Stage* { return new EmergencyPullOverStageSlowDown(config, injector); }); s_stage_factory_.Register( StageType::EMERGENCY_PULL_OVER_APPROACH, [](const ScenarioConfig::StageConfig& config, const std::shared_ptr<DependencyInjector>& injector) -> Stage* { return new EmergencyPullOverStageApproach(config, injector); }); s_stage_factory_.Register( StageType::EMERGENCY_PULL_OVER_STANDBY, [](const ScenarioConfig::StageConfig& config, const std::shared_ptr<DependencyInjector>& injector) -> Stage* { return new EmergencyPullOverStageStandby(config, injector); }); } std::unique_ptr<Stage> EmergencyPullOverScenario::CreateStage( const ScenarioConfig::StageConfig& stage_config, const std::shared_ptr<DependencyInjector>& injector) { if (s_stage_factory_.Empty()) { RegisterStages(); } auto ptr = s_stage_factory_.CreateObjectOrNull(stage_config.stage_type(), stage_config, injector); if (ptr) { ptr->SetContext(&context_); } return ptr; } /* * read scenario specific configs and set in context_ for stages to read */ bool EmergencyPullOverScenario::GetScenarioConfig() { if (!config_.has_emergency_pull_over_config()) { AERROR << "miss scenario specific config"; return false; } context_.scenario_config.CopyFrom(config_.emergency_pull_over_config()); return true; } } // namespace emergency_pull_over } // namespace scenario } // namespace planning } // namespace apollo
0
apollo_public_repos/apollo/modules/planning/scenarios/emergency
apollo_public_repos/apollo/modules/planning/scenarios/emergency/emergency_pull_over/stage_approach_test.cc
/****************************************************************************** * Copyright 2019 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. *****************************************************************************/ #include "modules/planning/scenarios/emergency/emergency_pull_over/stage_approach.h" #include "cyber/common/file.h" #include "cyber/common/log.h" #include "gtest/gtest.h" namespace apollo { namespace planning { namespace scenario { namespace emergency_pull_over { class StageApproachTest : public ::testing::Test { public: virtual void SetUp() { config_.set_stage_type(StageType::EMERGENCY_PULL_OVER_APPROACH); injector_ = std::make_shared<DependencyInjector>(); } protected: ScenarioConfig::StageConfig config_; std::shared_ptr<DependencyInjector> injector_; }; TEST_F(StageApproachTest, Init) { EmergencyPullOverStageApproach emergency_pull_over_stage_approach(config_, injector_); EXPECT_EQ(emergency_pull_over_stage_approach.Name(), StageType_Name( StageType::EMERGENCY_PULL_OVER_APPROACH)); } } // namespace emergency_pull_over } // namespace scenario } // namespace planning } // namespace apollo
0
apollo_public_repos/apollo/modules/planning/scenarios/emergency
apollo_public_repos/apollo/modules/planning/scenarios/emergency/emergency_pull_over/stage_standby.h
/****************************************************************************** * Copyright 2019 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 **/ #pragma once #include <memory> #include "modules/planning/proto/planning_config.pb.h" #include "modules/planning/scenarios/emergency/emergency_pull_over/emergency_pull_over_scenario.h" #include "modules/planning/scenarios/stage.h" namespace apollo { namespace planning { namespace scenario { namespace emergency_pull_over { struct EmergencyPullOverContext; class EmergencyPullOverStageStandby : public Stage { public: EmergencyPullOverStageStandby( const ScenarioConfig::StageConfig& config, const std::shared_ptr<DependencyInjector>& injector) : Stage(config, injector) {} private: Stage::StageStatus Process(const common::TrajectoryPoint& planning_init_point, Frame* frame) override; EmergencyPullOverContext* GetContext() { return GetContextAs<EmergencyPullOverContext>(); } private: Stage::StageStatus FinishStage(); private: ScenarioEmergencyPullOverConfig scenario_config_; }; } // namespace emergency_pull_over } // namespace scenario } // namespace planning } // namespace apollo
0
apollo_public_repos/apollo/modules/planning/scenarios/emergency
apollo_public_repos/apollo/modules/planning/scenarios/emergency/emergency_pull_over/stage_slow_down_test.cc
/****************************************************************************** * Copyright 2019 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. *****************************************************************************/ #include "modules/planning/scenarios/emergency/emergency_pull_over/stage_slow_down.h" #include "cyber/common/file.h" #include "cyber/common/log.h" #include "gtest/gtest.h" namespace apollo { namespace planning { namespace scenario { namespace emergency_pull_over { class StageSlowDownTest : public ::testing::Test { public: virtual void SetUp() { config_.set_stage_type(StageType::EMERGENCY_PULL_OVER_SLOW_DOWN); injector_ = std::make_shared<DependencyInjector>(); } protected: ScenarioConfig::StageConfig config_; std::shared_ptr<DependencyInjector> injector_; }; TEST_F(StageSlowDownTest, Init) { EmergencyPullOverStageSlowDown emergency_pull_over_stage_slow_down(config_, injector_); EXPECT_EQ(emergency_pull_over_stage_slow_down.Name(), StageType_Name( StageType::EMERGENCY_PULL_OVER_SLOW_DOWN)); } } // namespace emergency_pull_over } // namespace scenario } // namespace planning } // namespace apollo
0
apollo_public_repos/apollo/modules/planning/scenarios/emergency
apollo_public_repos/apollo/modules/planning/scenarios/emergency/emergency_pull_over/stage_standby.cc
/****************************************************************************** * Copyright 2019 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 **/ #include "modules/planning/scenarios/emergency/emergency_pull_over/stage_standby.h" #include <memory> #include <string> #include <vector> #include "cyber/common/log.h" #include "modules/planning/common/frame.h" #include "modules/planning/common/planning_context.h" #include "modules/planning/common/util/common.h" #include "modules/planning/scenarios/util/util.h" #include "modules/planning/tasks/deciders/path_bounds_decider/path_bounds_decider.h" namespace apollo { namespace planning { namespace scenario { namespace emergency_pull_over { using apollo::common::TrajectoryPoint; using apollo::common::VehicleConfigHelper; using apollo::common::VehicleSignal; Stage::StageStatus EmergencyPullOverStageStandby::Process( const TrajectoryPoint& planning_init_point, Frame* frame) { ADEBUG << "stage: Standby"; CHECK_NOTNULL(frame); scenario_config_.CopyFrom(GetContext()->scenario_config); auto& reference_line_info = frame->mutable_reference_line_info()->front(); // set vehicle signal reference_line_info.SetEmergencyLight(); reference_line_info.SetTurnSignal(VehicleSignal::TURN_NONE); // reset cruise_speed reference_line_info.SetCruiseSpeed(FLAGS_default_cruise_speed); // add a stop fence const auto& pull_over_status = injector_->planning_context()->planning_status().pull_over(); if (pull_over_status.has_position() && pull_over_status.position().has_x() && pull_over_status.position().has_y()) { const auto& reference_line_info = frame->reference_line_info().front(); const auto& reference_line = reference_line_info.reference_line(); common::SLPoint pull_over_sl; reference_line.XYToSL(pull_over_status.position(), &pull_over_sl); const double stop_distance = scenario_config_.stop_distance(); double stop_line_s = pull_over_sl.s() + stop_distance + VehicleConfigHelper::GetConfig().vehicle_param().front_edge_to_center(); const double adc_front_edge_s = reference_line_info.AdcSlBoundary().end_s(); double distance = stop_line_s - adc_front_edge_s; if (distance <= 0.0) { // push stop fence further stop_line_s = adc_front_edge_s + stop_distance; } const std::string virtual_obstacle_id = "EMERGENCY_PULL_OVER"; const std::vector<std::string> wait_for_obstacle_ids; planning::util::BuildStopDecision( virtual_obstacle_id, stop_line_s, stop_distance, StopReasonCode::STOP_REASON_PULL_OVER, wait_for_obstacle_ids, "EMERGENCY_PULL_OVER-scenario", frame, &(frame->mutable_reference_line_info()->front())); ADEBUG << "Build a stop fence for emergency_pull_over: id[" << virtual_obstacle_id << "] s[" << stop_line_s << "]"; } bool plan_ok = ExecuteTaskOnReferenceLine(planning_init_point, frame); if (!plan_ok) { AERROR << "EmergencyPullOverStageStandby planning error"; } return Stage::RUNNING; } Stage::StageStatus EmergencyPullOverStageStandby::FinishStage() { return FinishScenario(); } } // namespace emergency_pull_over } // namespace scenario } // namespace planning } // namespace apollo
0
apollo_public_repos/apollo/modules/planning/scenarios/emergency
apollo_public_repos/apollo/modules/planning/scenarios/emergency/emergency_pull_over/stage_standby_test.cc
/****************************************************************************** * Copyright 2019 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. *****************************************************************************/ #include "modules/planning/scenarios/emergency/emergency_pull_over/stage_standby.h" #include "cyber/common/file.h" #include "cyber/common/log.h" #include "gtest/gtest.h" namespace apollo { namespace planning { namespace scenario { namespace emergency_pull_over { class StageStandbyTest : public ::testing::Test { public: virtual void SetUp() { config_.set_stage_type(StageType::EMERGENCY_PULL_OVER_STANDBY); injector_ = std::make_shared<DependencyInjector>(); } protected: ScenarioConfig::StageConfig config_; std::shared_ptr<DependencyInjector> injector_; }; TEST_F(StageStandbyTest, Init) { EmergencyPullOverStageStandby emergency_pull_over_stage_standby(config_, injector_); EXPECT_EQ(emergency_pull_over_stage_standby.Name(), StageType_Name( StageType::EMERGENCY_PULL_OVER_STANDBY)); } } // namespace emergency_pull_over } // namespace scenario } // namespace planning } // namespace apollo
0
apollo_public_repos/apollo/modules/planning/scenarios/emergency
apollo_public_repos/apollo/modules/planning/scenarios/emergency/emergency_pull_over/stage_approach.cc
/****************************************************************************** * Copyright 2019 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 **/ #include "modules/planning/scenarios/emergency/emergency_pull_over/stage_approach.h" #include <memory> #include <string> #include <vector> #include "cyber/common/log.h" #include "modules/common/vehicle_state/vehicle_state_provider.h" #include "modules/planning/common/frame.h" #include "modules/planning/common/planning_context.h" #include "modules/planning/common/util/common.h" #include "modules/planning/scenarios/util/util.h" #include "modules/planning/tasks/deciders/path_bounds_decider/path_bounds_decider.h" namespace apollo { namespace planning { namespace scenario { namespace emergency_pull_over { using apollo::common::TrajectoryPoint; using apollo::common::VehicleConfigHelper; using apollo::common::VehicleSignal; EmergencyPullOverStageApproach::EmergencyPullOverStageApproach( const ScenarioConfig::StageConfig& config, const std::shared_ptr<DependencyInjector>& injector) : Stage(config, injector) {} Stage::StageStatus EmergencyPullOverStageApproach::Process( const TrajectoryPoint& planning_init_point, Frame* frame) { ADEBUG << "stage: Approach"; CHECK_NOTNULL(frame); scenario_config_.CopyFrom(GetContext()->scenario_config); auto& reference_line_info = frame->mutable_reference_line_info()->front(); // set vehicle signal reference_line_info.SetTurnSignal(VehicleSignal::TURN_RIGHT); double stop_line_s = 0.0; // add a stop fence const auto& pull_over_status = injector_->planning_context()->planning_status().pull_over(); if (pull_over_status.has_position() && pull_over_status.position().has_x() && pull_over_status.position().has_y()) { const auto& reference_line = reference_line_info.reference_line(); common::SLPoint pull_over_sl; reference_line.XYToSL(pull_over_status.position(), &pull_over_sl); const double stop_distance = scenario_config_.stop_distance(); stop_line_s = pull_over_sl.s() + stop_distance + VehicleConfigHelper::GetConfig().vehicle_param().front_edge_to_center(); const std::string virtual_obstacle_id = "EMERGENCY_PULL_OVER"; const std::vector<std::string> wait_for_obstacle_ids; planning::util::BuildStopDecision( virtual_obstacle_id, stop_line_s, stop_distance, StopReasonCode::STOP_REASON_PULL_OVER, wait_for_obstacle_ids, "EMERGENCY_PULL_OVER-scenario", frame, &(frame->mutable_reference_line_info()->front())); ADEBUG << "Build a stop fence for emergency_pull_over: id[" << virtual_obstacle_id << "] s[" << stop_line_s << "]"; } bool plan_ok = ExecuteTaskOnReferenceLine(planning_init_point, frame); if (!plan_ok) { AERROR << "EmergencyPullOverStageApproach planning error"; } if (stop_line_s > 0.0) { const double adc_front_edge_s = reference_line_info.AdcSlBoundary().end_s(); double distance = stop_line_s - adc_front_edge_s; const double adc_speed = injector_->vehicle_state()->linear_velocity(); const double max_adc_stop_speed = common::VehicleConfigHelper::Instance() ->GetConfig() .vehicle_param() .max_abs_speed_when_stopped(); ADEBUG << "adc_speed[" << adc_speed << "] distance[" << distance << "]"; static constexpr double kStopSpeedTolerance = 0.4; static constexpr double kStopDistanceTolerance = 3.0; if (adc_speed <= max_adc_stop_speed + kStopSpeedTolerance && std::fabs(distance) <= kStopDistanceTolerance) { return FinishStage(); } } return StageStatus::RUNNING; } Stage::StageStatus EmergencyPullOverStageApproach::FinishStage() { next_stage_ = StageType::EMERGENCY_PULL_OVER_STANDBY; return Stage::FINISHED; } } // namespace emergency_pull_over } // namespace scenario } // namespace planning } // namespace apollo
0
apollo_public_repos/apollo/modules/planning/scenarios/emergency
apollo_public_repos/apollo/modules/planning/scenarios/emergency/emergency_pull_over/stage_slow_down.h
/****************************************************************************** * Copyright 2019 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 **/ #pragma once #include <memory> #include "modules/planning/proto/planning_config.pb.h" #include "modules/planning/scenarios/emergency/emergency_pull_over/emergency_pull_over_scenario.h" #include "modules/planning/scenarios/stage.h" namespace apollo { namespace planning { namespace scenario { namespace emergency_pull_over { struct EmergencyPullOverContext; class EmergencyPullOverStageSlowDown : public Stage { public: EmergencyPullOverStageSlowDown( const ScenarioConfig::StageConfig& config, const std::shared_ptr<DependencyInjector>& injector); StageStatus Process(const common::TrajectoryPoint& planning_init_point, Frame* frame) override; EmergencyPullOverContext* GetContext() { return Stage::GetContextAs<EmergencyPullOverContext>(); } Stage::StageStatus FinishStage(); private: ScenarioEmergencyPullOverConfig scenario_config_; }; } // namespace emergency_pull_over } // namespace scenario } // namespace planning } // namespace apollo
0
apollo_public_repos/apollo/modules/planning/scenarios/emergency
apollo_public_repos/apollo/modules/planning/scenarios/emergency/emergency_pull_over/emergency_pull_over_scenario_test.cc
/****************************************************************************** * Copyright 2019 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 **/ #include "modules/planning/scenarios/emergency/emergency_pull_over/emergency_pull_over_scenario.h" #include "cyber/common/file.h" #include "cyber/common/log.h" #include "gtest/gtest.h" #include "modules/planning/common/planning_gflags.h" namespace apollo { namespace planning { namespace scenario { namespace emergency_pull_over { class EmergencyPullOverScenarioTest : public ::testing::Test { public: virtual void SetUp() {} protected: std::unique_ptr<EmergencyPullOverScenario> scenario_; }; TEST_F(EmergencyPullOverScenarioTest, Init) { FLAGS_scenario_emergency_pull_over_config_file = "/apollo/modules/planning/conf/scenario" "/emergency_pull_over_config.pb.txt"; ScenarioConfig config; EXPECT_TRUE(apollo::cyber::common::GetProtoFromFile( FLAGS_scenario_emergency_pull_over_config_file, &config)); ScenarioContext context; auto injector = std::make_shared<DependencyInjector>(); scenario_.reset(new EmergencyPullOverScenario(config, &context, injector)); EXPECT_EQ(scenario_->scenario_type(), ScenarioType::EMERGENCY_PULL_OVER); } } // namespace emergency_pull_over } // namespace scenario } // namespace planning } // namespace apollo
0
apollo_public_repos/apollo/modules/planning/scenarios/emergency
apollo_public_repos/apollo/modules/planning/scenarios/emergency/emergency_pull_over/BUILD
load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test") load("//third_party/gpus:common.bzl", "if_cuda", "if_rocm") load("//tools:cpplint.bzl", "cpplint") package(default_visibility = ["//visibility:public"]) cc_library( name = "emergency_pull_over_scenario", srcs = [ "emergency_pull_over_scenario.cc", "stage_approach.cc", "stage_slow_down.cc", "stage_standby.cc", ], hdrs = [ "emergency_pull_over_scenario.h", "stage_approach.h", "stage_slow_down.h", "stage_standby.h", ], copts = ["-DMODULE_NAME=\\\"planning\\\""], deps = [ "//cyber", "//modules/common/util:util_tool", "//modules/common/vehicle_state:vehicle_state_provider", "//modules/planning/common:planning_common", "//modules/planning/common/util:common_lib", "//modules/planning/common/util:util_lib", "//modules/common_msgs/planning_msgs:planning_cc_proto", "//modules/planning/scenarios:scenario", "//modules/planning/scenarios/util:scenario_util_lib", "@com_github_gflags_gflags//:gflags", "@eigen", ], ) cc_test( name = "emergency_pull_over_scenario_test", size = "small", srcs = ["emergency_pull_over_scenario_test.cc"], data = [ "//modules/planning:planning_conf", ], linkopts = ["-lgomp"], deps = [ ":emergency_pull_over_scenario", "@com_google_googletest//:gtest_main", ] + if_cuda([ "@local_config_cuda//cuda:cudart", ]) + if_rocm([ "@local_config_rocm//rocm:hip", ]), linkstatic = True, ) cc_test( name = "stage_slow_down_test", size = "small", srcs = ["stage_slow_down_test.cc"], data = [ "//modules/planning:planning_conf", ], linkopts = ["-lgomp"], deps = [ ":emergency_pull_over_scenario", "@com_google_googletest//:gtest_main", ] + if_cuda([ "@local_config_cuda//cuda:cudart", ]) + if_rocm([ "@local_config_rocm//rocm:hip", ]), linkstatic = True, ) cc_test( name = "stage_approach_test", size = "small", srcs = ["stage_approach_test.cc"], data = [ "//modules/planning:planning_conf", ], linkopts = ["-lgomp"], deps = [ ":emergency_pull_over_scenario", "@com_google_googletest//:gtest_main", ] + if_cuda([ "@local_config_cuda//cuda:cudart", ]) + if_rocm([ "@local_config_rocm//rocm:hip", ]), linkstatic = True, ) cc_test( name = "stage_standby_test", size = "small", srcs = ["stage_standby_test.cc"], data = [ "//modules/planning:planning_conf", ], linkopts = ["-lgomp"], deps = [ ":emergency_pull_over_scenario", "@com_google_googletest//:gtest_main", ] + if_cuda([ "@local_config_cuda//cuda:cudart", ]) + if_rocm([ "@local_config_rocm//rocm:hip", ]), linkstatic = True, ) cpplint()
0
apollo_public_repos/apollo/modules/planning/scenarios/emergency
apollo_public_repos/apollo/modules/planning/scenarios/emergency/emergency_pull_over/emergency_pull_over_scenario.h
/****************************************************************************** * Copyright 2019 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 **/ #pragma once #include <memory> #include "modules/common/util/factory.h" #include "modules/planning/common/frame.h" #include "modules/planning/scenarios/scenario.h" namespace apollo { namespace planning { namespace scenario { namespace emergency_pull_over { // stage context struct EmergencyPullOverContext { ScenarioEmergencyPullOverConfig scenario_config; double target_slow_down_speed = 0.0; }; class EmergencyPullOverScenario : public Scenario { public: EmergencyPullOverScenario(const ScenarioConfig& config, const ScenarioContext* context, const std::shared_ptr<DependencyInjector>& injector) : Scenario(config, context, injector) {} void Init() override; std::unique_ptr<Stage> CreateStage( const ScenarioConfig::StageConfig& stage_config, const std::shared_ptr<DependencyInjector>& injector); EmergencyPullOverContext* GetContext() { return &context_; } private: static void RegisterStages(); bool GetScenarioConfig(); private: static apollo::common::util::Factory< StageType, Stage, Stage* (*)(const ScenarioConfig::StageConfig& stage_config, const std::shared_ptr<DependencyInjector>& injector)> s_stage_factory_; bool init_ = false; EmergencyPullOverContext context_; }; } // namespace emergency_pull_over } // namespace scenario } // namespace planning } // namespace apollo
0
apollo_public_repos/apollo/modules/planning/scenarios/emergency
apollo_public_repos/apollo/modules/planning/scenarios/emergency/emergency_stop/emergency_stop_scenario_test.cc
/****************************************************************************** * Copyright 2019 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 **/ #include "modules/planning/scenarios/emergency/emergency_stop/emergency_stop_scenario.h" #include "cyber/common/file.h" #include "cyber/common/log.h" #include "gtest/gtest.h" #include "modules/planning/common/planning_gflags.h" namespace apollo { namespace planning { namespace scenario { namespace emergency_stop { class EmergencyStopScenarioTest : public ::testing::Test { public: virtual void SetUp() {} protected: std::unique_ptr<EmergencyStopScenario> scenario_; }; TEST_F(EmergencyStopScenarioTest, Init) { FLAGS_scenario_emergency_stop_config_file = "/apollo/modules/planning/conf/scenario" "/emergency_stop_config.pb.txt"; ScenarioConfig config; EXPECT_TRUE(apollo::cyber::common::GetProtoFromFile( FLAGS_scenario_emergency_stop_config_file, &config)); ScenarioContext context; auto injector = std::make_shared<DependencyInjector>(); scenario_.reset(new EmergencyStopScenario(config, &context, injector)); EXPECT_EQ(scenario_->scenario_type(), ScenarioType::EMERGENCY_STOP); } } // namespace emergency_stop } // namespace scenario } // namespace planning } // namespace apollo
0
apollo_public_repos/apollo/modules/planning/scenarios/emergency
apollo_public_repos/apollo/modules/planning/scenarios/emergency/emergency_stop/stage_approach.h
/****************************************************************************** * Copyright 2019 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 **/ #pragma once #include <memory> #include "modules/planning/proto/planning_config.pb.h" #include "modules/planning/scenarios/emergency/emergency_stop/emergency_stop_scenario.h" #include "modules/planning/scenarios/stage.h" namespace apollo { namespace planning { namespace scenario { namespace emergency_stop { struct EmergencyStopContext; class EmergencyStopStageApproach : public Stage { public: EmergencyStopStageApproach( const ScenarioConfig::StageConfig& config, const std::shared_ptr<DependencyInjector>& injector); StageStatus Process(const common::TrajectoryPoint& planning_init_point, Frame* frame) override; EmergencyStopContext* GetContext() { return Stage::GetContextAs<EmergencyStopContext>(); } Stage::StageStatus FinishStage(); private: ScenarioEmergencyStopConfig scenario_config_; }; } // namespace emergency_stop } // namespace scenario } // namespace planning } // namespace apollo
0
apollo_public_repos/apollo/modules/planning/scenarios/emergency
apollo_public_repos/apollo/modules/planning/scenarios/emergency/emergency_stop/stage_approach_test.cc
/****************************************************************************** * Copyright 2019 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. *****************************************************************************/ #include "modules/planning/scenarios/emergency/emergency_stop/stage_approach.h" #include "cyber/common/file.h" #include "cyber/common/log.h" #include "gtest/gtest.h" namespace apollo { namespace planning { namespace scenario { namespace emergency_stop { class StageApproachTest : public ::testing::Test { public: virtual void SetUp() { config_.set_stage_type(StageType::EMERGENCY_STOP_APPROACH); injector_ = std::make_shared<DependencyInjector>(); } protected: ScenarioConfig::StageConfig config_; std::shared_ptr<DependencyInjector> injector_; }; TEST_F(StageApproachTest, Init) { EmergencyStopStageApproach emergency_stop_stage_approach(config_, injector_); EXPECT_EQ( emergency_stop_stage_approach.Name(), StageType_Name(StageType::EMERGENCY_STOP_APPROACH)); } } // namespace emergency_stop } // namespace scenario } // namespace planning } // namespace apollo
0
apollo_public_repos/apollo/modules/planning/scenarios/emergency
apollo_public_repos/apollo/modules/planning/scenarios/emergency/emergency_stop/emergency_stop_scenario.cc
/****************************************************************************** * Copyright 2019 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 **/ #include "modules/planning/scenarios/emergency/emergency_stop/emergency_stop_scenario.h" #include "cyber/common/log.h" #include "modules/planning/scenarios/emergency/emergency_stop/stage_approach.h" #include "modules/planning/scenarios/emergency/emergency_stop/stage_standby.h" namespace apollo { namespace planning { namespace scenario { namespace emergency_stop { apollo::common::util::Factory< StageType, Stage, Stage* (*)(const ScenarioConfig::StageConfig& stage_config, const std::shared_ptr<DependencyInjector>& injector)> EmergencyStopScenario::s_stage_factory_; void EmergencyStopScenario::Init() { if (init_) { return; } Scenario::Init(); if (!GetScenarioConfig()) { AERROR << "fail to get scenario specific config"; return; } init_ = true; } void EmergencyStopScenario::RegisterStages() { if (!s_stage_factory_.Empty()) { s_stage_factory_.Clear(); } s_stage_factory_.Register( StageType::EMERGENCY_STOP_APPROACH, [](const ScenarioConfig::StageConfig& config, const std::shared_ptr<DependencyInjector>& injector) -> Stage* { return new EmergencyStopStageApproach(config, injector); }); s_stage_factory_.Register( StageType::EMERGENCY_STOP_STANDBY, [](const ScenarioConfig::StageConfig& config, const std::shared_ptr<DependencyInjector>& injector) -> Stage* { return new EmergencyStopStageStandby(config, injector); }); } std::unique_ptr<Stage> EmergencyStopScenario::CreateStage( const ScenarioConfig::StageConfig& stage_config, const std::shared_ptr<DependencyInjector>& injector) { if (s_stage_factory_.Empty()) { RegisterStages(); } auto ptr = s_stage_factory_.CreateObjectOrNull(stage_config.stage_type(), stage_config, injector); if (ptr) { ptr->SetContext(&context_); } return ptr; } /* * read scenario specific configs and set in context_ for stages to read */ bool EmergencyStopScenario::GetScenarioConfig() { if (!config_.has_emergency_stop_config()) { AERROR << "miss scenario specific config"; return false; } context_.scenario_config.CopyFrom(config_.emergency_stop_config()); return true; } } // namespace emergency_stop } // namespace scenario } // namespace planning } // namespace apollo
0
apollo_public_repos/apollo/modules/planning/scenarios/emergency
apollo_public_repos/apollo/modules/planning/scenarios/emergency/emergency_stop/stage_standby.h
/****************************************************************************** * Copyright 2019 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 **/ #pragma once #include <memory> #include "modules/planning/proto/planning_config.pb.h" #include "modules/planning/scenarios/emergency/emergency_stop/emergency_stop_scenario.h" #include "modules/planning/scenarios/stage.h" namespace apollo { namespace planning { namespace scenario { namespace emergency_stop { struct EmergencyStopContext; class EmergencyStopStageStandby : public Stage { public: EmergencyStopStageStandby(const ScenarioConfig::StageConfig& config, const std::shared_ptr<DependencyInjector>& injector) : Stage(config, injector) {} private: Stage::StageStatus Process(const common::TrajectoryPoint& planning_init_point, Frame* frame) override; EmergencyStopContext* GetContext() { return GetContextAs<EmergencyStopContext>(); } private: Stage::StageStatus FinishStage(); private: ScenarioEmergencyStopConfig scenario_config_; }; } // namespace emergency_stop } // namespace scenario } // namespace planning } // namespace apollo
0
apollo_public_repos/apollo/modules/planning/scenarios/emergency
apollo_public_repos/apollo/modules/planning/scenarios/emergency/emergency_stop/stage_standby.cc
/****************************************************************************** * Copyright 2019 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 **/ #include "modules/planning/scenarios/emergency/emergency_stop/stage_standby.h" #include <string> #include <vector> #include "cyber/common/log.h" #include "modules/planning/common/frame.h" #include "modules/planning/common/planning_context.h" #include "modules/planning/common/util/common.h" #include "modules/planning/scenarios/util/util.h" #include "modules/planning/tasks/deciders/path_bounds_decider/path_bounds_decider.h" namespace apollo { namespace planning { namespace scenario { namespace emergency_stop { using apollo::common::TrajectoryPoint; Stage::StageStatus EmergencyStopStageStandby::Process( const TrajectoryPoint& planning_init_point, Frame* frame) { ADEBUG << "stage: Standby"; CHECK_NOTNULL(frame); scenario_config_.CopyFrom(GetContext()->scenario_config); // add a stop fence const auto& reference_line_info = frame->reference_line_info().front(); const auto& reference_line = reference_line_info.reference_line(); const double adc_front_edge_s = reference_line_info.AdcSlBoundary().end_s(); const double stop_distance = scenario_config_.stop_distance(); bool stop_fence_exist = false; double stop_line_s; const auto& emergency_stop_status = injector_->planning_context()->planning_status().emergency_stop(); if (emergency_stop_status.has_stop_fence_point()) { common::SLPoint stop_fence_sl; reference_line.XYToSL(emergency_stop_status.stop_fence_point(), &stop_fence_sl); if (stop_fence_sl.s() > adc_front_edge_s) { stop_fence_exist = true; stop_line_s = stop_fence_sl.s(); } } if (!stop_fence_exist) { static constexpr double kBuffer = 2.0; stop_line_s = adc_front_edge_s + stop_distance + kBuffer; const auto& stop_fence_point = reference_line.GetReferencePoint(stop_line_s); auto* emergency_stop_fence_point = injector_->planning_context() ->mutable_planning_status() ->mutable_emergency_stop() ->mutable_stop_fence_point(); emergency_stop_fence_point->set_x(stop_fence_point.x()); emergency_stop_fence_point->set_y(stop_fence_point.y()); } const std::string virtual_obstacle_id = "EMERGENCY_STOP"; const std::vector<std::string> wait_for_obstacle_ids; planning::util::BuildStopDecision( virtual_obstacle_id, stop_line_s, stop_distance, StopReasonCode::STOP_REASON_EMERGENCY, wait_for_obstacle_ids, "EMERGENCY_STOP-scenario", frame, &(frame->mutable_reference_line_info()->front())); ADEBUG << "Build a stop fence for emergency_stop: id[" << virtual_obstacle_id << "] s[" << stop_line_s << "]"; bool plan_ok = ExecuteTaskOnReferenceLine(planning_init_point, frame); if (!plan_ok) { AERROR << "EmergencyStopStageStandby planning error"; } return Stage::RUNNING; } Stage::StageStatus EmergencyStopStageStandby::FinishStage() { return FinishScenario(); } } // namespace emergency_stop } // namespace scenario } // namespace planning } // namespace apollo
0
apollo_public_repos/apollo/modules/planning/scenarios/emergency
apollo_public_repos/apollo/modules/planning/scenarios/emergency/emergency_stop/stage_standby_test.cc
/****************************************************************************** * Copyright 2019 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. *****************************************************************************/ #include "modules/planning/scenarios/emergency/emergency_stop/stage_standby.h" #include "cyber/common/file.h" #include "cyber/common/log.h" #include "gtest/gtest.h" namespace apollo { namespace planning { namespace scenario { namespace emergency_stop { class StageStandbyTest : public ::testing::Test { public: virtual void SetUp() { config_.set_stage_type(StageType::EMERGENCY_STOP_STANDBY); injector_ = std::make_shared<DependencyInjector>(); } protected: ScenarioConfig::StageConfig config_; std::shared_ptr<DependencyInjector> injector_; }; TEST_F(StageStandbyTest, Init) { EmergencyStopStageStandby emergency_stop_stage_standby(config_, injector_); EXPECT_EQ( emergency_stop_stage_standby.Name(), StageType_Name(StageType::EMERGENCY_STOP_STANDBY)); } } // namespace emergency_stop } // namespace scenario } // namespace planning } // namespace apollo
0
apollo_public_repos/apollo/modules/planning/scenarios/emergency
apollo_public_repos/apollo/modules/planning/scenarios/emergency/emergency_stop/stage_approach.cc
/****************************************************************************** * Copyright 2019 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 **/ #include "modules/planning/scenarios/emergency/emergency_stop/stage_approach.h" #include <memory> #include <string> #include <vector> #include "cyber/common/log.h" #include "modules/common/vehicle_state/vehicle_state_provider.h" #include "modules/planning/common/frame.h" #include "modules/planning/common/planning_context.h" #include "modules/planning/common/util/common.h" #include "modules/planning/scenarios/util/util.h" #include "modules/planning/tasks/deciders/path_bounds_decider/path_bounds_decider.h" namespace apollo { namespace planning { namespace scenario { namespace emergency_stop { using apollo::common::TrajectoryPoint; EmergencyStopStageApproach::EmergencyStopStageApproach( const ScenarioConfig::StageConfig& config, const std::shared_ptr<DependencyInjector>& injector) : Stage(config, injector) {} Stage::StageStatus EmergencyStopStageApproach::Process( const TrajectoryPoint& planning_init_point, Frame* frame) { ADEBUG << "stage: Approach"; CHECK_NOTNULL(frame); scenario_config_.CopyFrom(GetContext()->scenario_config); // set vehicle signal frame->mutable_reference_line_info()->front().SetEmergencyLight(); // add a stop fence const auto& reference_line_info = frame->reference_line_info().front(); const auto& reference_line = reference_line_info.reference_line(); const double adc_speed = injector_->vehicle_state()->linear_velocity(); const double adc_front_edge_s = reference_line_info.AdcSlBoundary().end_s(); const double stop_distance = scenario_config_.stop_distance(); bool stop_fence_exist = false; double stop_line_s; const auto& emergency_stop_status = injector_->planning_context()->planning_status().emergency_stop(); if (emergency_stop_status.has_stop_fence_point()) { common::SLPoint stop_fence_sl; reference_line.XYToSL(emergency_stop_status.stop_fence_point(), &stop_fence_sl); if (stop_fence_sl.s() > adc_front_edge_s) { stop_fence_exist = true; stop_line_s = stop_fence_sl.s(); } } if (!stop_fence_exist) { const double deceleration = scenario_config_.max_stop_deceleration(); const double travel_distance = std::ceil(std::pow(adc_speed, 2) / (2 * deceleration)); static constexpr double kBuffer = 2.0; stop_line_s = adc_front_edge_s + travel_distance + stop_distance + kBuffer; ADEBUG << "travel_distance[" << travel_distance << "] [" << adc_speed << "] adc_front_edge_s[" << adc_front_edge_s << "] stop_line_s[" << stop_line_s << "]"; const auto& stop_fence_point = reference_line.GetReferencePoint(stop_line_s); auto* emergency_stop_fence_point = injector_->planning_context() ->mutable_planning_status() ->mutable_emergency_stop() ->mutable_stop_fence_point(); emergency_stop_fence_point->set_x(stop_fence_point.x()); emergency_stop_fence_point->set_y(stop_fence_point.y()); } const std::string virtual_obstacle_id = "EMERGENCY_STOP"; const std::vector<std::string> wait_for_obstacle_ids; planning::util::BuildStopDecision( virtual_obstacle_id, stop_line_s, stop_distance, StopReasonCode::STOP_REASON_EMERGENCY, wait_for_obstacle_ids, "EMERGENCY_STOP-scenario", frame, &(frame->mutable_reference_line_info()->front())); ADEBUG << "Build a stop fence for emergency_stop: id[" << virtual_obstacle_id << "] s[" << stop_line_s << "]"; bool plan_ok = ExecuteTaskOnReferenceLine(planning_init_point, frame); if (!plan_ok) { AERROR << "EmergencyPullOverStageApproach planning error"; } const double max_adc_stop_speed = common::VehicleConfigHelper::Instance() ->GetConfig() .vehicle_param() .max_abs_speed_when_stopped(); if (adc_speed <= max_adc_stop_speed) { return FinishStage(); } return StageStatus::RUNNING; } Stage::StageStatus EmergencyStopStageApproach::FinishStage() { next_stage_ = StageType::EMERGENCY_STOP_STANDBY; return Stage::FINISHED; } } // namespace emergency_stop } // namespace scenario } // namespace planning } // namespace apollo
0
apollo_public_repos/apollo/modules/planning/scenarios/emergency
apollo_public_repos/apollo/modules/planning/scenarios/emergency/emergency_stop/emergency_stop_scenario.h
/****************************************************************************** * Copyright 2019 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 **/ #pragma once #include <memory> #include "modules/common/util/factory.h" #include "modules/planning/common/frame.h" #include "modules/planning/scenarios/scenario.h" namespace apollo { namespace planning { namespace scenario { namespace emergency_stop { // stage context struct EmergencyStopContext { ScenarioEmergencyStopConfig scenario_config; }; class EmergencyStopScenario : public Scenario { public: EmergencyStopScenario(const ScenarioConfig& config, const ScenarioContext* context, const std::shared_ptr<DependencyInjector>& injector) : Scenario(config, context, injector) {} void Init() override; std::unique_ptr<Stage> CreateStage( const ScenarioConfig::StageConfig& stage_config, const std::shared_ptr<DependencyInjector>& injector); EmergencyStopContext* GetContext() { return &context_; } private: static void RegisterStages(); bool GetScenarioConfig(); private: static apollo::common::util::Factory< StageType, Stage, Stage* (*)(const ScenarioConfig::StageConfig& stage_config, const std::shared_ptr<DependencyInjector>& injector)> s_stage_factory_; bool init_ = false; EmergencyStopContext context_; }; } // namespace emergency_stop } // namespace scenario } // namespace planning } // namespace apollo
0
apollo_public_repos/apollo/modules/planning/scenarios/emergency
apollo_public_repos/apollo/modules/planning/scenarios/emergency/emergency_stop/BUILD
load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test") load("//third_party/gpus:common.bzl", "if_cuda", "if_rocm") load("//tools:cpplint.bzl", "cpplint") package(default_visibility = ["//visibility:public"]) cc_library( name = "emergency_stop_scenario", srcs = [ "emergency_stop_scenario.cc", "stage_approach.cc", "stage_standby.cc", ], hdrs = [ "emergency_stop_scenario.h", "stage_approach.h", "stage_standby.h", ], copts = ["-DMODULE_NAME=\\\"planning\\\""], deps = [ "//cyber", "//modules/common/util:util_tool", "//modules/common/vehicle_state:vehicle_state_provider", "//modules/planning/common:planning_common", "//modules/planning/common/util:common_lib", "//modules/planning/common/util:util_lib", "//modules/common_msgs/planning_msgs:planning_cc_proto", "//modules/planning/scenarios:scenario", "//modules/planning/scenarios/util:scenario_util_lib", "@com_github_gflags_gflags//:gflags", "@eigen", ], ) cc_test( name = "emergency_stop_scenario_test", size = "small", srcs = ["emergency_stop_scenario_test.cc"], data = [ "//modules/planning:planning_conf", ], linkopts = ["-lgomp"], deps = [ ":emergency_stop_scenario", "@com_google_googletest//:gtest_main", ] + if_cuda([ "@local_config_cuda//cuda:cudart", ]) + if_rocm([ "@local_config_rocm//rocm:hip", ]), linkstatic = True, ) cc_test( name = "stage_approach_test", size = "small", srcs = ["stage_approach_test.cc"], data = [ "//modules/planning:planning_conf", ], linkopts = ["-lgomp"], deps = [ ":emergency_stop_scenario", "@com_google_googletest//:gtest_main", ] + if_cuda([ "@local_config_cuda//cuda:cudart", ]) + if_rocm([ "@local_config_rocm//rocm:hip", ]), linkstatic = True, ) cc_test( name = "stage_standby_test", size = "small", srcs = ["stage_standby_test.cc"], data = [ "//modules/planning:planning_conf", ], linkopts = ["-lgomp"], deps = [ ":emergency_stop_scenario", "@com_google_googletest//:gtest_main", ] + if_cuda([ "@local_config_cuda//cuda:cudart", ]) + if_rocm([ "@local_config_rocm//rocm:hip", ]), linkstatic = True, ) cpplint()
0
apollo_public_repos/apollo/modules/planning/scenarios/bare_intersection
apollo_public_repos/apollo/modules/planning/scenarios/bare_intersection/unprotected/bare_intersection_unprotected_scenario.cc
/****************************************************************************** * Copyright 2019 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 **/ #include "modules/planning/scenarios/bare_intersection/unprotected/bare_intersection_unprotected_scenario.h" #include <memory> #include "cyber/common/log.h" #include "modules/planning/common/frame.h" #include "modules/planning/common/planning_context.h" #include "modules/planning/proto/planning_config.pb.h" #include "modules/planning/scenarios/bare_intersection/unprotected/stage_approach.h" #include "modules/planning/scenarios/bare_intersection/unprotected/stage_intersection_cruise.h" namespace apollo { namespace planning { namespace scenario { namespace bare_intersection { using apollo::hdmap::HDMapUtil; void BareIntersectionUnprotectedScenario::Init() { if (init_) { return; } Scenario::Init(); if (!GetScenarioConfig()) { AERROR << "fail to get scenario specific config"; return; } const std::string& pnc_junction_overlap_id = injector_->planning_context() ->planning_status() .bare_intersection() .current_pnc_junction_overlap_id(); if (pnc_junction_overlap_id.empty()) { AERROR << "Could not find pnc_junction"; return; } hdmap::PNCJunctionInfoConstPtr pnc_junction = HDMapUtil::BaseMap().GetPNCJunctionById( hdmap::MakeMapId(pnc_junction_overlap_id)); if (!pnc_junction) { AERROR << "Could not find pnc_junction: " << pnc_junction_overlap_id; return; } context_.current_pnc_junction_overlap_id = pnc_junction_overlap_id; init_ = true; } apollo::common::util::Factory< StageType, Stage, Stage* (*)(const ScenarioConfig::StageConfig& stage_config, const std::shared_ptr<DependencyInjector>& injector)> BareIntersectionUnprotectedScenario::s_stage_factory_; void BareIntersectionUnprotectedScenario::RegisterStages() { if (!s_stage_factory_.Empty()) { s_stage_factory_.Clear(); } s_stage_factory_.Register( StageType::BARE_INTERSECTION_UNPROTECTED_APPROACH, [](const ScenarioConfig::StageConfig& config, const std::shared_ptr<DependencyInjector>& injector) -> Stage* { return new BareIntersectionUnprotectedStageApproach(config, injector); }); s_stage_factory_.Register( StageType::BARE_INTERSECTION_UNPROTECTED_INTERSECTION_CRUISE, [](const ScenarioConfig::StageConfig& config, const std::shared_ptr<DependencyInjector>& injector) -> Stage* { return new BareIntersectionUnprotectedStageIntersectionCruise(config, injector); }); } std::unique_ptr<Stage> BareIntersectionUnprotectedScenario::CreateStage( const ScenarioConfig::StageConfig& stage_config, const std::shared_ptr<DependencyInjector>& injector) { if (s_stage_factory_.Empty()) { RegisterStages(); } auto ptr = s_stage_factory_.CreateObjectOrNull(stage_config.stage_type(), stage_config, injector); if (ptr) { ptr->SetContext(&context_); } return ptr; } /* * read scenario specific configs and set in context_ for stages to read */ bool BareIntersectionUnprotectedScenario::GetScenarioConfig() { if (!config_.has_bare_intersection_unprotected_config()) { AERROR << "miss scenario specific config"; return false; } context_.scenario_config = config_.bare_intersection_unprotected_config(); return true; } } // namespace bare_intersection } // namespace scenario } // namespace planning } // namespace apollo
0
apollo_public_repos/apollo/modules/planning/scenarios/bare_intersection
apollo_public_repos/apollo/modules/planning/scenarios/bare_intersection/unprotected/bare_intersection_unprotected_scenario.h
/****************************************************************************** * Copyright 2019 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 **/ #pragma once #include <memory> #include <string> #include "modules/common/util/factory.h" #include "modules/common_msgs/planning_msgs/planning.pb.h" #include "modules/planning/scenarios/scenario.h" namespace apollo { namespace planning { namespace scenario { namespace bare_intersection { // stage context struct BareIntersectionUnprotectedContext { ScenarioBareIntersectionUnprotectedConfig scenario_config; std::string current_pnc_junction_overlap_id; }; class BareIntersectionUnprotectedScenario : public Scenario { public: BareIntersectionUnprotectedScenario( const ScenarioConfig& config, const ScenarioContext* context, const std::shared_ptr<DependencyInjector>& injector) : Scenario(config, context, injector) {} void Init() override; std::unique_ptr<Stage> CreateStage( const ScenarioConfig::StageConfig& stage_config, const std::shared_ptr<DependencyInjector>& injector); BareIntersectionUnprotectedContext* GetContext() { return &context_; } private: static void RegisterStages(); bool GetScenarioConfig(); private: static apollo::common::util::Factory< StageType, Stage, Stage* (*)(const ScenarioConfig::StageConfig& stage_config, const std::shared_ptr<DependencyInjector>& injector)> s_stage_factory_; bool init_ = false; BareIntersectionUnprotectedContext context_; }; } // namespace bare_intersection } // namespace scenario } // namespace planning } // namespace apollo
0
apollo_public_repos/apollo/modules/planning/scenarios/bare_intersection
apollo_public_repos/apollo/modules/planning/scenarios/bare_intersection/unprotected/stage_approach.h
/****************************************************************************** * Copyright 2019 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 **/ #pragma once #include <memory> #include <string> #include <vector> #include "modules/planning/scenarios/bare_intersection/unprotected/bare_intersection_unprotected_scenario.h" #include "modules/planning/scenarios/stage.h" namespace apollo { namespace planning { namespace scenario { namespace bare_intersection { struct BareIntersectionUnprotectedContext; class BareIntersectionUnprotectedStageApproach : public Stage { public: BareIntersectionUnprotectedStageApproach( const ScenarioConfig::StageConfig& config, const std::shared_ptr<DependencyInjector>& injector) : Stage(config, injector) {} private: Stage::StageStatus Process(const common::TrajectoryPoint& planning_init_point, Frame* frame) override; BareIntersectionUnprotectedContext* GetContext() { return GetContextAs<BareIntersectionUnprotectedContext>(); } bool CheckClear(const ReferenceLineInfo& reference_line_info, std::vector<std::string>* wait_for_obstacle_ids); Stage::StageStatus FinishStage(Frame* frame); private: ScenarioBareIntersectionUnprotectedConfig scenario_config_; }; } // namespace bare_intersection } // namespace scenario } // namespace planning } // namespace apollo
0
apollo_public_repos/apollo/modules/planning/scenarios/bare_intersection
apollo_public_repos/apollo/modules/planning/scenarios/bare_intersection/unprotected/stage_approach_test.cc
/****************************************************************************** * Copyright 2019 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. *****************************************************************************/ #include "modules/planning/scenarios/bare_intersection/unprotected/stage_approach.h" #include "cyber/common/file.h" #include "cyber/common/log.h" #include "gtest/gtest.h" namespace apollo { namespace planning { namespace scenario { namespace bare_intersection { class StageApproachTest : public ::testing::Test { public: virtual void SetUp() { config_.set_stage_type( StageType::BARE_INTERSECTION_UNPROTECTED_APPROACH); injector_ = std::make_shared<DependencyInjector>(); } protected: ScenarioConfig::StageConfig config_; std::shared_ptr<DependencyInjector> injector_; }; TEST_F(StageApproachTest, Init) { BareIntersectionUnprotectedStageApproach bare_intersection_unprotected_stage_approach(config_, injector_); EXPECT_EQ(bare_intersection_unprotected_stage_approach.Name(), StageType_Name( StageType::BARE_INTERSECTION_UNPROTECTED_APPROACH)); } } // namespace bare_intersection } // namespace scenario } // namespace planning } // namespace apollo
0
apollo_public_repos/apollo/modules/planning/scenarios/bare_intersection
apollo_public_repos/apollo/modules/planning/scenarios/bare_intersection/unprotected/stage_approach.cc
/****************************************************************************** * Copyright 2019 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 **/ #include "modules/planning/scenarios/bare_intersection/unprotected/stage_approach.h" #include <vector> #include "cyber/common/log.h" #include "modules/map/pnc_map/path.h" #include "modules/planning/common/frame.h" #include "modules/planning/common/planning_context.h" #include "modules/planning/common/util/common.h" #include "modules/planning/scenarios/util/util.h" namespace apollo { namespace planning { namespace scenario { namespace bare_intersection { using apollo::common::TrajectoryPoint; using apollo::hdmap::PathOverlap; Stage::StageStatus BareIntersectionUnprotectedStageApproach::Process( const TrajectoryPoint& planning_init_point, Frame* frame) { ADEBUG << "stage: Approach"; CHECK_NOTNULL(frame); scenario_config_.CopyFrom(GetContext()->scenario_config); bool plan_ok = ExecuteTaskOnReferenceLine(planning_init_point, frame); if (!plan_ok) { AERROR << "BareIntersectionUnprotectedStageApproach planning error"; } const auto& reference_line_info = frame->reference_line_info().front(); const std::string pnc_junction_overlap_id = GetContext()->current_pnc_junction_overlap_id; if (pnc_junction_overlap_id.empty()) { return FinishScenario(); } // get overlap along reference line PathOverlap* current_pnc_junction = scenario::util::GetOverlapOnReferenceLine( reference_line_info, pnc_junction_overlap_id, ReferenceLineInfo::PNC_JUNCTION); if (!current_pnc_junction) { return FinishScenario(); } static constexpr double kPassStopLineBuffer = 0.3; // unit: m const double adc_front_edge_s = reference_line_info.AdcSlBoundary().end_s(); const double distance_adc_to_pnc_junction = current_pnc_junction->start_s - adc_front_edge_s; ADEBUG << "pnc_junction_overlap_id[" << pnc_junction_overlap_id << "] start_s[" << current_pnc_junction->start_s << "] distance_adc_to_pnc_junction[" << distance_adc_to_pnc_junction << "]"; if (distance_adc_to_pnc_junction < -kPassStopLineBuffer) { // passed stop line return FinishStage(frame); } // set cruise_speed to slow down frame->mutable_reference_line_info()->front().SetCruiseSpeed( scenario_config_.approach_cruise_speed()); // set right_of_way_status reference_line_info.SetJunctionRightOfWay(current_pnc_junction->start_s, false); plan_ok = ExecuteTaskOnReferenceLine(planning_init_point, frame); if (!plan_ok) { AERROR << "BareIntersectionUnprotectedStageApproach planning error"; } std::vector<std::string> wait_for_obstacle_ids; bool clear = CheckClear(reference_line_info, &wait_for_obstacle_ids); if (scenario_config_.enable_explicit_stop()) { bool stop = false; static constexpr double kCheckClearDistance = 5.0; // meter static constexpr double kStartWatchDistance = 2.0; // meter if (distance_adc_to_pnc_junction <= kCheckClearDistance && distance_adc_to_pnc_junction >= kStartWatchDistance && !clear) { stop = true; } else if (distance_adc_to_pnc_junction < kStartWatchDistance) { // creeping area auto* bare_intersection_status = injector_->planning_context() ->mutable_planning_status() ->mutable_bare_intersection(); int clear_counter = bare_intersection_status->clear_counter(); clear_counter = clear ? clear_counter + 1 : 0; if (clear_counter >= 5) { clear_counter = 0; // reset } else { stop = true; } // use PlanningContext instead of static counter for multi-ADC bare_intersection_status->set_clear_counter(clear_counter); } if (stop) { // build stop decision ADEBUG << "BuildStopDecision: bare pnc_junction[" << pnc_junction_overlap_id << "] start_s[" << current_pnc_junction->start_s << "]"; const std::string virtual_obstacle_id = "PNC_JUNCTION_" + current_pnc_junction->object_id; planning::util::BuildStopDecision( virtual_obstacle_id, current_pnc_junction->start_s, scenario_config_.stop_distance(), StopReasonCode::STOP_REASON_STOP_SIGN, wait_for_obstacle_ids, "bare intersection", frame, &(frame->mutable_reference_line_info()->front())); } } return Stage::RUNNING; } bool BareIntersectionUnprotectedStageApproach::CheckClear( const ReferenceLineInfo& reference_line_info, std::vector<std::string>* wait_for_obstacle_ids) { // TODO(all): move to conf static constexpr double kConf_min_boundary_t = 6.0; // second static constexpr double kConf_ignore_max_st_min_t = 0.1; // second static constexpr double kConf_ignore_min_st_min_s = 15.0; // meter bool all_far_away = true; for (auto* obstacle : reference_line_info.path_decision().obstacles().Items()) { if (obstacle->IsVirtual() || obstacle->IsStatic()) { continue; } if (obstacle->reference_line_st_boundary().min_t() < kConf_min_boundary_t) { const double kepsilon = 1e-6; double obstacle_traveled_s = obstacle->reference_line_st_boundary().bottom_left_point().s() - obstacle->reference_line_st_boundary().bottom_right_point().s(); ADEBUG << "obstacle[" << obstacle->Id() << "] obstacle_st_min_t[" << obstacle->reference_line_st_boundary().min_t() << "] obstacle_st_min_s[" << obstacle->reference_line_st_boundary().min_s() << "] obstacle_traveled_s[" << obstacle_traveled_s << "]"; // ignore the obstacle which is already on reference line and moving // along the direction of ADC if (obstacle_traveled_s < kepsilon && obstacle->reference_line_st_boundary().min_t() < kConf_ignore_max_st_min_t && obstacle->reference_line_st_boundary().min_s() > kConf_ignore_min_st_min_s) { continue; } wait_for_obstacle_ids->push_back(obstacle->Id()); all_far_away = false; } } return all_far_away; } Stage::StageStatus BareIntersectionUnprotectedStageApproach::FinishStage( Frame* frame) { next_stage_ = StageType::BARE_INTERSECTION_UNPROTECTED_INTERSECTION_CRUISE; // reset cruise_speed auto& reference_line_info = frame->mutable_reference_line_info()->front(); reference_line_info.SetCruiseSpeed(FLAGS_default_cruise_speed); return Stage::FINISHED; } } // namespace bare_intersection } // namespace scenario } // namespace planning } // namespace apollo
0
apollo_public_repos/apollo/modules/planning/scenarios/bare_intersection
apollo_public_repos/apollo/modules/planning/scenarios/bare_intersection/unprotected/stage_intersection_cruise.cc
/****************************************************************************** * Copyright 2019 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 **/ #include "modules/planning/scenarios/bare_intersection/unprotected/stage_intersection_cruise.h" #include <memory> #include "cyber/common/log.h" namespace apollo { namespace planning { namespace scenario { namespace bare_intersection { Stage::StageStatus BareIntersectionUnprotectedStageIntersectionCruise::Process( const common::TrajectoryPoint& planning_init_point, Frame* frame) { ADEBUG << "stage: IntersectionCruise"; CHECK_NOTNULL(frame); bool plan_ok = ExecuteTaskOnReferenceLine(planning_init_point, frame); if (!plan_ok) { AERROR << "StopSignUnprotectedStageIntersectionCruise plan error"; } bool stage_done = stage_impl_.CheckDone( *frame, ScenarioType::BARE_INTERSECTION_UNPROTECTED, config_, injector_->planning_context(), false); if (stage_done) { return FinishStage(); } return Stage::RUNNING; } Stage::StageStatus BareIntersectionUnprotectedStageIntersectionCruise::FinishStage() { return FinishScenario(); } } // namespace bare_intersection } // namespace scenario } // namespace planning } // namespace apollo
0
apollo_public_repos/apollo/modules/planning/scenarios/bare_intersection
apollo_public_repos/apollo/modules/planning/scenarios/bare_intersection/unprotected/bare_intersection_unprotected_scenario_test.cc
/****************************************************************************** * Copyright 2019 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 **/ #include "modules/planning/scenarios/bare_intersection/unprotected/bare_intersection_unprotected_scenario.h" #include "cyber/common/file.h" #include "cyber/common/log.h" #include "gtest/gtest.h" #include "modules/planning/common/planning_gflags.h" namespace apollo { namespace planning { namespace scenario { namespace bare_intersection { class BareIntersectionUnprotectedScenarioTest : public ::testing::Test { public: virtual void SetUp() {} protected: std::unique_ptr<BareIntersectionUnprotectedScenario> scenario_; }; TEST_F(BareIntersectionUnprotectedScenarioTest, Init) { FLAGS_scenario_bare_intersection_unprotected_config_file = "/apollo/modules/planning/conf/" "scenario/bare_intersection_unprotected_config.pb.txt"; ScenarioConfig config; EXPECT_TRUE(apollo::cyber::common::GetProtoFromFile( FLAGS_scenario_bare_intersection_unprotected_config_file, &config)); ScenarioContext context; auto planning_context = std::make_shared<DependencyInjector>(); scenario_.reset(new BareIntersectionUnprotectedScenario(config, &context, planning_context)); EXPECT_EQ(scenario_->scenario_type(), ScenarioType::BARE_INTERSECTION_UNPROTECTED); } } // namespace bare_intersection } // namespace scenario } // namespace planning } // namespace apollo
0
apollo_public_repos/apollo/modules/planning/scenarios/bare_intersection
apollo_public_repos/apollo/modules/planning/scenarios/bare_intersection/unprotected/stage_intersection_cruise.h
/****************************************************************************** * Copyright 2019 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 **/ #pragma once #include <memory> #include "modules/planning/scenarios/bare_intersection/unprotected/bare_intersection_unprotected_scenario.h" #include "modules/planning/scenarios/common/stage_intersection_cruise_impl.h" #include "modules/planning/scenarios/stage.h" namespace apollo { namespace planning { namespace scenario { namespace bare_intersection { struct BareIntersectionUnprotectedContext; class BareIntersectionUnprotectedStageIntersectionCruise : public Stage { public: BareIntersectionUnprotectedStageIntersectionCruise( const ScenarioConfig::StageConfig& config, const std::shared_ptr<DependencyInjector>& injector) : Stage(config, injector) {} private: Stage::StageStatus Process(const common::TrajectoryPoint& planning_init_point, Frame* frame) override; BareIntersectionUnprotectedContext* GetContext() { return GetContextAs<BareIntersectionUnprotectedContext>(); } Stage::StageStatus FinishStage(); private: ScenarioBareIntersectionUnprotectedConfig scenario_config_; StageIntersectionCruiseImpl stage_impl_; }; } // namespace bare_intersection } // namespace scenario } // namespace planning } // namespace apollo
0
apollo_public_repos/apollo/modules/planning/scenarios/bare_intersection
apollo_public_repos/apollo/modules/planning/scenarios/bare_intersection/unprotected/BUILD
load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test") load("//third_party/gpus:common.bzl", "if_cuda", "if_rocm") load("//tools:cpplint.bzl", "cpplint") package(default_visibility = ["//visibility:public"]) cc_library( name = "bare_intersection_unprotected_scenario", srcs = [ "bare_intersection_unprotected_scenario.cc", "stage_approach.cc", "stage_intersection_cruise.cc", ], hdrs = [ "bare_intersection_unprotected_scenario.h", "stage_approach.h", "stage_intersection_cruise.h", ], copts = ["-DMODULE_NAME=\\\"planning\\\""], deps = [ "//cyber", "//modules/common/util", "//modules/common/util:util_tool", "//modules/planning/common/util:common_lib", "//modules/common_msgs/planning_msgs:planning_cc_proto", "//modules/planning/scenarios:scenario", "//modules/planning/scenarios/common:stage_intersection_cruise_impl", "//modules/planning/tasks/deciders/creep_decider", "@com_github_gflags_gflags//:gflags", "@eigen", ] + if_cuda([ "@local_config_cuda//cuda:cudart", ]) + if_rocm([ "@local_config_rocm//rocm:hip", ]), ) cc_test( name = "bare_intersection_unprotected_scenario_test", size = "small", srcs = ["bare_intersection_unprotected_scenario_test.cc"], data = ["//modules/planning:planning_conf"], linkopts = ["-lgomp"], deps = [ ":bare_intersection_unprotected_scenario", "@com_google_googletest//:gtest_main", ] + if_cuda([ "@local_config_cuda//cuda:cudart", ]) + if_rocm([ "@local_config_rocm//rocm:hip", ]), linkstatic = True, ) cc_test( name = "stage_approach_test", size = "small", srcs = ["stage_approach_test.cc"], data = [ "//modules/planning:planning_conf", ], linkopts = ["-lgomp"], deps = [ ":bare_intersection_unprotected_scenario", "@com_google_googletest//:gtest_main", ], linkstatic = True, ) cpplint()
0
apollo_public_repos/apollo/modules/planning/scenarios
apollo_public_repos/apollo/modules/planning/scenarios/common/stage_intersection_cruise_impl.h
/****************************************************************************** * Copyright 2019 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 **/ #pragma once #include "modules/planning/common/frame.h" #include "modules/planning/proto/planning_config.pb.h" namespace apollo { namespace planning { namespace scenario { class StageIntersectionCruiseImpl { public: bool CheckDone(const Frame& frame, const ScenarioType& scenario_type, const ScenarioConfig::StageConfig& config, const PlanningContext* context, const bool right_of_way_status); }; } // namespace scenario } // namespace planning } // namespace apollo
0
apollo_public_repos/apollo/modules/planning/scenarios
apollo_public_repos/apollo/modules/planning/scenarios/common/stage_intersection_cruise_impl.cc
/****************************************************************************** * Copyright 2019 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 **/ #include "modules/planning/scenarios/common/stage_intersection_cruise_impl.h" #include <string> #include "cyber/common/log.h" #include "modules/map/pnc_map/path.h" #include "modules/planning/common/planning_context.h" #include "modules/planning/common/util/util.h" #include "modules/planning/scenarios/util/util.h" namespace apollo { namespace planning { namespace scenario { bool StageIntersectionCruiseImpl::CheckDone( const Frame& frame, const ScenarioType& scenario_type, const ScenarioConfig::StageConfig& config, const PlanningContext* context, const bool right_of_way_status) { const auto& reference_line_info = frame.reference_line_info().front(); const auto& junction_overlaps = reference_line_info.reference_line().map_path().junction_overlaps(); if (junction_overlaps.empty()) { // TODO(all): remove when pnc_junction completely available on map // pnc_junction not exist on map, use current traffic_sign's end_s // get traffic sign overlap along reference line hdmap::PathOverlap* traffic_sign_overlap = nullptr; if (scenario_type == ScenarioType::STOP_SIGN_PROTECTED || scenario_type == ScenarioType::STOP_SIGN_UNPROTECTED) { // stop_sign scenarios const auto& stop_sign_status = context->planning_status().stop_sign(); const std::string traffic_sign_overlap_id = stop_sign_status.current_stop_sign_overlap_id(); traffic_sign_overlap = scenario::util::GetOverlapOnReferenceLine( reference_line_info, traffic_sign_overlap_id, ReferenceLineInfo::STOP_SIGN); } else if (scenario_type == ScenarioType::TRAFFIC_LIGHT_PROTECTED || scenario_type == ScenarioType::TRAFFIC_LIGHT_UNPROTECTED_LEFT_TURN || scenario_type == ScenarioType::TRAFFIC_LIGHT_UNPROTECTED_RIGHT_TURN) { // traffic_light scenarios const auto& traffic_light_status = context->planning_status().traffic_light(); const std::string traffic_sign_overlap_id = traffic_light_status.current_traffic_light_overlap_id_size() > 0 ? traffic_light_status.current_traffic_light_overlap_id(0) : ""; traffic_sign_overlap = scenario::util::GetOverlapOnReferenceLine( reference_line_info, traffic_sign_overlap_id, ReferenceLineInfo::SIGNAL); } else if (scenario_type == ScenarioType::YIELD_SIGN) { // yield_sign scenarios const auto& yield_sign_status = context->planning_status().yield_sign(); const std::string traffic_sign_overlap_id = yield_sign_status.current_yield_sign_overlap_id_size() > 0 ? yield_sign_status.current_yield_sign_overlap_id(0) : ""; traffic_sign_overlap = scenario::util::GetOverlapOnReferenceLine( reference_line_info, traffic_sign_overlap_id, ReferenceLineInfo::YIELD_SIGN); } if (!traffic_sign_overlap) { return true; } static constexpr double kIntersectionPassDist = 20.0; // unit: m const double adc_back_edge_s = reference_line_info.AdcSlBoundary().start_s(); const double distance_adc_pass_traffic_sign = adc_back_edge_s - traffic_sign_overlap->end_s; ADEBUG << "distance_adc_pass_traffic_sign[" << distance_adc_pass_traffic_sign << "] traffic_sign_end_s[" << traffic_sign_overlap->end_s << "]"; // set right_of_way_status reference_line_info.SetJunctionRightOfWay(traffic_sign_overlap->start_s, right_of_way_status); return distance_adc_pass_traffic_sign >= kIntersectionPassDist; } if (!planning::util::CheckInsideJunction(reference_line_info)) { return true; } // set right_of_way_status hdmap::PathOverlap junction_overlap; const double adc_front_edge_s = reference_line_info.AdcSlBoundary().end_s(); reference_line_info.GetJunction(adc_front_edge_s, &junction_overlap); reference_line_info.SetJunctionRightOfWay(junction_overlap.start_s, right_of_way_status); return false; } } // namespace scenario } // namespace planning } // namespace apollo
0
apollo_public_repos/apollo/modules/planning/scenarios
apollo_public_repos/apollo/modules/planning/scenarios/common/BUILD
load("@rules_cc//cc:defs.bzl", "cc_library") load("//tools:cpplint.bzl", "cpplint") package(default_visibility = ["//visibility:public"]) cc_library( name = "stage_intersection_cruise_impl", srcs = ["stage_intersection_cruise_impl.cc"], hdrs = ["stage_intersection_cruise_impl.h"], copts = ["-DMODULE_NAME=\\\"planning\\\""], deps = [ "//modules/planning/common:planning_common", "//modules/planning/common/util:util_lib", "//modules/planning/scenarios/util:scenario_util_lib", ], ) cpplint()
0
apollo_public_repos/apollo/modules/planning/scenarios/traffic_light
apollo_public_repos/apollo/modules/planning/scenarios/traffic_light/unprotected_left_turn/traffic_light_unprotected_left_turn_scenario.h
/****************************************************************************** * Copyright 2018 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 **/ #pragma once #include <memory> #include <string> #include <vector> #include "modules/common/util/factory.h" #include "modules/map/hdmap/hdmap.h" #include "modules/common_msgs/planning_msgs/planning.pb.h" #include "modules/planning/scenarios/scenario.h" namespace apollo { namespace planning { namespace scenario { namespace traffic_light { // stage context struct TrafficLightUnprotectedLeftTurnContext { ScenarioTrafficLightUnprotectedLeftTurnConfig scenario_config; std::vector<std::string> current_traffic_light_overlap_ids; double creep_start_time; }; class TrafficLightUnprotectedLeftTurnScenario : public Scenario { public: TrafficLightUnprotectedLeftTurnScenario( const ScenarioConfig& config, const ScenarioContext* context, const std::shared_ptr<DependencyInjector>& injector) : Scenario(config, context, injector) {} void Init() override; std::unique_ptr<Stage> CreateStage( const ScenarioConfig::StageConfig& stage_config, const std::shared_ptr<DependencyInjector>& injector); TrafficLightUnprotectedLeftTurnContext* GetContext() { return &context_; } private: static void RegisterStages(); bool GetScenarioConfig(); private: static apollo::common::util::Factory< StageType, Stage, Stage* (*)(const ScenarioConfig::StageConfig& stage_config, const std::shared_ptr<DependencyInjector>& injector)> s_stage_factory_; bool init_ = false; TrafficLightUnprotectedLeftTurnContext context_; }; } // namespace traffic_light } // namespace scenario } // namespace planning } // namespace apollo
0
apollo_public_repos/apollo/modules/planning/scenarios/traffic_light
apollo_public_repos/apollo/modules/planning/scenarios/traffic_light/unprotected_left_turn/stage_approach.h
/****************************************************************************** * Copyright 2019 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 **/ #pragma once #include <memory> #include "modules/planning/proto/planning_config.pb.h" #include "modules/planning/scenarios/stage.h" #include "modules/planning/scenarios/traffic_light/unprotected_left_turn/traffic_light_unprotected_left_turn_scenario.h" namespace apollo { namespace planning { namespace scenario { namespace traffic_light { struct TrafficLightUnprotectedLeftTurnContext; class TrafficLightUnprotectedLeftTurnStageApproach : public Stage { public: TrafficLightUnprotectedLeftTurnStageApproach( const ScenarioConfig::StageConfig& config, const std::shared_ptr<DependencyInjector>& injector) : Stage(config, injector) {} private: Stage::StageStatus Process(const common::TrajectoryPoint& planning_init_point, Frame* frame) override; TrafficLightUnprotectedLeftTurnContext* GetContext() { return Stage::GetContextAs<TrafficLightUnprotectedLeftTurnContext>(); } private: Stage::StageStatus FinishStage(Frame* frame); private: ScenarioTrafficLightUnprotectedLeftTurnConfig scenario_config_; }; } // namespace traffic_light } // namespace scenario } // namespace planning } // namespace apollo
0
apollo_public_repos/apollo/modules/planning/scenarios/traffic_light
apollo_public_repos/apollo/modules/planning/scenarios/traffic_light/unprotected_left_turn/stage_creep_test.cc
/****************************************************************************** * Copyright 2019 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. *****************************************************************************/ #include "modules/planning/scenarios/traffic_light/unprotected_left_turn/stage_creep.h" #include "cyber/common/file.h" #include "cyber/common/log.h" #include "gtest/gtest.h" #include "modules/planning/common/planning_gflags.h" namespace apollo { namespace planning { namespace scenario { namespace traffic_light { class TrafficLightUnprotectedLeftTurnStageCreepTest : public ::testing::Test { public: virtual void SetUp() { config_.set_stage_type( StageType::TRAFFIC_LIGHT_UNPROTECTED_LEFT_TURN_CREEP); injector_ = std::make_shared<DependencyInjector>(); } protected: ScenarioConfig::StageConfig config_; std::shared_ptr<DependencyInjector> injector_; }; TEST_F(TrafficLightUnprotectedLeftTurnStageCreepTest, Init) { TrafficLightUnprotectedLeftTurnStageCreep traffic_light_unprotected_left_turn_stage_creep(config_, injector_); EXPECT_EQ(traffic_light_unprotected_left_turn_stage_creep.Name(), StageType_Name( StageType::TRAFFIC_LIGHT_UNPROTECTED_LEFT_TURN_CREEP)); } } // namespace traffic_light } // namespace scenario } // namespace planning } // namespace apollo
0
apollo_public_repos/apollo/modules/planning/scenarios/traffic_light
apollo_public_repos/apollo/modules/planning/scenarios/traffic_light/unprotected_left_turn/stage_creep.h
/****************************************************************************** * Copyright 2018 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 **/ #pragma once #include <memory> #include "modules/planning/proto/planning_config.pb.h" #include "modules/planning/scenarios/stage.h" #include "modules/planning/scenarios/traffic_light/unprotected_left_turn/traffic_light_unprotected_left_turn_scenario.h" namespace apollo { namespace planning { namespace scenario { namespace traffic_light { struct TrafficLightUnprotectedLeftTurnContext; class TrafficLightUnprotectedLeftTurnStageCreep : public Stage { public: TrafficLightUnprotectedLeftTurnStageCreep( const ScenarioConfig::StageConfig& config, const std::shared_ptr<DependencyInjector>& injector) : Stage(config, injector) {} private: Stage::StageStatus Process(const common::TrajectoryPoint& planning_init_point, Frame* frame) override; TrafficLightUnprotectedLeftTurnContext* GetContext() { return Stage::GetContextAs<TrafficLightUnprotectedLeftTurnContext>(); } private: Stage::StageStatus FinishStage(); private: ScenarioTrafficLightUnprotectedLeftTurnConfig scenario_config_; }; } // namespace traffic_light } // namespace scenario } // namespace planning } // namespace apollo
0
apollo_public_repos/apollo/modules/planning/scenarios/traffic_light
apollo_public_repos/apollo/modules/planning/scenarios/traffic_light/unprotected_left_turn/stage_approach_test.cc
/****************************************************************************** * Copyright 2019 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. *****************************************************************************/ #include "modules/planning/scenarios/traffic_light/unprotected_left_turn/stage_approach.h" #include "cyber/common/file.h" #include "cyber/common/log.h" #include "gtest/gtest.h" #include "modules/planning/common/planning_gflags.h" namespace apollo { namespace planning { namespace scenario { namespace traffic_light { class TrafficLightUnprotectedLeftTurnStageApproachTest : public ::testing::Test { public: virtual void SetUp() { config_.set_stage_type( StageType::TRAFFIC_LIGHT_UNPROTECTED_LEFT_TURN_APPROACH); injector_ = std::make_shared<DependencyInjector>(); } protected: ScenarioConfig::StageConfig config_; std::shared_ptr<DependencyInjector> injector_; }; TEST_F(TrafficLightUnprotectedLeftTurnStageApproachTest, Init) { TrafficLightUnprotectedLeftTurnStageApproach traffic_light_unprotected_left_turn_stage_approach(config_, injector_); EXPECT_EQ(traffic_light_unprotected_left_turn_stage_approach.Name(), StageType_Name( StageType::TRAFFIC_LIGHT_UNPROTECTED_LEFT_TURN_APPROACH)); } } // namespace traffic_light } // namespace scenario } // namespace planning } // namespace apollo
0
apollo_public_repos/apollo/modules/planning/scenarios/traffic_light
apollo_public_repos/apollo/modules/planning/scenarios/traffic_light/unprotected_left_turn/stage_creep.cc
/****************************************************************************** * Copyright 2018 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 **/ #include "modules/planning/scenarios/traffic_light/unprotected_left_turn/stage_creep.h" #include <string> #include "cyber/common/log.h" #include "cyber/time/clock.h" #include "modules/common_msgs/perception_msgs/traffic_light_detection.pb.h" #include "modules/planning/common/frame.h" #include "modules/planning/common/planning_context.h" #include "modules/planning/common/speed_profile_generator.h" #include "modules/planning/scenarios/util/util.h" #include "modules/planning/tasks/deciders/creep_decider/creep_decider.h" namespace apollo { namespace planning { namespace scenario { namespace traffic_light { using apollo::common::TrajectoryPoint; using apollo::cyber::Clock; using apollo::hdmap::PathOverlap; Stage::StageStatus TrafficLightUnprotectedLeftTurnStageCreep::Process( const TrajectoryPoint& planning_init_point, Frame* frame) { ADEBUG << "stage: Creep"; CHECK_NOTNULL(frame); scenario_config_.CopyFrom(GetContext()->scenario_config); if (!config_.enabled()) { return FinishStage(); } bool plan_ok = ExecuteTaskOnReferenceLine(planning_init_point, frame); if (!plan_ok) { AERROR << "TrafficLightUnprotectedLeftTurnStageCreep planning error"; } if (GetContext()->current_traffic_light_overlap_ids.empty()) { return FinishScenario(); } const auto& reference_line_info = frame->reference_line_info().front(); const std::string traffic_light_overlap_id = GetContext()->current_traffic_light_overlap_ids[0]; PathOverlap* current_traffic_light_overlap = scenario::util::GetOverlapOnReferenceLine(reference_line_info, traffic_light_overlap_id, ReferenceLineInfo::SIGNAL); if (!current_traffic_light_overlap) { return FinishScenario(); } // set right_of_way_status reference_line_info.SetJunctionRightOfWay( current_traffic_light_overlap->start_s, false); // creep // note: don't check traffic light color while creeping on right turn const double wait_time = Clock::NowInSeconds() - GetContext()->creep_start_time; const double timeout_sec = scenario_config_.creep_timeout_sec(); auto* task = dynamic_cast<CreepDecider*>(FindTask(TaskConfig::CREEP_DECIDER)); if (task == nullptr) { AERROR << "task is nullptr"; return FinishStage(); } double creep_stop_s = current_traffic_light_overlap->end_s + task->FindCreepDistance(*frame, reference_line_info); const double distance = creep_stop_s - reference_line_info.AdcSlBoundary().end_s(); if (distance <= 0.0) { auto& rfl_info = frame->mutable_reference_line_info()->front(); *(rfl_info.mutable_speed_data()) = SpeedProfileGenerator::GenerateFixedDistanceCreepProfile(0.0, 0); } if (task->CheckCreepDone(*frame, reference_line_info, current_traffic_light_overlap->end_s, wait_time, timeout_sec)) { return FinishStage(); } return Stage::RUNNING; } Stage::StageStatus TrafficLightUnprotectedLeftTurnStageCreep::FinishStage() { next_stage_ = StageType::TRAFFIC_LIGHT_UNPROTECTED_LEFT_TURN_INTERSECTION_CRUISE; return Stage::FINISHED; } } // namespace traffic_light } // namespace scenario } // namespace planning } // namespace apollo
0
apollo_public_repos/apollo/modules/planning/scenarios/traffic_light
apollo_public_repos/apollo/modules/planning/scenarios/traffic_light/unprotected_left_turn/stage_approach.cc
/****************************************************************************** * Copyright 2019 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 **/ #include "modules/planning/scenarios/traffic_light/unprotected_left_turn/stage_approach.h" #include "cyber/common/log.h" #include "cyber/time/clock.h" #include "modules/common/vehicle_state/vehicle_state_provider.h" #include "modules/common_msgs/perception_msgs/perception_obstacle.pb.h" #include "modules/common_msgs/perception_msgs/traffic_light_detection.pb.h" #include "modules/planning/common/frame.h" #include "modules/planning/common/planning_context.h" #include "modules/planning/common/speed_profile_generator.h" #include "modules/planning/scenarios/util/util.h" #include "modules/planning/tasks/deciders/creep_decider/creep_decider.h" namespace apollo { namespace planning { namespace scenario { namespace traffic_light { using apollo::common::TrajectoryPoint; using apollo::cyber::Clock; using apollo::hdmap::PathOverlap; using apollo::perception::TrafficLight; Stage::StageStatus TrafficLightUnprotectedLeftTurnStageApproach::Process( const TrajectoryPoint& planning_init_point, Frame* frame) { ADEBUG << "stage: Approach"; CHECK_NOTNULL(frame); scenario_config_.CopyFrom(GetContext()->scenario_config); if (!config_.enabled()) { return FinishStage(frame); } // set cruise_speed to slow down frame->mutable_reference_line_info()->front().SetCruiseSpeed( scenario_config_.approach_cruise_speed()); bool plan_ok = ExecuteTaskOnReferenceLine(planning_init_point, frame); if (!plan_ok) { AERROR << "TrafficLightUnprotectedLeftTurnStageApproach planning error"; } if (GetContext()->current_traffic_light_overlap_ids.empty()) { return FinishScenario(); } const auto& reference_line_info = frame->reference_line_info().front(); const double adc_front_edge_s = reference_line_info.AdcSlBoundary().end_s(); PathOverlap* traffic_light = nullptr; bool traffic_light_all_done = true; for (const auto& traffic_light_overlap_id : GetContext()->current_traffic_light_overlap_ids) { // get overlap along reference line PathOverlap* current_traffic_light_overlap = scenario::util::GetOverlapOnReferenceLine(reference_line_info, traffic_light_overlap_id, ReferenceLineInfo::SIGNAL); if (!current_traffic_light_overlap) { continue; } traffic_light = current_traffic_light_overlap; // set right_of_way_status reference_line_info.SetJunctionRightOfWay( current_traffic_light_overlap->start_s, false); const double distance_adc_to_stop_line = current_traffic_light_overlap->start_s - adc_front_edge_s; auto signal_color = frame->GetSignal(traffic_light_overlap_id).color(); ADEBUG << "traffic_light_overlap_id[" << traffic_light_overlap_id << "] start_s[" << current_traffic_light_overlap->start_s << "] distance_adc_to_stop_line[" << distance_adc_to_stop_line << "] color[" << signal_color << "]"; if (distance_adc_to_stop_line < 0) return FinishStage(frame); // check on traffic light color and distance to stop line if (signal_color != TrafficLight::GREEN || distance_adc_to_stop_line >= scenario_config_.max_valid_stop_distance()) { traffic_light_all_done = false; break; } } if (traffic_light == nullptr) { return FinishScenario(); } if (traffic_light_all_done) { return FinishStage(frame); } return Stage::RUNNING; } Stage::StageStatus TrafficLightUnprotectedLeftTurnStageApproach::FinishStage( Frame* frame) { // check speed at stop_stage const double adc_speed = injector_->vehicle_state()->linear_velocity(); if (adc_speed > scenario_config_.max_adc_speed_before_creep()) { // skip creep next_stage_ = StageType :: TRAFFIC_LIGHT_UNPROTECTED_LEFT_TURN_INTERSECTION_CRUISE; } else { // creep // update PlanningContext injector_->planning_context() ->mutable_planning_status() ->mutable_traffic_light() ->mutable_done_traffic_light_overlap_id() ->Clear(); for (const auto& traffic_light_overlap_id : GetContext()->current_traffic_light_overlap_ids) { injector_->planning_context() ->mutable_planning_status() ->mutable_traffic_light() ->add_done_traffic_light_overlap_id(traffic_light_overlap_id); } GetContext()->creep_start_time = Clock::NowInSeconds(); next_stage_ = StageType::TRAFFIC_LIGHT_UNPROTECTED_LEFT_TURN_CREEP; } // reset cruise_speed auto& reference_line_info = frame->mutable_reference_line_info()->front(); reference_line_info.SetCruiseSpeed(FLAGS_default_cruise_speed); return Stage::FINISHED; } } // namespace traffic_light } // namespace scenario } // namespace planning } // namespace apollo
0
apollo_public_repos/apollo/modules/planning/scenarios/traffic_light
apollo_public_repos/apollo/modules/planning/scenarios/traffic_light/unprotected_left_turn/stage_intersection_cruise.cc
/****************************************************************************** * Copyright 2018 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 **/ #include "modules/planning/scenarios/traffic_light/unprotected_left_turn/stage_intersection_cruise.h" #include "cyber/common/log.h" namespace apollo { namespace planning { namespace scenario { namespace traffic_light { Stage::StageStatus TrafficLightUnprotectedLeftTurnStageIntersectionCruise::Process( const common::TrajectoryPoint& planning_init_point, Frame* frame) { ADEBUG << "stage: IntersectionCruise"; CHECK_NOTNULL(frame); bool plan_ok = ExecuteTaskOnReferenceLine(planning_init_point, frame); if (!plan_ok) { AERROR << "TrafficLightUnprotectedLeftTurnStageIntersectionCruise " << "plan error"; } bool stage_done = stage_impl_.CheckDone( *frame, ScenarioType::TRAFFIC_LIGHT_UNPROTECTED_LEFT_TURN, config_, injector_->planning_context(), true); if (stage_done) { return FinishStage(); } return Stage::RUNNING; } Stage::StageStatus TrafficLightUnprotectedLeftTurnStageIntersectionCruise::FinishStage() { return FinishScenario(); } } // namespace traffic_light } // namespace scenario } // namespace planning } // namespace apollo
0
apollo_public_repos/apollo/modules/planning/scenarios/traffic_light
apollo_public_repos/apollo/modules/planning/scenarios/traffic_light/unprotected_left_turn/traffic_light_unprotected_left_turn_scenario.cc
/****************************************************************************** * Copyright 2018 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 **/ #include "modules/planning/scenarios/traffic_light/unprotected_left_turn/traffic_light_unprotected_left_turn_scenario.h" #include "cyber/common/log.h" #include "cyber/time/clock.h" #include "modules/common/vehicle_state/vehicle_state_provider.h" #include "modules/common_msgs/perception_msgs/perception_obstacle.pb.h" #include "modules/common_msgs/perception_msgs/traffic_light_detection.pb.h" #include "modules/planning/common/frame.h" #include "modules/planning/common/planning_context.h" #include "modules/planning/proto/planning_config.pb.h" #include "modules/planning/scenarios/traffic_light/unprotected_left_turn/stage_approach.h" #include "modules/planning/scenarios/traffic_light/unprotected_left_turn/stage_creep.h" #include "modules/planning/scenarios/traffic_light/unprotected_left_turn/stage_intersection_cruise.h" namespace apollo { namespace planning { namespace scenario { namespace traffic_light { using apollo::hdmap::HDMapUtil; void TrafficLightUnprotectedLeftTurnScenario::Init() { if (init_) { return; } Scenario::Init(); if (!GetScenarioConfig()) { AERROR << "fail to get scenario specific config"; return; } const auto& traffic_light_status = injector_->planning_context()->planning_status().traffic_light(); if (traffic_light_status.current_traffic_light_overlap_id().empty()) { AERROR << "Could not find traffic-light(s)"; return; } context_.current_traffic_light_overlap_ids.clear(); for (int i = 0; i < traffic_light_status.current_traffic_light_overlap_id_size(); i++) { const std::string traffic_light_overlap_id = traffic_light_status.current_traffic_light_overlap_id(i); hdmap::SignalInfoConstPtr traffic_light = HDMapUtil::BaseMap().GetSignalById( hdmap::MakeMapId(traffic_light_overlap_id)); if (!traffic_light) { AERROR << "Could not find traffic light: " << traffic_light_overlap_id; } context_.current_traffic_light_overlap_ids.push_back( traffic_light_overlap_id); } init_ = true; } apollo::common::util::Factory< StageType, Stage, Stage* (*)(const ScenarioConfig::StageConfig& stage_config, const std::shared_ptr<DependencyInjector>& injector)> TrafficLightUnprotectedLeftTurnScenario::s_stage_factory_; void TrafficLightUnprotectedLeftTurnScenario::RegisterStages() { if (!s_stage_factory_.Empty()) { s_stage_factory_.Clear(); } s_stage_factory_.Register( StageType::TRAFFIC_LIGHT_UNPROTECTED_LEFT_TURN_APPROACH, [](const ScenarioConfig::StageConfig& config, const std::shared_ptr<DependencyInjector>& injector) -> Stage* { return new TrafficLightUnprotectedLeftTurnStageApproach(config, injector); }); s_stage_factory_.Register( StageType::TRAFFIC_LIGHT_UNPROTECTED_LEFT_TURN_CREEP, [](const ScenarioConfig::StageConfig& config, const std::shared_ptr<DependencyInjector>& injector) -> Stage* { return new TrafficLightUnprotectedLeftTurnStageCreep(config, injector); }); s_stage_factory_.Register( StageType::TRAFFIC_LIGHT_UNPROTECTED_LEFT_TURN_INTERSECTION_CRUISE, [](const ScenarioConfig::StageConfig& config, const std::shared_ptr<DependencyInjector>& injector) -> Stage* { return new TrafficLightUnprotectedLeftTurnStageIntersectionCruise( config, injector); }); } std::unique_ptr<Stage> TrafficLightUnprotectedLeftTurnScenario::CreateStage( const ScenarioConfig::StageConfig& stage_config, const std::shared_ptr<DependencyInjector>& injector) { if (s_stage_factory_.Empty()) { RegisterStages(); } auto ptr = s_stage_factory_.CreateObjectOrNull(stage_config.stage_type(), stage_config, injector); if (ptr) { ptr->SetContext(&context_); } return ptr; } /* * read scenario specific configs and set in context_ for stages to read */ bool TrafficLightUnprotectedLeftTurnScenario::GetScenarioConfig() { if (!config_.has_traffic_light_unprotected_left_turn_config()) { AERROR << "miss scenario specific config"; return false; } context_.scenario_config.CopyFrom( config_.traffic_light_unprotected_left_turn_config()); return true; } } // namespace traffic_light } // namespace scenario } // namespace planning } // namespace apollo
0
apollo_public_repos/apollo/modules/planning/scenarios/traffic_light
apollo_public_repos/apollo/modules/planning/scenarios/traffic_light/unprotected_left_turn/stage_intersection_cruise.h
/****************************************************************************** * Copyright 2018 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 **/ #pragma once #include <memory> #include "modules/planning/scenarios/common/stage_intersection_cruise_impl.h" #include "modules/planning/scenarios/stage.h" #include "modules/planning/scenarios/traffic_light/unprotected_left_turn/traffic_light_unprotected_left_turn_scenario.h" namespace apollo { namespace planning { namespace scenario { namespace traffic_light { struct TrafficLightUnprotectedLeftTurnContext; class TrafficLightUnprotectedLeftTurnStageIntersectionCruise : public Stage { public: TrafficLightUnprotectedLeftTurnStageIntersectionCruise( const ScenarioConfig::StageConfig& config, const std::shared_ptr<DependencyInjector>& injector) : Stage(config, injector) {} private: Stage::StageStatus Process(const common::TrajectoryPoint& planning_init_point, Frame* frame) override; TrafficLightUnprotectedLeftTurnContext* GetContext() { return GetContextAs<TrafficLightUnprotectedLeftTurnContext>(); } Stage::StageStatus FinishStage(); private: ScenarioTrafficLightUnprotectedLeftTurnConfig scenario_config_; StageIntersectionCruiseImpl stage_impl_; }; } // namespace traffic_light } // namespace scenario } // namespace planning } // namespace apollo
0
apollo_public_repos/apollo/modules/planning/scenarios/traffic_light
apollo_public_repos/apollo/modules/planning/scenarios/traffic_light/unprotected_left_turn/BUILD
load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test") load("//tools:cpplint.bzl", "cpplint") load("//third_party/gpus:common.bzl", "if_cuda", "if_rocm") package(default_visibility = ["//visibility:public"]) cc_library( name = "traffic_light_unprotected_left_turn_scenario", srcs = [ "stage_approach.cc", "stage_creep.cc", "stage_intersection_cruise.cc", "traffic_light_unprotected_left_turn_scenario.cc", ], hdrs = [ "stage_approach.h", "stage_creep.h", "stage_intersection_cruise.h", "traffic_light_unprotected_left_turn_scenario.h", ], copts = ["-DMODULE_NAME=\\\"planning\\\""], deps = [ "//cyber", "//modules/common/util", "//modules/common/util:util_tool", "//modules/common_msgs/planning_msgs:planning_cc_proto", "//modules/planning/scenarios:scenario", "//modules/planning/scenarios/common:stage_intersection_cruise_impl", "//modules/planning/tasks/deciders/creep_decider", "@com_github_gflags_gflags//:gflags", "@eigen", ] + if_cuda([ "@local_config_cuda//cuda:cudart", ]) + if_rocm([ "@local_config_rocm//rocm:hip", ]), ) cc_test( name = "traffic_light_left_turn_unprotected_scenario_test", size = "small", srcs = ["traffic_light_unprotected_left_turn_scenario_test.cc"], data = ["//modules/planning:planning_conf"], linkopts = ["-lgomp"], deps = [ ":traffic_light_unprotected_left_turn_scenario", "@com_google_googletest//:gtest_main", ], linkstatic = True, ) cc_test( name = "stage_approach_test", size = "small", srcs = ["stage_approach_test.cc"], data = [ "//modules/planning:planning_conf", ], linkopts = ["-lgomp"], deps = [ ":traffic_light_unprotected_left_turn_scenario", "@com_google_googletest//:gtest_main", ], linkstatic = True, ) cc_test( name = "stage_creep_test", size = "small", srcs = ["stage_creep_test.cc"], data = [ "//modules/planning:planning_conf", ], linkopts = ["-lgomp"], deps = [ ":traffic_light_unprotected_left_turn_scenario", "@com_google_googletest//:gtest_main", ], linkstatic = True, ) cpplint()
0
apollo_public_repos/apollo/modules/planning/scenarios/traffic_light
apollo_public_repos/apollo/modules/planning/scenarios/traffic_light/unprotected_left_turn/traffic_light_unprotected_left_turn_scenario_test.cc
/****************************************************************************** * Copyright 2018 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 **/ #include "modules/planning/scenarios/traffic_light/unprotected_left_turn/traffic_light_unprotected_left_turn_scenario.h" #include "cyber/common/file.h" #include "cyber/common/log.h" #include "gtest/gtest.h" #include "modules/planning/common/planning_gflags.h" namespace apollo { namespace planning { namespace scenario { namespace traffic_light { class TrafficLightUnprotectedLeftTurnScenarioTest : public ::testing::Test { public: virtual void SetUp() {} protected: std::unique_ptr<TrafficLightUnprotectedLeftTurnScenario> scenario_; }; TEST_F(TrafficLightUnprotectedLeftTurnScenarioTest, Init) { FLAGS_scenario_traffic_light_unprotected_left_turn_config_file = "/apollo/modules/planning/conf/" "scenario/traffic_light_unprotected_left_turn_config.pb.txt"; ScenarioConfig config; EXPECT_TRUE(apollo::cyber::common::GetProtoFromFile( FLAGS_scenario_traffic_light_unprotected_left_turn_config_file, &config)); ScenarioContext context; auto injector = std::make_shared<DependencyInjector>(); scenario_.reset( new TrafficLightUnprotectedLeftTurnScenario(config, &context, injector)); EXPECT_EQ(scenario_->scenario_type(), ScenarioType::TRAFFIC_LIGHT_UNPROTECTED_LEFT_TURN); } } // namespace traffic_light } // namespace scenario } // namespace planning } // namespace apollo
0
apollo_public_repos/apollo/modules/planning/scenarios/traffic_light
apollo_public_repos/apollo/modules/planning/scenarios/traffic_light/unprotected_right_turn/stage_stop.cc
/****************************************************************************** * Copyright 2018 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 **/ #include "modules/planning/scenarios/traffic_light/unprotected_right_turn/stage_stop.h" #include "cyber/common/log.h" #include "cyber/time/clock.h" #include "modules/common/vehicle_state/vehicle_state_provider.h" #include "modules/map/pnc_map/path.h" #include "modules/planning/common/frame.h" #include "modules/planning/common/planning_context.h" #include "modules/planning/common/util/util.h" #include "modules/planning/scenarios/util/util.h" namespace apollo { namespace planning { namespace scenario { namespace traffic_light { using apollo::common::TrajectoryPoint; using apollo::cyber::Clock; using apollo::hdmap::HDMapUtil; using apollo::hdmap::PathOverlap; using apollo::perception::TrafficLight; Stage::StageStatus TrafficLightUnprotectedRightTurnStageStop::Process( const TrajectoryPoint& planning_init_point, Frame* frame) { ADEBUG << "stage: Stop"; CHECK_NOTNULL(frame); scenario_config_.CopyFrom(GetContext()->scenario_config); bool plan_ok = ExecuteTaskOnReferenceLine(planning_init_point, frame); if (!plan_ok) { AERROR << "TrafficLightRightTurnUnprotectedStop planning error"; } if (GetContext()->current_traffic_light_overlap_ids.empty()) { return FinishScenario(); } const auto& reference_line_info = frame->reference_line_info().front(); const double adc_front_edge_s = reference_line_info.AdcSlBoundary().end_s(); bool traffic_light_all_stop = true; bool traffic_light_all_green = true; bool traffic_light_no_right_turn_on_red = false; PathOverlap* current_traffic_light_overlap = nullptr; for (const auto& traffic_light_overlap_id : GetContext()->current_traffic_light_overlap_ids) { // get overlap along reference line current_traffic_light_overlap = scenario::util::GetOverlapOnReferenceLine( reference_line_info, traffic_light_overlap_id, ReferenceLineInfo::SIGNAL); if (!current_traffic_light_overlap) { continue; } // set right_of_way_status reference_line_info.SetJunctionRightOfWay( current_traffic_light_overlap->start_s, false); const double distance_adc_to_stop_line = current_traffic_light_overlap->start_s - adc_front_edge_s; auto signal_color = frame->GetSignal(traffic_light_overlap_id).color(); ADEBUG << "traffic_light_overlap_id[" << traffic_light_overlap_id << "] start_s[" << current_traffic_light_overlap->start_s << "] distance_adc_to_stop_line[" << distance_adc_to_stop_line << "] color[" << signal_color << "]"; // check distance to stop line if (distance_adc_to_stop_line > scenario_config_.max_valid_stop_distance()) { traffic_light_all_stop = false; break; } // check on traffic light color if (signal_color != TrafficLight::GREEN) { traffic_light_all_green = false; traffic_light_no_right_turn_on_red = CheckTrafficLightNoRightTurnOnRed(traffic_light_overlap_id); break; } } if (traffic_light_all_stop && traffic_light_all_green) { return FinishStage(true); } if (!traffic_light_no_right_turn_on_red) { if (traffic_light_all_stop && !traffic_light_all_green) { // check distance pass stop line const double distance_adc_pass_stop_line = adc_front_edge_s - current_traffic_light_overlap->end_s; ADEBUG << "distance_adc_pass_stop_line[" << distance_adc_pass_stop_line << "]"; if (distance_adc_pass_stop_line > scenario_config_.min_pass_s_distance()) { return FinishStage(false); } if (scenario_config_.enable_right_turn_on_red()) { // when right_turn_on_red is enabled // check on wait-time if (GetContext()->stop_start_time == 0.0) { GetContext()->stop_start_time = Clock::NowInSeconds(); } else { auto start_time = GetContext()->stop_start_time; const double wait_time = Clock::NowInSeconds() - start_time; ADEBUG << "stop_start_time[" << start_time << "] wait_time[" << wait_time << "]"; if (wait_time > scenario_config_.red_light_right_turn_stop_duration_sec()) { return FinishStage(false); } } } } } return Stage::RUNNING; } bool TrafficLightUnprotectedRightTurnStageStop:: CheckTrafficLightNoRightTurnOnRed(const std::string& traffic_light_id) { hdmap::SignalInfoConstPtr traffic_light_ptr = HDMapUtil::BaseMap().GetSignalById(hdmap::MakeMapId(traffic_light_id)); if (!traffic_light_ptr) { return false; } const auto& signal = traffic_light_ptr->signal(); for (int i = 0; i < signal.sign_info_size(); i++) { if (signal.sign_info(i).type() == hdmap::SignInfo::NO_RIGHT_TURN_ON_RED) { return true; } } return false; } Stage::StageStatus TrafficLightUnprotectedRightTurnStageStop::FinishStage( const bool protected_mode) { if (protected_mode) { // intersection_cruise next_stage_ = StageType :: TRAFFIC_LIGHT_UNPROTECTED_RIGHT_TURN_INTERSECTION_CRUISE; } else { // check speed at stop_stage const double adc_speed = injector_->vehicle_state()->linear_velocity(); if (adc_speed > scenario_config_.max_adc_speed_before_creep()) { // skip creep next_stage_ = StageType :: TRAFFIC_LIGHT_UNPROTECTED_RIGHT_TURN_INTERSECTION_CRUISE; } else { // creep // update PlanningContext injector_->planning_context() ->mutable_planning_status() ->mutable_traffic_light() ->mutable_done_traffic_light_overlap_id() ->Clear(); for (const auto& traffic_light_overlap_id : GetContext()->current_traffic_light_overlap_ids) { injector_->planning_context() ->mutable_planning_status() ->mutable_traffic_light() ->add_done_traffic_light_overlap_id(traffic_light_overlap_id); } GetContext()->creep_start_time = Clock::NowInSeconds(); next_stage_ = StageType::TRAFFIC_LIGHT_UNPROTECTED_RIGHT_TURN_CREEP; } } return Stage::FINISHED; } } // namespace traffic_light } // namespace scenario } // namespace planning } // namespace apollo
0
apollo_public_repos/apollo/modules/planning/scenarios/traffic_light
apollo_public_repos/apollo/modules/planning/scenarios/traffic_light/unprotected_right_turn/stage_creep_test.cc
/****************************************************************************** * Copyright 2019 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. *****************************************************************************/ #include "modules/planning/scenarios/traffic_light/unprotected_right_turn/stage_creep.h" #include "cyber/common/file.h" #include "cyber/common/log.h" #include "gtest/gtest.h" #include "modules/planning/common/planning_gflags.h" namespace apollo { namespace planning { namespace scenario { namespace traffic_light { class TrafficLightUnprotectedRightTurnStageCreepTest : public ::testing::Test { public: virtual void SetUp() { config_.set_stage_type( StageType::TRAFFIC_LIGHT_UNPROTECTED_RIGHT_TURN_STOP); injector_ = std::make_shared<DependencyInjector>(); } protected: ScenarioConfig::StageConfig config_; std::shared_ptr<DependencyInjector> injector_; }; TEST_F(TrafficLightUnprotectedRightTurnStageCreepTest, Init) { TrafficLightUnprotectedRightTurnStageCreep traffic_light_unprotected_right_turn_stage_creep(config_, injector_); EXPECT_EQ(traffic_light_unprotected_right_turn_stage_creep.Name(), StageType_Name( StageType::TRAFFIC_LIGHT_UNPROTECTED_RIGHT_TURN_STOP)); } } // namespace traffic_light } // namespace scenario } // namespace planning } // namespace apollo
0
apollo_public_repos/apollo/modules/planning/scenarios/traffic_light
apollo_public_repos/apollo/modules/planning/scenarios/traffic_light/unprotected_right_turn/stage_creep.h
/****************************************************************************** * Copyright 2018 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 **/ #pragma once #include <memory> #include "modules/planning/proto/planning_config.pb.h" #include "modules/planning/scenarios/stage.h" #include "modules/planning/scenarios/traffic_light/unprotected_right_turn/traffic_light_unprotected_right_turn_scenario.h" namespace apollo { namespace planning { namespace scenario { namespace traffic_light { struct TrafficLightUnprotectedRightTurnContext; class TrafficLightUnprotectedRightTurnStageCreep : public Stage { public: TrafficLightUnprotectedRightTurnStageCreep( const ScenarioConfig::StageConfig& config, const std::shared_ptr<DependencyInjector>& injector) : Stage(config, injector) {} private: Stage::StageStatus Process(const common::TrajectoryPoint& planning_init_point, Frame* frame) override; TrafficLightUnprotectedRightTurnContext* GetContext() { return Stage::GetContextAs<TrafficLightUnprotectedRightTurnContext>(); } private: Stage::StageStatus FinishStage(); private: ScenarioTrafficLightUnprotectedRightTurnConfig scenario_config_; }; } // namespace traffic_light } // namespace scenario } // namespace planning } // namespace apollo
0
apollo_public_repos/apollo/modules/planning/scenarios/traffic_light
apollo_public_repos/apollo/modules/planning/scenarios/traffic_light/unprotected_right_turn/stage_creep.cc
/****************************************************************************** * Copyright 2018 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 **/ #include "modules/planning/scenarios/traffic_light/unprotected_right_turn/stage_creep.h" #include <string> #include "cyber/common/log.h" #include "cyber/time/clock.h" #include "modules/common/vehicle_state/vehicle_state_provider.h" #include "modules/map/pnc_map/path.h" #include "modules/common_msgs/perception_msgs/perception_obstacle.pb.h" #include "modules/common_msgs/perception_msgs/traffic_light_detection.pb.h" #include "modules/planning/common/frame.h" #include "modules/planning/common/planning_context.h" #include "modules/planning/common/speed_profile_generator.h" #include "modules/planning/common/util/util.h" #include "modules/planning/scenarios/util/util.h" #include "modules/planning/tasks/deciders/creep_decider/creep_decider.h" namespace apollo { namespace planning { namespace scenario { namespace traffic_light { using apollo::common::TrajectoryPoint; using apollo::cyber::Clock; using apollo::hdmap::PathOverlap; Stage::StageStatus TrafficLightUnprotectedRightTurnStageCreep::Process( const TrajectoryPoint& planning_init_point, Frame* frame) { ADEBUG << "stage: Creep"; CHECK_NOTNULL(frame); scenario_config_.CopyFrom(GetContext()->scenario_config); if (!config_.enabled()) { return FinishStage(); } bool plan_ok = ExecuteTaskOnReferenceLine(planning_init_point, frame); if (!plan_ok) { AERROR << "TrafficLightUnprotectedRightTurnStageCreep planning error"; } if (GetContext()->current_traffic_light_overlap_ids.empty()) { return FinishScenario(); } const auto& reference_line_info = frame->reference_line_info().front(); const std::string traffic_light_overlap_id = GetContext()->current_traffic_light_overlap_ids[0]; PathOverlap* current_traffic_light_overlap = scenario::util::GetOverlapOnReferenceLine(reference_line_info, traffic_light_overlap_id, ReferenceLineInfo::SIGNAL); if (!current_traffic_light_overlap) { return FinishScenario(); } // set right_of_way_status reference_line_info.SetJunctionRightOfWay( current_traffic_light_overlap->start_s, false); // creep // note: don't check traffic light color while creeping on right turn const double wait_time = Clock::NowInSeconds() - GetContext()->creep_start_time; const double timeout_sec = scenario_config_.creep_timeout_sec(); auto* task = dynamic_cast<CreepDecider*>(FindTask(TaskConfig::CREEP_DECIDER)); if (task == nullptr) { AERROR << "task is nullptr"; return FinishStage(); } double creep_stop_s = current_traffic_light_overlap->end_s + task->FindCreepDistance(*frame, reference_line_info); const double distance = creep_stop_s - reference_line_info.AdcSlBoundary().end_s(); if (distance <= 0.0) { auto& rfl_info = frame->mutable_reference_line_info()->front(); *(rfl_info.mutable_speed_data()) = SpeedProfileGenerator::GenerateFixedDistanceCreepProfile(0.0, 0); } if (task->CheckCreepDone(*frame, reference_line_info, current_traffic_light_overlap->end_s, wait_time, timeout_sec)) { return FinishStage(); } return Stage::RUNNING; } Stage::StageStatus TrafficLightUnprotectedRightTurnStageCreep::FinishStage() { next_stage_ = StageType::TRAFFIC_LIGHT_UNPROTECTED_RIGHT_TURN_INTERSECTION_CRUISE; return Stage::FINISHED; } } // namespace traffic_light } // namespace scenario } // namespace planning } // namespace apollo
0
apollo_public_repos/apollo/modules/planning/scenarios/traffic_light
apollo_public_repos/apollo/modules/planning/scenarios/traffic_light/unprotected_right_turn/stage_intersection_cruise.cc
/****************************************************************************** * Copyright 2018 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 **/ #include "modules/planning/scenarios/traffic_light/unprotected_right_turn/stage_intersection_cruise.h" #include "cyber/common/log.h" namespace apollo { namespace planning { namespace scenario { namespace traffic_light { Stage::StageStatus TrafficLightUnprotectedRightTurnStageIntersectionCruise::Process( const common::TrajectoryPoint& planning_init_point, Frame* frame) { ADEBUG << "stage: IntersectionCruise"; CHECK_NOTNULL(frame); bool plan_ok = ExecuteTaskOnReferenceLine(planning_init_point, frame); if (!plan_ok) { AERROR << "TrafficLightUnprotectedRightTurnStageIntersectionCruise " << "plan error"; } bool stage_done = stage_impl_.CheckDone( *frame, ScenarioType::TRAFFIC_LIGHT_UNPROTECTED_RIGHT_TURN, config_, injector_->planning_context(), false); if (stage_done) { return FinishStage(); } return Stage::RUNNING; } Stage::StageStatus TrafficLightUnprotectedRightTurnStageIntersectionCruise::FinishStage() { return FinishScenario(); } } // namespace traffic_light } // namespace scenario } // namespace planning } // namespace apollo
0
apollo_public_repos/apollo/modules/planning/scenarios/traffic_light
apollo_public_repos/apollo/modules/planning/scenarios/traffic_light/unprotected_right_turn/traffic_light_unprotected_right_turn_scenario.cc
/****************************************************************************** * Copyright 2018 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 **/ #include "modules/planning/scenarios/traffic_light/unprotected_right_turn/traffic_light_unprotected_right_turn_scenario.h" #include "cyber/common/log.h" #include "cyber/time/clock.h" #include "modules/common/vehicle_state/vehicle_state_provider.h" #include "modules/common_msgs/perception_msgs/perception_obstacle.pb.h" #include "modules/common_msgs/perception_msgs/traffic_light_detection.pb.h" #include "modules/planning/common/frame.h" #include "modules/planning/common/planning_context.h" #include "modules/planning/proto/planning_config.pb.h" #include "modules/planning/scenarios/traffic_light/unprotected_right_turn/stage_creep.h" #include "modules/planning/scenarios/traffic_light/unprotected_right_turn/stage_intersection_cruise.h" #include "modules/planning/scenarios/traffic_light/unprotected_right_turn/stage_stop.h" namespace apollo { namespace planning { namespace scenario { namespace traffic_light { using apollo::hdmap::HDMapUtil; void TrafficLightUnprotectedRightTurnScenario::Init() { if (init_) { return; } Scenario::Init(); if (!GetScenarioConfig()) { AERROR << "fail to get scenario specific config"; return; } const auto& traffic_light_status = injector_->planning_context()->planning_status().traffic_light(); if (traffic_light_status.current_traffic_light_overlap_id().empty()) { AERROR << "Could not find traffic-light(s)"; return; } context_.current_traffic_light_overlap_ids.clear(); for (int i = 0; i < traffic_light_status.current_traffic_light_overlap_id_size(); i++) { const std::string traffic_light_overlap_id = traffic_light_status.current_traffic_light_overlap_id(i); hdmap::SignalInfoConstPtr traffic_light = HDMapUtil::BaseMap().GetSignalById( hdmap::MakeMapId(traffic_light_overlap_id)); if (!traffic_light) { AERROR << "Could not find traffic light: " << traffic_light_overlap_id; } context_.current_traffic_light_overlap_ids.push_back( traffic_light_overlap_id); } init_ = true; } apollo::common::util::Factory< StageType, Stage, Stage* (*)(const ScenarioConfig::StageConfig& stage_config, const std::shared_ptr<DependencyInjector>& injector)> TrafficLightUnprotectedRightTurnScenario::s_stage_factory_; void TrafficLightUnprotectedRightTurnScenario::RegisterStages() { if (!s_stage_factory_.Empty()) { s_stage_factory_.Clear(); } s_stage_factory_.Register( StageType::TRAFFIC_LIGHT_UNPROTECTED_RIGHT_TURN_STOP, [](const ScenarioConfig::StageConfig& config, const std::shared_ptr<DependencyInjector>& injector) -> Stage* { return new TrafficLightUnprotectedRightTurnStageStop(config, injector); }); s_stage_factory_.Register( StageType::TRAFFIC_LIGHT_UNPROTECTED_RIGHT_TURN_CREEP, [](const ScenarioConfig::StageConfig& config, const std::shared_ptr<DependencyInjector>& injector) -> Stage* { return new TrafficLightUnprotectedRightTurnStageCreep(config, injector); }); s_stage_factory_.Register( StageType::TRAFFIC_LIGHT_UNPROTECTED_RIGHT_TURN_INTERSECTION_CRUISE, [](const ScenarioConfig::StageConfig& config, const std::shared_ptr<DependencyInjector>& injector) -> Stage* { return new TrafficLightUnprotectedRightTurnStageIntersectionCruise( config, injector); }); } std::unique_ptr<Stage> TrafficLightUnprotectedRightTurnScenario::CreateStage( const ScenarioConfig::StageConfig& stage_config, const std::shared_ptr<DependencyInjector>& injector) { if (s_stage_factory_.Empty()) { RegisterStages(); } auto ptr = s_stage_factory_.CreateObjectOrNull(stage_config.stage_type(), stage_config, injector); if (ptr) { ptr->SetContext(&context_); } return ptr; } /* * read scenario specific configs and set in context_ for stages to read */ bool TrafficLightUnprotectedRightTurnScenario::GetScenarioConfig() { if (!config_.has_traffic_light_unprotected_right_turn_config()) { AERROR << "miss scenario specific config"; return false; } context_.scenario_config.CopyFrom( config_.traffic_light_unprotected_right_turn_config()); return true; } } // namespace traffic_light } // namespace scenario } // namespace planning } // namespace apollo
0
apollo_public_repos/apollo/modules/planning/scenarios/traffic_light
apollo_public_repos/apollo/modules/planning/scenarios/traffic_light/unprotected_right_turn/stage_stop.h
/****************************************************************************** * Copyright 2018 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 **/ #pragma once #include <memory> #include <string> #include "modules/planning/scenarios/stage.h" #include "modules/planning/scenarios/traffic_light/unprotected_right_turn/traffic_light_unprotected_right_turn_scenario.h" namespace apollo { namespace planning { namespace scenario { namespace traffic_light { struct TrafficLightUnprotectedRightTurnContext; class TrafficLightUnprotectedRightTurnStageStop : public Stage { public: TrafficLightUnprotectedRightTurnStageStop( const ScenarioConfig::StageConfig& config, const std::shared_ptr<DependencyInjector>& injector) : Stage(config, injector) {} private: Stage::StageStatus Process(const common::TrajectoryPoint& planning_init_point, Frame* frame) override; TrafficLightUnprotectedRightTurnContext* GetContext() { return GetContextAs<TrafficLightUnprotectedRightTurnContext>(); } bool CheckTrafficLightNoRightTurnOnRed(const std::string& traffic_light_id); Stage::StageStatus FinishStage(const bool protected_mode); private: ScenarioTrafficLightUnprotectedRightTurnConfig scenario_config_; }; } // namespace traffic_light } // namespace scenario } // namespace planning } // namespace apollo
0
apollo_public_repos/apollo/modules/planning/scenarios/traffic_light
apollo_public_repos/apollo/modules/planning/scenarios/traffic_light/unprotected_right_turn/traffic_light_unprotected_right_turn_scenario_test.cc
/****************************************************************************** * Copyright 2018 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 **/ #include "modules/planning/scenarios/traffic_light/unprotected_right_turn/traffic_light_unprotected_right_turn_scenario.h" #include "cyber/common/file.h" #include "cyber/common/log.h" #include "gtest/gtest.h" #include "modules/planning/common/planning_gflags.h" namespace apollo { namespace planning { namespace scenario { namespace traffic_light { class TrafficLightUnprotectedRightTurnScenarioTest : public ::testing::Test { public: virtual void SetUp() {} protected: std::unique_ptr<TrafficLightUnprotectedRightTurnScenario> scenario_; }; TEST_F(TrafficLightUnprotectedRightTurnScenarioTest, Init) { FLAGS_scenario_traffic_light_unprotected_right_turn_config_file = "/apollo/modules/planning/conf/" "scenario/traffic_light_unprotected_right_turn_config.pb.txt"; ScenarioConfig config; EXPECT_TRUE(apollo::cyber::common::GetProtoFromFile( FLAGS_scenario_traffic_light_unprotected_right_turn_config_file, &config)); ScenarioContext context; auto injector = std::make_shared<DependencyInjector>(); scenario_.reset( new TrafficLightUnprotectedRightTurnScenario(config, &context, injector)); EXPECT_EQ(scenario_->scenario_type(), ScenarioType::TRAFFIC_LIGHT_UNPROTECTED_RIGHT_TURN); } } // namespace traffic_light } // namespace scenario } // namespace planning } // namespace apollo
0
apollo_public_repos/apollo/modules/planning/scenarios/traffic_light
apollo_public_repos/apollo/modules/planning/scenarios/traffic_light/unprotected_right_turn/stage_stop_test.cc
/****************************************************************************** * Copyright 2019 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. *****************************************************************************/ #include "modules/planning/scenarios/traffic_light/unprotected_right_turn/stage_stop.h" #include "cyber/common/file.h" #include "cyber/common/log.h" #include "gtest/gtest.h" #include "modules/planning/common/planning_gflags.h" namespace apollo { namespace planning { namespace scenario { namespace traffic_light { class TrafficLightUnprotectedRightTurnStageStopTest : public ::testing::Test { public: virtual void SetUp() { config_.set_stage_type( StageType::TRAFFIC_LIGHT_UNPROTECTED_RIGHT_TURN_CREEP); injector_ = std::make_shared<DependencyInjector>(); } protected: ScenarioConfig::StageConfig config_; std::shared_ptr<DependencyInjector> injector_; }; TEST_F(TrafficLightUnprotectedRightTurnStageStopTest, Init) { TrafficLightUnprotectedRightTurnStageStop traffic_light_unprotected_right_turn_stage_stop(config_, injector_); EXPECT_EQ(traffic_light_unprotected_right_turn_stage_stop.Name(), StageType_Name( StageType::TRAFFIC_LIGHT_UNPROTECTED_RIGHT_TURN_CREEP)); } } // namespace traffic_light } // namespace scenario } // namespace planning } // namespace apollo
0
apollo_public_repos/apollo/modules/planning/scenarios/traffic_light
apollo_public_repos/apollo/modules/planning/scenarios/traffic_light/unprotected_right_turn/stage_intersection_cruise.h
/****************************************************************************** * Copyright 2018 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 **/ #pragma once #include <memory> #include "modules/planning/scenarios/common/stage_intersection_cruise_impl.h" #include "modules/planning/scenarios/stage.h" #include "modules/planning/scenarios/traffic_light/unprotected_right_turn/traffic_light_unprotected_right_turn_scenario.h" namespace apollo { namespace planning { namespace scenario { namespace traffic_light { struct TrafficLightUnprotectedRightTurnContext; class TrafficLightUnprotectedRightTurnStageIntersectionCruise : public Stage { public: TrafficLightUnprotectedRightTurnStageIntersectionCruise( const ScenarioConfig::StageConfig& config, const std::shared_ptr<DependencyInjector>& injector) : Stage(config, injector) {} private: Stage::StageStatus Process(const common::TrajectoryPoint& planning_init_point, Frame* frame) override; TrafficLightUnprotectedRightTurnContext* GetContext() { return GetContextAs<TrafficLightUnprotectedRightTurnContext>(); } Stage::StageStatus FinishStage(); private: ScenarioTrafficLightUnprotectedRightTurnConfig scenario_config_; StageIntersectionCruiseImpl stage_impl_; }; } // namespace traffic_light } // namespace scenario } // namespace planning } // namespace apollo
0
apollo_public_repos/apollo/modules/planning/scenarios/traffic_light
apollo_public_repos/apollo/modules/planning/scenarios/traffic_light/unprotected_right_turn/BUILD
load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test") load("//tools:cpplint.bzl", "cpplint") load("//third_party/gpus:common.bzl", "if_cuda", "if_rocm") package(default_visibility = ["//visibility:public"]) cc_library( name = "traffic_light_unprotected_right_turn_scenario", srcs = [ "stage_creep.cc", "stage_intersection_cruise.cc", "stage_stop.cc", "traffic_light_unprotected_right_turn_scenario.cc", ], hdrs = [ "stage_creep.h", "stage_intersection_cruise.h", "stage_stop.h", "traffic_light_unprotected_right_turn_scenario.h", ], copts = ["-DMODULE_NAME=\\\"planning\\\""], deps = [ "//cyber", "//modules/common/util", "//modules/common/util:util_tool", "//modules/common_msgs/planning_msgs:planning_cc_proto", "//modules/planning/scenarios:scenario", "//modules/planning/scenarios/common:stage_intersection_cruise_impl", "//modules/planning/scenarios/util:scenario_util_lib", "//modules/planning/tasks/deciders/creep_decider", "@com_github_gflags_gflags//:gflags", "@eigen", ] + if_cuda([ "@local_config_cuda//cuda:cudart", ]) + if_rocm([ "@local_config_rocm//rocm:hip", ]), ) cc_test( name = "traffic_light_right_turn_unprotected_scenario_test", size = "small", srcs = ["traffic_light_unprotected_right_turn_scenario_test.cc"], data = ["//modules/planning:planning_conf"], linkopts = ["-lgomp"], deps = [ ":traffic_light_unprotected_right_turn_scenario", "@com_google_googletest//:gtest_main", ] + if_cuda([ "@local_config_cuda//cuda:cudart", ]) + if_rocm([ "@local_config_rocm//rocm:hip", ]), linkstatic = True, ) cc_test( name = "stage_creep_test", size = "small", srcs = ["stage_creep_test.cc"], data = [ "//modules/planning:planning_conf", ], linkopts = ["-lgomp"], deps = [ ":traffic_light_unprotected_right_turn_scenario", "@com_google_googletest//:gtest_main", ] + if_cuda([ "@local_config_cuda//cuda:cudart", ]) + if_rocm([ "@local_config_rocm//rocm:hip", ]), linkstatic = True, ) cc_test( name = "stage_stop_test", size = "small", srcs = ["stage_stop_test.cc"], data = [ "//modules/planning:planning_conf", ], linkopts = ["-lgomp"], deps = [ ":traffic_light_unprotected_right_turn_scenario", "@com_google_googletest//:gtest_main", ], linkstatic = True, ) cpplint()
0
apollo_public_repos/apollo/modules/planning/scenarios/traffic_light
apollo_public_repos/apollo/modules/planning/scenarios/traffic_light/unprotected_right_turn/traffic_light_unprotected_right_turn_scenario.h
/****************************************************************************** * Copyright 2018 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 **/ #pragma once #include <memory> #include <string> #include <vector> #include "modules/common/util/factory.h" #include "modules/map/hdmap/hdmap.h" #include "modules/common_msgs/planning_msgs/planning.pb.h" #include "modules/planning/scenarios/scenario.h" namespace apollo { namespace planning { namespace scenario { namespace traffic_light { // stage context struct TrafficLightUnprotectedRightTurnContext { ScenarioTrafficLightUnprotectedRightTurnConfig scenario_config; std::vector<std::string> current_traffic_light_overlap_ids; double stop_start_time = 0.0; double creep_start_time = 0.0; }; class TrafficLightUnprotectedRightTurnScenario : public Scenario { public: TrafficLightUnprotectedRightTurnScenario( const ScenarioConfig& config, const ScenarioContext* context, const std::shared_ptr<DependencyInjector>& injector) : Scenario(config, context, injector) {} void Init() override; std::unique_ptr<Stage> CreateStage( const ScenarioConfig::StageConfig& stage_config, const std::shared_ptr<DependencyInjector>& injector); TrafficLightUnprotectedRightTurnContext* GetContext() { return &context_; } private: static void RegisterStages(); bool GetScenarioConfig(); private: static apollo::common::util::Factory< StageType, Stage, Stage* (*)(const ScenarioConfig::StageConfig& stage_config, const std::shared_ptr<DependencyInjector>& injector)> s_stage_factory_; bool init_ = false; TrafficLightUnprotectedRightTurnContext context_; }; } // namespace traffic_light } // namespace scenario } // namespace planning } // namespace apollo
0
apollo_public_repos/apollo/modules/planning/scenarios/traffic_light
apollo_public_repos/apollo/modules/planning/scenarios/traffic_light/protected/traffic_light_protected_scenario_test.cc
/****************************************************************************** * Copyright 2018 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 **/ #include "modules/planning/scenarios/traffic_light/protected/traffic_light_protected_scenario.h" #include "cyber/common/file.h" #include "cyber/common/log.h" #include "gtest/gtest.h" #include "modules/planning/common/planning_gflags.h" namespace apollo { namespace planning { namespace scenario { namespace traffic_light { class TrafficLightProtectedScenarioTest : public ::testing::Test { public: virtual void SetUp() {} protected: std::unique_ptr<TrafficLightProtectedScenario> scenario_; }; TEST_F(TrafficLightProtectedScenarioTest, Init) { FLAGS_scenario_traffic_light_protected_config_file = "/apollo/modules/planning/conf/" "scenario/traffic_light_protected_config.pb.txt"; ScenarioConfig config; EXPECT_TRUE(apollo::cyber::common::GetProtoFromFile( FLAGS_scenario_traffic_light_protected_config_file, &config)); ScenarioContext context; auto injector = std::make_shared<DependencyInjector>(); scenario_.reset( new TrafficLightProtectedScenario(config, &context, injector)); EXPECT_EQ(scenario_->scenario_type(), ScenarioType::TRAFFIC_LIGHT_PROTECTED); } } // namespace traffic_light } // namespace scenario } // namespace planning } // namespace apollo
0
apollo_public_repos/apollo/modules/planning/scenarios/traffic_light
apollo_public_repos/apollo/modules/planning/scenarios/traffic_light/protected/stage_approach.h
/****************************************************************************** * Copyright 2018 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 **/ #pragma once #include <memory> #include "modules/planning/scenarios/stage.h" #include "modules/planning/scenarios/traffic_light/protected/traffic_light_protected_scenario.h" namespace apollo { namespace planning { namespace scenario { namespace traffic_light { struct TrafficLightProtectedContext; class TrafficLightProtectedStageApproach : public Stage { public: TrafficLightProtectedStageApproach( const ScenarioConfig::StageConfig& config, const std::shared_ptr<DependencyInjector>& injector) : Stage(config, injector) {} private: Stage::StageStatus Process(const common::TrajectoryPoint& planning_init_point, Frame* frame) override; TrafficLightProtectedContext* GetContext() { return GetContextAs<TrafficLightProtectedContext>(); } private: Stage::StageStatus FinishStage(); private: ScenarioTrafficLightProtectedConfig scenario_config_; }; } // namespace traffic_light } // namespace scenario } // namespace planning } // namespace apollo
0
apollo_public_repos/apollo/modules/planning/scenarios/traffic_light
apollo_public_repos/apollo/modules/planning/scenarios/traffic_light/protected/traffic_light_protected_scenario.cc
/****************************************************************************** * Copyright 2018 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 **/ #include "modules/planning/scenarios/traffic_light/protected/traffic_light_protected_scenario.h" #include "cyber/common/log.h" #include "modules/planning/common/frame.h" #include "modules/planning/common/planning_context.h" #include "modules/planning/proto/planning_config.pb.h" #include "modules/planning/scenarios/traffic_light/protected/stage_approach.h" #include "modules/planning/scenarios/traffic_light/protected/stage_intersection_cruise.h" namespace apollo { namespace planning { namespace scenario { namespace traffic_light { using apollo::hdmap::HDMapUtil; void TrafficLightProtectedScenario::Init() { if (init_) { return; } Scenario::Init(); if (!GetScenarioConfig()) { AERROR << "fail to get scenario specific config"; return; } const auto& traffic_light_status = injector_->planning_context()->planning_status().traffic_light(); if (traffic_light_status.current_traffic_light_overlap_id().empty()) { AERROR << "Could not find traffic-light(s)"; return; } context_.current_traffic_light_overlap_ids.clear(); for (int i = 0; i < traffic_light_status.current_traffic_light_overlap_id_size(); i++) { const std::string traffic_light_overlap_id = traffic_light_status.current_traffic_light_overlap_id(i); hdmap::SignalInfoConstPtr traffic_light = HDMapUtil::BaseMap().GetSignalById( hdmap::MakeMapId(traffic_light_overlap_id)); if (!traffic_light) { AERROR << "Could not find traffic light: " << traffic_light_overlap_id; } context_.current_traffic_light_overlap_ids.push_back( traffic_light_overlap_id); } init_ = true; } apollo::common::util::Factory< StageType, Stage, Stage* (*)(const ScenarioConfig::StageConfig& stage_config, const std::shared_ptr<DependencyInjector>& injector)> TrafficLightProtectedScenario::s_stage_factory_; void TrafficLightProtectedScenario::RegisterStages() { if (!s_stage_factory_.Empty()) { s_stage_factory_.Clear(); } s_stage_factory_.Register( StageType::TRAFFIC_LIGHT_PROTECTED_APPROACH, [](const ScenarioConfig::StageConfig& config, const std::shared_ptr<DependencyInjector>& injector) -> Stage* { return new TrafficLightProtectedStageApproach(config, injector); }); s_stage_factory_.Register( StageType::TRAFFIC_LIGHT_PROTECTED_INTERSECTION_CRUISE, [](const ScenarioConfig::StageConfig& config, const std::shared_ptr<DependencyInjector>& injector) -> Stage* { return new TrafficLightProtectedStageIntersectionCruise(config, injector); }); } std::unique_ptr<Stage> TrafficLightProtectedScenario::CreateStage( const ScenarioConfig::StageConfig& stage_config, const std::shared_ptr<DependencyInjector>& injector) { if (s_stage_factory_.Empty()) { RegisterStages(); } auto ptr = s_stage_factory_.CreateObjectOrNull(stage_config.stage_type(), stage_config, injector); if (ptr) { ptr->SetContext(&context_); } return ptr; } /* * read scenario specific configs and set in context_ for stages to read */ bool TrafficLightProtectedScenario::GetScenarioConfig() { if (!config_.has_traffic_light_protected_config()) { AERROR << "miss scenario specific config"; return false; } context_.scenario_config.CopyFrom(config_.traffic_light_protected_config()); return true; } } // namespace traffic_light } // namespace scenario } // namespace planning } // namespace apollo
0
apollo_public_repos/apollo/modules/planning/scenarios/traffic_light
apollo_public_repos/apollo/modules/planning/scenarios/traffic_light/protected/stage_approach_test.cc
/****************************************************************************** * Copyright 2019 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. *****************************************************************************/ #include "modules/planning/scenarios/traffic_light/protected/stage_approach.h" #include "cyber/common/file.h" #include "cyber/common/log.h" #include "gtest/gtest.h" #include "modules/planning/common/planning_gflags.h" namespace apollo { namespace planning { namespace scenario { namespace traffic_light { class TrafficLightProtectedStageApproachTest : public ::testing::Test { public: virtual void SetUp() { config_.set_stage_type(StageType::TRAFFIC_LIGHT_PROTECTED_APPROACH); injector_ = std::make_shared<DependencyInjector>(); } protected: ScenarioConfig::StageConfig config_; std::shared_ptr<DependencyInjector> injector_; }; TEST_F(TrafficLightProtectedStageApproachTest, Init) { TrafficLightProtectedStageApproach traffic_light_protected_stage_approach( config_, injector_); EXPECT_EQ(traffic_light_protected_stage_approach.Name(), StageType_Name( StageType::TRAFFIC_LIGHT_PROTECTED_APPROACH)); } } // namespace traffic_light } // namespace scenario } // namespace planning } // namespace apollo
0
apollo_public_repos/apollo/modules/planning/scenarios/traffic_light
apollo_public_repos/apollo/modules/planning/scenarios/traffic_light/protected/stage_approach.cc
/****************************************************************************** * Copyright 2018 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 **/ #include "modules/planning/scenarios/traffic_light/protected/stage_approach.h" #include "cyber/common/log.h" #include "modules/map/pnc_map/path.h" #include "modules/planning/common/frame.h" #include "modules/planning/common/planning_context.h" #include "modules/planning/common/util/util.h" #include "modules/planning/scenarios/util/util.h" namespace apollo { namespace planning { namespace scenario { namespace traffic_light { using apollo::common::TrajectoryPoint; using apollo::hdmap::PathOverlap; using apollo::perception::TrafficLight; Stage::StageStatus TrafficLightProtectedStageApproach::Process( const TrajectoryPoint& planning_init_point, Frame* frame) { ADEBUG << "stage: Approach"; CHECK_NOTNULL(frame); scenario_config_.CopyFrom(GetContext()->scenario_config); bool plan_ok = ExecuteTaskOnReferenceLine(planning_init_point, frame); if (!plan_ok) { AERROR << "TrafficLightProtectedStageApproach planning error"; } if (GetContext()->current_traffic_light_overlap_ids.empty()) { return FinishScenario(); } const auto& reference_line_info = frame->reference_line_info().front(); bool traffic_light_all_done = true; for (const auto& traffic_light_overlap_id : GetContext()->current_traffic_light_overlap_ids) { // get overlap along reference line PathOverlap* current_traffic_light_overlap = scenario::util::GetOverlapOnReferenceLine(reference_line_info, traffic_light_overlap_id, ReferenceLineInfo::SIGNAL); if (!current_traffic_light_overlap) { continue; } // set right_of_way_status reference_line_info.SetJunctionRightOfWay( current_traffic_light_overlap->start_s, false); const double adc_front_edge_s = reference_line_info.AdcSlBoundary().end_s(); const double distance_adc_to_stop_line = current_traffic_light_overlap->start_s - adc_front_edge_s; auto signal_color = frame->GetSignal(traffic_light_overlap_id).color(); ADEBUG << "traffic_light_overlap_id[" << traffic_light_overlap_id << "] start_s[" << current_traffic_light_overlap->start_s << "] distance_adc_to_stop_line[" << distance_adc_to_stop_line << "] color[" << signal_color << "]"; // check distance to stop line if (distance_adc_to_stop_line > scenario_config_.max_valid_stop_distance()) { traffic_light_all_done = false; break; } // check on traffic light color if (signal_color != TrafficLight::GREEN) { traffic_light_all_done = false; break; } } if (traffic_light_all_done) { return FinishStage(); } return Stage::RUNNING; } Stage::StageStatus TrafficLightProtectedStageApproach::FinishStage() { auto* traffic_light = injector_->planning_context() ->mutable_planning_status() ->mutable_traffic_light(); traffic_light->clear_done_traffic_light_overlap_id(); for (const auto& traffic_light_overlap_id : GetContext()->current_traffic_light_overlap_ids) { traffic_light->add_done_traffic_light_overlap_id(traffic_light_overlap_id); } next_stage_ = StageType::TRAFFIC_LIGHT_PROTECTED_INTERSECTION_CRUISE; return Stage::FINISHED; } } // namespace traffic_light } // namespace scenario } // namespace planning } // namespace apollo
0
apollo_public_repos/apollo/modules/planning/scenarios/traffic_light
apollo_public_repos/apollo/modules/planning/scenarios/traffic_light/protected/stage_intersection_cruise.cc
/****************************************************************************** * Copyright 2018 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 **/ #include "modules/planning/scenarios/traffic_light/protected/stage_intersection_cruise.h" #include "cyber/common/log.h" namespace apollo { namespace planning { namespace scenario { namespace traffic_light { Stage::StageStatus TrafficLightProtectedStageIntersectionCruise::Process( const common::TrajectoryPoint& planning_init_point, Frame* frame) { ADEBUG << "stage: IntersectionCruise"; CHECK_NOTNULL(frame); bool plan_ok = ExecuteTaskOnReferenceLine(planning_init_point, frame); if (!plan_ok) { AERROR << "TrafficLightProtectedStageIntersectionCruise plan error"; } bool stage_done = stage_impl_.CheckDone(*frame, ScenarioType::TRAFFIC_LIGHT_PROTECTED, config_, injector_->planning_context(), true); if (stage_done) { return FinishStage(); } return Stage::RUNNING; } Stage::StageStatus TrafficLightProtectedStageIntersectionCruise::FinishStage() { return FinishScenario(); } } // namespace traffic_light } // namespace scenario } // namespace planning } // namespace apollo
0
apollo_public_repos/apollo/modules/planning/scenarios/traffic_light
apollo_public_repos/apollo/modules/planning/scenarios/traffic_light/protected/traffic_light_protected_scenario.h
/****************************************************************************** * Copyright 2018 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 **/ #pragma once #include <memory> #include <string> #include <vector> #include "modules/common/util/factory.h" #include "modules/common_msgs/planning_msgs/planning.pb.h" #include "modules/planning/scenarios/scenario.h" namespace apollo { namespace planning { namespace scenario { namespace traffic_light { // stage context struct TrafficLightProtectedContext { ScenarioTrafficLightProtectedConfig scenario_config; std::vector<std::string> current_traffic_light_overlap_ids; }; class TrafficLightProtectedScenario : public Scenario { public: TrafficLightProtectedScenario( const ScenarioConfig& config, const ScenarioContext* context, const std::shared_ptr<DependencyInjector>& injector) : Scenario(config, context, injector) {} void Init() override; std::unique_ptr<Stage> CreateStage( const ScenarioConfig::StageConfig& stage_config, const std::shared_ptr<DependencyInjector>& injector); TrafficLightProtectedContext* GetContext() { return &context_; } private: static void RegisterStages(); bool GetScenarioConfig(); private: static apollo::common::util::Factory< StageType, Stage, Stage* (*)(const ScenarioConfig::StageConfig& stage_config, const std::shared_ptr<DependencyInjector>& injector)> s_stage_factory_; bool init_ = false; TrafficLightProtectedContext context_; }; } // namespace traffic_light } // namespace scenario } // namespace planning } // namespace apollo
0
apollo_public_repos/apollo/modules/planning/scenarios/traffic_light
apollo_public_repos/apollo/modules/planning/scenarios/traffic_light/protected/stage_intersection_cruise.h
/****************************************************************************** * Copyright 2018 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 **/ #pragma once #include <memory> #include "modules/planning/scenarios/common/stage_intersection_cruise_impl.h" #include "modules/planning/scenarios/stage.h" #include "modules/planning/scenarios/traffic_light/protected/traffic_light_protected_scenario.h" namespace apollo { namespace planning { namespace scenario { namespace traffic_light { struct TrafficLightProtectedContext; class TrafficLightProtectedStageIntersectionCruise : public Stage { public: TrafficLightProtectedStageIntersectionCruise( const ScenarioConfig::StageConfig& config, const std::shared_ptr<DependencyInjector>& injector) : Stage(config, injector) {} private: Stage::StageStatus Process(const common::TrajectoryPoint& planning_init_point, Frame* frame) override; TrafficLightProtectedContext* GetContext() { return GetContextAs<TrafficLightProtectedContext>(); } Stage::StageStatus FinishStage(); private: ScenarioTrafficLightProtectedConfig scenario_config_; StageIntersectionCruiseImpl stage_impl_; }; } // namespace traffic_light } // namespace scenario } // namespace planning } // namespace apollo
0
apollo_public_repos/apollo/modules/planning/scenarios/traffic_light
apollo_public_repos/apollo/modules/planning/scenarios/traffic_light/protected/BUILD
load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test") load("//third_party/gpus:common.bzl", "if_cuda", "if_rocm") load("//tools:cpplint.bzl", "cpplint") package(default_visibility = ["//visibility:public"]) cc_library( name = "traffic_light_protected_scenario", srcs = [ "stage_approach.cc", "stage_intersection_cruise.cc", "traffic_light_protected_scenario.cc", ], hdrs = [ "stage_approach.h", "stage_intersection_cruise.h", "traffic_light_protected_scenario.h", ], copts = ["-DMODULE_NAME=\\\"planning\\\""], deps = [ "//cyber", "//modules/common/util", "//modules/common/util:util_tool", "//modules/common_msgs/planning_msgs:planning_cc_proto", "//modules/planning/scenarios:scenario", "//modules/planning/scenarios/common:stage_intersection_cruise_impl", "//modules/planning/scenarios/util:scenario_util_lib", "@com_github_gflags_gflags//:gflags", "@eigen", ] + if_cuda([ "@local_config_cuda//cuda:cudart", ]) + if_rocm([ "@local_config_rocm//rocm:hip", ]), ) cc_test( name = "traffic_light_protected_scenario_test", size = "small", srcs = ["traffic_light_protected_scenario_test.cc"], data = ["//modules/planning:planning_conf"], linkopts = ["-lgomp"], deps = [ ":traffic_light_protected_scenario", "@com_google_googletest//:gtest_main", ], linkstatic = True, ) cc_test( name = "stage_approach_test", size = "small", srcs = ["stage_approach_test.cc"], data = [ "//modules/planning:planning_conf", ], linkopts = ["-lgomp"], deps = [ ":traffic_light_protected_scenario", "@com_google_googletest//:gtest_main", ], linkstatic = True, ) cpplint()
0
apollo_public_repos/apollo/modules/planning/scenarios
apollo_public_repos/apollo/modules/planning/scenarios/park_and_go/stage_check.h
/****************************************************************************** * Copyright 2019 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. *****************************************************************************/ #pragma once #include <memory> #include "cyber/common/log.h" #include "modules/common_msgs/config_msgs/vehicle_config.pb.h" #include "modules/common/configs/vehicle_config_helper.h" #include "modules/common/math/vec2d.h" #include "modules/common/vehicle_state/proto/vehicle_state.pb.h" #include "modules/common/vehicle_state/vehicle_state_provider.h" #include "modules/planning/common/frame.h" #include "modules/planning/common/planning_context.h" #include "modules/planning/common/util/common.h" #include "modules/planning/proto/planning_config.pb.h" #include "modules/planning/scenarios/park_and_go/park_and_go_scenario.h" #include "modules/planning/scenarios/stage.h" #include "modules/planning/scenarios/util/util.h" namespace apollo { namespace planning { namespace scenario { namespace park_and_go { struct ParkAndGoContext; class ParkAndGoStageCheck : public Stage { public: ParkAndGoStageCheck(const ScenarioConfig::StageConfig& config, const std::shared_ptr<DependencyInjector>& injector) : Stage(config, injector) {} Stage::StageStatus Process(const common::TrajectoryPoint& planning_init_point, Frame* frame) override; ParkAndGoContext* GetContext() { return Stage::GetContextAs<ParkAndGoContext>(); } Stage::StageStatus FinishStage(const bool success); private: bool CheckObstacle(const ReferenceLineInfo& reference_line_info); void ADCInitStatus(); private: ScenarioParkAndGoConfig scenario_config_; }; } // namespace park_and_go } // namespace scenario } // namespace planning } // namespace apollo
0
apollo_public_repos/apollo/modules/planning/scenarios
apollo_public_repos/apollo/modules/planning/scenarios/park_and_go/park_and_go_scenario_test.cc
/****************************************************************************** * Copyright 2019 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 **/ #include "modules/planning/scenarios/park_and_go/park_and_go_scenario.h" #include "cyber/common/file.h" #include "cyber/common/log.h" #include "gtest/gtest.h" #include "modules/planning/common/planning_gflags.h" namespace apollo { namespace planning { namespace scenario { namespace park_and_go { class ParkAndGoTest : public ::testing::Test { public: virtual void SetUp() {} protected: std::unique_ptr<ParkAndGoScenario> scenario_; }; TEST_F(ParkAndGoTest, VerifyConf) { ScenarioConfig config; EXPECT_TRUE(apollo::cyber::common::GetProtoFromFile( FLAGS_scenario_park_and_go_config_file, &config)); } } // namespace park_and_go } // namespace scenario } // namespace planning } // namespace apollo
0
apollo_public_repos/apollo/modules/planning/scenarios
apollo_public_repos/apollo/modules/planning/scenarios/park_and_go/stage_pre_cruise.cc
/****************************************************************************** * Copyright 2019 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. *****************************************************************************/ #include "modules/planning/scenarios/park_and_go/stage_pre_cruise.h" #include "cyber/common/log.h" #include "modules/common/vehicle_state/vehicle_state_provider.h" #include "modules/planning/common/frame.h" #include "modules/planning/common/planning_context.h" #include "modules/planning/common/util/common.h" #include "modules/planning/scenarios/util/util.h" #include "modules/planning/tasks/deciders/path_bounds_decider/path_bounds_decider.h" namespace apollo { namespace planning { namespace scenario { namespace park_and_go { using apollo::common::TrajectoryPoint; Stage::StageStatus ParkAndGoStagePreCruise::Process( const TrajectoryPoint& planning_init_point, Frame* frame) { ADEBUG << "stage: Pre Cruise"; CHECK_NOTNULL(frame); scenario_config_.CopyFrom(GetContext()->scenario_config); frame->mutable_open_space_info()->set_is_on_open_space_trajectory(true); bool plan_ok = ExecuteTaskOnOpenSpace(frame); if (!plan_ok) { AERROR << "ParkAndGoStagePreCruise planning error"; return StageStatus::ERROR; } // const bool ready_to_cruise = // scenario::util::CheckADCReadyToCruise(frame, scenario_config_); auto vehicle_status = injector_->vehicle_state(); ADEBUG << vehicle_status->steering_percentage(); if ((std::fabs(vehicle_status->steering_percentage()) < scenario_config_.max_steering_percentage_when_cruise()) && scenario::util::CheckADCReadyToCruise(injector_->vehicle_state(), frame, scenario_config_)) { return FinishStage(); } return StageStatus::RUNNING; } Stage::StageStatus ParkAndGoStagePreCruise::FinishStage() { next_stage_ = StageType::PARK_AND_GO_CRUISE; return Stage::FINISHED; } } // namespace park_and_go } // namespace scenario } // namespace planning } // namespace apollo
0
apollo_public_repos/apollo/modules/planning/scenarios
apollo_public_repos/apollo/modules/planning/scenarios/park_and_go/stage_pre_cruise.h
/****************************************************************************** * Copyright 2019 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. *****************************************************************************/ #pragma once #include <memory> #include "modules/planning/proto/planning_config.pb.h" #include "modules/planning/scenarios/park_and_go/park_and_go_scenario.h" #include "modules/planning/scenarios/stage.h" namespace apollo { namespace planning { namespace scenario { namespace park_and_go { struct ParkAndGoContext; class ParkAndGoStagePreCruise : public Stage { public: ParkAndGoStagePreCruise(const ScenarioConfig::StageConfig& config, const std::shared_ptr<DependencyInjector>& injector) : Stage(config, injector) {} Stage::StageStatus Process(const common::TrajectoryPoint& planning_init_point, Frame* frame) override; ParkAndGoContext* GetContext() { return Stage::GetContextAs<ParkAndGoContext>(); } Stage::StageStatus FinishStage(); private: ScenarioParkAndGoConfig scenario_config_; }; } // namespace park_and_go } // namespace scenario } // namespace planning } // namespace apollo
0
apollo_public_repos/apollo/modules/planning/scenarios
apollo_public_repos/apollo/modules/planning/scenarios/park_and_go/stage_adjust.h
/****************************************************************************** * Copyright 2019 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. *****************************************************************************/ #pragma once #include <memory> #include "modules/planning/proto/planning_config.pb.h" #include "modules/planning/scenarios/park_and_go/park_and_go_scenario.h" #include "modules/planning/scenarios/stage.h" namespace apollo { namespace planning { namespace scenario { namespace park_and_go { struct ParkAndGoContext; class ParkAndGoStageAdjust : public Stage { public: ParkAndGoStageAdjust(const ScenarioConfig::StageConfig& config, const std::shared_ptr<DependencyInjector>& injector) : Stage(config, injector) {} Stage::StageStatus Process(const common::TrajectoryPoint& planning_init_point, Frame* frame) override; ParkAndGoContext* GetContext() { return Stage::GetContextAs<ParkAndGoContext>(); } Stage::StageStatus FinishStage(); private: void ResetInitPostion(); ScenarioParkAndGoConfig scenario_config_; }; } // namespace park_and_go } // namespace scenario } // namespace planning } // namespace apollo
0
apollo_public_repos/apollo/modules/planning/scenarios
apollo_public_repos/apollo/modules/planning/scenarios/park_and_go/stage_adjust.cc
/****************************************************************************** * Copyright 2019 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. *****************************************************************************/ #include "modules/planning/scenarios/park_and_go/stage_adjust.h" #include "cyber/common/log.h" #include "modules/common/vehicle_state/vehicle_state_provider.h" #include "modules/planning/common/frame.h" #include "modules/planning/common/planning_context.h" #include "modules/planning/common/util/common.h" #include "modules/planning/scenarios/util/util.h" #include "modules/planning/tasks/deciders/path_bounds_decider/path_bounds_decider.h" namespace apollo { namespace planning { namespace scenario { namespace park_and_go { using apollo::common::TrajectoryPoint; Stage::StageStatus ParkAndGoStageAdjust::Process( const TrajectoryPoint& planning_init_point, Frame* frame) { ADEBUG << "stage: Adjust"; CHECK_NOTNULL(frame); scenario_config_.CopyFrom(GetContext()->scenario_config); frame->mutable_open_space_info()->set_is_on_open_space_trajectory(true); bool plan_ok = ExecuteTaskOnOpenSpace(frame); if (!plan_ok) { AERROR << "ParkAndGoStageAdjust planning error"; return StageStatus::ERROR; } const bool is_ready_to_cruise = scenario::util::CheckADCReadyToCruise( injector_->vehicle_state(), frame, scenario_config_); bool is_end_of_trajectory = false; const auto& history_frame = injector_->frame_history()->Latest(); if (history_frame) { const auto& trajectory_points = history_frame->current_frame_planned_trajectory().trajectory_point(); if (!trajectory_points.empty()) { is_end_of_trajectory = (trajectory_points.rbegin()->relative_time() < 0.0); } } if (!is_ready_to_cruise && !is_end_of_trajectory) { return StageStatus::RUNNING; } return FinishStage(); } Stage::StageStatus ParkAndGoStageAdjust::FinishStage() { const auto vehicle_status = injector_->vehicle_state(); ADEBUG << vehicle_status->steering_percentage(); if (std::fabs(vehicle_status->steering_percentage()) < scenario_config_.max_steering_percentage_when_cruise()) { next_stage_ = StageType::PARK_AND_GO_CRUISE; } else { ResetInitPostion(); next_stage_ = StageType::PARK_AND_GO_PRE_CRUISE; } return Stage::FINISHED; } void ParkAndGoStageAdjust::ResetInitPostion() { auto* park_and_go_status = injector_->planning_context() ->mutable_planning_status() ->mutable_park_and_go(); park_and_go_status->mutable_adc_init_position()->set_x( injector_->vehicle_state()->x()); park_and_go_status->mutable_adc_init_position()->set_y( injector_->vehicle_state()->y()); park_and_go_status->mutable_adc_init_position()->set_z(0.0); park_and_go_status->set_adc_init_heading( injector_->vehicle_state()->heading()); } } // namespace park_and_go } // namespace scenario } // namespace planning } // namespace apollo
0
apollo_public_repos/apollo/modules/planning/scenarios
apollo_public_repos/apollo/modules/planning/scenarios/park_and_go/stage_check_test.cc
/****************************************************************************** * Copyright 2019 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 **/ #include "modules/planning/scenarios/park_and_go/stage_check.h" #include "gtest/gtest.h" #include "modules/planning/proto/planning_config.pb.h" namespace apollo { namespace planning { namespace scenario { namespace park_and_go { class ParkAndGoStageCheckTest : public ::testing::Test { public: virtual void SetUp() { config_.set_stage_type(StageType::PARK_AND_GO_CHECK); injector_ = std::make_shared<DependencyInjector>(); } protected: ScenarioConfig::StageConfig config_; std::shared_ptr<DependencyInjector> injector_; }; TEST_F(ParkAndGoStageCheckTest, Init) { ParkAndGoStageCheck park_and_go_stage_check(config_, injector_); EXPECT_EQ(park_and_go_stage_check.Name(), StageType_Name(StageType::PARK_AND_GO_CHECK)); } } // namespace park_and_go } // namespace scenario } // namespace planning } // namespace apollo
0
apollo_public_repos/apollo/modules/planning/scenarios
apollo_public_repos/apollo/modules/planning/scenarios/park_and_go/stage_cruise.cc
/****************************************************************************** * Copyright 2019 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. *****************************************************************************/ #include "modules/planning/scenarios/park_and_go/stage_cruise.h" #include "cyber/common/log.h" #include "modules/common/vehicle_state/vehicle_state_provider.h" #include "modules/planning/common/frame.h" #include "modules/planning/common/planning_context.h" #include "modules/planning/common/util/common.h" #include "modules/planning/scenarios/util/util.h" #include "modules/planning/tasks/deciders/path_bounds_decider/path_bounds_decider.h" namespace apollo { namespace planning { namespace scenario { namespace park_and_go { using apollo::common::TrajectoryPoint; Stage::StageStatus ParkAndGoStageCruise::Process( const TrajectoryPoint& planning_init_point, Frame* frame) { ADEBUG << "stage: Cruise"; CHECK_NOTNULL(frame); scenario_config_.CopyFrom(GetContext()->scenario_config); bool plan_ok = ExecuteTaskOnReferenceLine(planning_init_point, frame); if (!plan_ok) { AERROR << "ParkAndGoStageCruise planning error"; } const ReferenceLineInfo& reference_line_info = frame->reference_line_info().front(); // check ADC status: // 1. At routing beginning: stage finished ParkAndGoStatus status = CheckADCParkAndGoCruiseCompleted(reference_line_info); if (status == CRUISE_COMPLETE) { return FinishStage(); } return Stage::RUNNING; } Stage::StageStatus ParkAndGoStageCruise::FinishStage() { return FinishScenario(); } ParkAndGoStageCruise::ParkAndGoStatus ParkAndGoStageCruise::CheckADCParkAndGoCruiseCompleted( const ReferenceLineInfo& reference_line_info) { const auto& reference_line = reference_line_info.reference_line(); // check l delta const common::math::Vec2d adc_position = {injector_->vehicle_state()->x(), injector_->vehicle_state()->y()}; common::SLPoint adc_position_sl; reference_line.XYToSL(adc_position, &adc_position_sl); const double kLBuffer = 0.5; if (std::fabs(adc_position_sl.l()) < kLBuffer) { ADEBUG << "cruise completed"; return CRUISE_COMPLETE; } /* loose heading check, so that ADC can enter LANE_FOLLOW scenario sooner * which is more sophisticated // heading delta const double adc_heading = common::VehicleStateProvider::Instance()->heading(); const auto reference_point = reference_line.GetReferencePoint(adc_position_sl.s()); const auto path_point = reference_point.ToPathPoint(adc_position_sl.s()); ADEBUG << "adc_position_sl.l():[" << adc_position_sl.l() << "]"; ADEBUG << "adc_heading - path_point.theta():[" << adc_heading << "]" << "[" << path_point.theta() << "]"; const double kHeadingBuffer = 0.1; if (std::fabs(adc_heading - path_point.theta()) < kHeadingBuffer) { ADEBUG << "cruise completed"; return CRUISE_COMPLETE; } */ return CRUISING; } } // namespace park_and_go } // namespace scenario } // namespace planning } // namespace apollo
0
apollo_public_repos/apollo/modules/planning/scenarios
apollo_public_repos/apollo/modules/planning/scenarios/park_and_go/stage_cruise.h
/****************************************************************************** * Copyright 2019 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. *****************************************************************************/ #pragma once #include <memory> #include "modules/planning/proto/planning_config.pb.h" #include "modules/planning/scenarios/park_and_go/park_and_go_scenario.h" #include "modules/planning/scenarios/stage.h" namespace apollo { namespace planning { namespace scenario { namespace park_and_go { struct ParkAndGoContext; class ParkAndGoStageCruise : public Stage { public: enum ParkAndGoStatus { CRUISING = 1, CRUISE_COMPLETE = 2, ADJUST = 3, ADJUST_COMPLETE = 4, FAIL = 5, }; ParkAndGoStageCruise(const ScenarioConfig::StageConfig& config, const std::shared_ptr<DependencyInjector>& injector) : Stage(config, injector) {} Stage::StageStatus Process(const common::TrajectoryPoint& planning_init_point, Frame* frame) override; ParkAndGoContext* GetContext() { return Stage::GetContextAs<ParkAndGoContext>(); } Stage::StageStatus FinishStage(); private: ParkAndGoStatus CheckADCParkAndGoCruiseCompleted( const ReferenceLineInfo& reference_line_info); private: ScenarioParkAndGoConfig scenario_config_; }; } // namespace park_and_go } // namespace scenario } // namespace planning } // namespace apollo
0
apollo_public_repos/apollo/modules/planning/scenarios
apollo_public_repos/apollo/modules/planning/scenarios/park_and_go/stage_adjust_test.cc
/****************************************************************************** * Copyright 2019 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 **/ #include "modules/planning/scenarios/park_and_go/stage_adjust.h" #include "gtest/gtest.h" #include "modules/planning/proto/planning_config.pb.h" namespace apollo { namespace planning { namespace scenario { namespace park_and_go { class ParkAndGoStageAdjustTest : public ::testing::Test { public: virtual void SetUp() { config_.set_stage_type(StageType::PARK_AND_GO_ADJUST); injector_ = std::make_shared<DependencyInjector>(); } protected: ScenarioConfig::StageConfig config_; std::shared_ptr<DependencyInjector> injector_; }; TEST_F(ParkAndGoStageAdjustTest, Init) { ParkAndGoStageAdjust park_and_go_stage_adjust(config_, injector_); EXPECT_EQ(park_and_go_stage_adjust.Name(), StageType_Name(StageType::PARK_AND_GO_ADJUST)); } } // namespace park_and_go } // namespace scenario } // namespace planning } // namespace apollo
0
apollo_public_repos/apollo/modules/planning/scenarios
apollo_public_repos/apollo/modules/planning/scenarios/park_and_go/park_and_go_scenario.h
/****************************************************************************** * Copyright 2019 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 park_and_go_scenario.h */ #pragma once #include <memory> #include "modules/planning/scenarios/scenario.h" namespace apollo { namespace planning { namespace scenario { namespace park_and_go { // stage context struct ParkAndGoContext { ScenarioParkAndGoConfig scenario_config; }; class ParkAndGoScenario : public Scenario { public: ParkAndGoScenario(const ScenarioConfig& config, const ScenarioContext* context, const std::shared_ptr<DependencyInjector>& injector) : Scenario(config, context, injector) {} void Init() override; std::unique_ptr<Stage> CreateStage( const ScenarioConfig::StageConfig& stage_config, const std::shared_ptr<DependencyInjector>& injector) override; ParkAndGoContext* GetContext() { return &context_; } private: static void RegisterStages(); bool GetScenarioConfig(); private: static apollo::common::util::Factory< StageType, Stage, Stage* (*)(const ScenarioConfig::StageConfig& stage_config, const std::shared_ptr<DependencyInjector>& injector)> s_stage_factory_; bool init_ = false; ParkAndGoContext context_; }; } // namespace park_and_go } // namespace scenario } // namespace planning } // namespace apollo
0
apollo_public_repos/apollo/modules/planning/scenarios
apollo_public_repos/apollo/modules/planning/scenarios/park_and_go/park_and_go_scenario.cc
/****************************************************************************** * Copyright 2019 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. *****************************************************************************/ #include "modules/planning/scenarios/park_and_go/park_and_go_scenario.h" #include "cyber/common/log.h" #include "modules/planning/scenarios/park_and_go/stage_adjust.h" #include "modules/planning/scenarios/park_and_go/stage_check.h" #include "modules/planning/scenarios/park_and_go/stage_cruise.h" #include "modules/planning/scenarios/park_and_go/stage_pre_cruise.h" namespace apollo { namespace planning { namespace scenario { namespace park_and_go { apollo::common::util::Factory< StageType, Stage, Stage* (*)(const ScenarioConfig::StageConfig& stage_config, const std::shared_ptr<DependencyInjector>& injector)> ParkAndGoScenario::s_stage_factory_; void ParkAndGoScenario::Init() { if (init_) { return; } Scenario::Init(); if (!GetScenarioConfig()) { AERROR << "fail to get scenario specific config"; return; } init_ = true; } void ParkAndGoScenario::RegisterStages() { if (!s_stage_factory_.Empty()) { s_stage_factory_.Clear(); } s_stage_factory_.Register( StageType::PARK_AND_GO_CHECK, [](const ScenarioConfig::StageConfig& config, const std::shared_ptr<DependencyInjector>& injector) -> Stage* { return new ParkAndGoStageCheck(config, injector); }); s_stage_factory_.Register( StageType::PARK_AND_GO_ADJUST, [](const ScenarioConfig::StageConfig& config, const std::shared_ptr<DependencyInjector>& injector) -> Stage* { return new ParkAndGoStageAdjust(config, injector); }); s_stage_factory_.Register( StageType::PARK_AND_GO_PRE_CRUISE, [](const ScenarioConfig::StageConfig& config, const std::shared_ptr<DependencyInjector>& injector) -> Stage* { return new ParkAndGoStagePreCruise(config, injector); }); s_stage_factory_.Register( StageType::PARK_AND_GO_CRUISE, [](const ScenarioConfig::StageConfig& config, const std::shared_ptr<DependencyInjector>& injector) -> Stage* { return new ParkAndGoStageCruise(config, injector); }); } std::unique_ptr<Stage> ParkAndGoScenario::CreateStage( const ScenarioConfig::StageConfig& stage_config, const std::shared_ptr<DependencyInjector>& injector) { if (s_stage_factory_.Empty()) { RegisterStages(); } auto ptr = s_stage_factory_.CreateObjectOrNull(stage_config.stage_type(), stage_config, injector); if (ptr) { ptr->SetContext(&context_); } return ptr; } bool ParkAndGoScenario::GetScenarioConfig() { if (!config_.has_park_and_go_config()) { AERROR << "miss scenario specific config"; return false; } context_.scenario_config.CopyFrom(config_.park_and_go_config()); return true; } } // namespace park_and_go } // namespace scenario } // namespace planning } // namespace apollo
0
apollo_public_repos/apollo/modules/planning/scenarios
apollo_public_repos/apollo/modules/planning/scenarios/park_and_go/stage_cruise_test.cc
/****************************************************************************** * Copyright 2019 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 stage_cruise_test.cc */ #include "modules/planning/scenarios/park_and_go/stage_cruise.h" #include "cyber/common/file.h" #include "cyber/common/log.h" #include "gtest/gtest.h" #include "modules/planning/common/planning_gflags.h" #include "modules/planning/proto/planning_config.pb.h" namespace apollo { namespace planning { namespace scenario { namespace park_and_go { class ParkAndGoStageCruiseTest : public ::testing::Test { public: virtual void SetUp() { config_.set_stage_type(StageType::PARK_AND_GO_CRUISE); injector_ = std::make_shared<DependencyInjector>(); } protected: ScenarioConfig::StageConfig config_; std::shared_ptr<DependencyInjector> injector_; }; TEST_F(ParkAndGoStageCruiseTest, Init) { ParkAndGoStageCruise park_and_go_stage_cruise(config_, injector_); EXPECT_EQ(park_and_go_stage_cruise.Name(), StageType_Name(StageType::PARK_AND_GO_CRUISE)); } } // namespace park_and_go } // namespace scenario } // namespace planning } // namespace apollo
0
apollo_public_repos/apollo/modules/planning/scenarios
apollo_public_repos/apollo/modules/planning/scenarios/park_and_go/stage_check.cc
/****************************************************************************** * Copyright 2019 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. *****************************************************************************/ #include "modules/planning/scenarios/park_and_go/stage_check.h" namespace apollo { namespace planning { namespace scenario { namespace park_and_go { using apollo::common::TrajectoryPoint; Stage::StageStatus ParkAndGoStageCheck::Process( const TrajectoryPoint& planning_init_point, Frame* frame) { ADEBUG << "stage: Check"; CHECK_NOTNULL(frame); scenario_config_.CopyFrom(GetContext()->scenario_config); ADCInitStatus(); frame->mutable_open_space_info()->set_is_on_open_space_trajectory(true); bool plan_ok = ExecuteTaskOnOpenSpace(frame); if (!plan_ok) { AERROR << "ParkAndGoStageAdjust planning error"; return StageStatus::ERROR; } bool ready_to_cruise = scenario::util::CheckADCReadyToCruise( injector_->vehicle_state(), frame, scenario_config_); return FinishStage(ready_to_cruise); } Stage::StageStatus ParkAndGoStageCheck::FinishStage(const bool success) { if (success) { next_stage_ = StageType::PARK_AND_GO_CRUISE; } else { next_stage_ = StageType::PARK_AND_GO_ADJUST; } injector_->planning_context() ->mutable_planning_status() ->mutable_park_and_go() ->set_in_check_stage(false); return Stage::FINISHED; } void ParkAndGoStageCheck::ADCInitStatus() { auto* park_and_go_status = injector_->planning_context() ->mutable_planning_status() ->mutable_park_and_go(); park_and_go_status->Clear(); park_and_go_status->mutable_adc_init_position()->set_x( injector_->vehicle_state()->x()); park_and_go_status->mutable_adc_init_position()->set_y( injector_->vehicle_state()->y()); park_and_go_status->mutable_adc_init_position()->set_z(0.0); park_and_go_status->set_adc_init_heading( injector_->vehicle_state()->heading()); park_and_go_status->set_in_check_stage(true); } } // namespace park_and_go } // namespace scenario } // namespace planning } // namespace apollo
0
apollo_public_repos/apollo/modules/planning/scenarios
apollo_public_repos/apollo/modules/planning/scenarios/park_and_go/BUILD
load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test") load("//tools:cpplint.bzl", "cpplint") load("//third_party/gpus:common.bzl", "if_cuda", "if_rocm") package(default_visibility = ["//visibility:public"]) cc_library( name = "park_and_go_scenario", srcs = [ "park_and_go_scenario.cc", "stage_adjust.cc", "stage_check.cc", "stage_cruise.cc", "stage_pre_cruise.cc", ], hdrs = [ "park_and_go_scenario.h", "stage_adjust.h", "stage_check.h", "stage_cruise.h", "stage_pre_cruise.h", ], copts = ["-DMODULE_NAME=\\\"planning\\\""], deps = [ "//cyber", "//modules/common/util:util_tool", "//modules/common/vehicle_state:vehicle_state_provider", "//modules/planning/common:planning_common", "//modules/planning/common/util:common_lib", "//modules/planning/common/util:util_lib", "//modules/common_msgs/planning_msgs:planning_cc_proto", "//modules/planning/scenarios:scenario", "//modules/planning/scenarios/util:scenario_util_lib", "//modules/planning/tasks/deciders/path_bounds_decider", "@com_github_gflags_gflags//:gflags", ], ) cc_test( name = "park_and_go_scenario_test", size = "small", srcs = ["park_and_go_scenario_test.cc"], data = [ "//modules/planning:planning_conf", ], linkopts = ["-lgomp"], deps = [ ":park_and_go_scenario", "@com_google_googletest//:gtest_main", ] + if_cuda([ "@local_config_cuda//cuda:cudart", ]) + if_rocm([ "@local_config_rocm//rocm:hip", ]), linkstatic = True, ) cc_test( name = "park_and_go_stages_test", size = "small", srcs = [ "stage_adjust_test.cc", "stage_check_test.cc", "stage_cruise_test.cc", "stage_pre_cruise_test.cc", ], data = [ "//modules/planning:planning_conf", ], linkopts = ["-lgomp"], deps = [ ":park_and_go_scenario", "@com_google_googletest//:gtest_main", ] + if_cuda([ "@local_config_cuda//cuda:cudart", ]) + if_rocm([ "@local_config_rocm//rocm:hip", ]), linkstatic = True, ) cpplint()
0
apollo_public_repos/apollo/modules/planning/scenarios
apollo_public_repos/apollo/modules/planning/scenarios/park_and_go/stage_pre_cruise_test.cc
/****************************************************************************** * Copyright 2019 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 stage_pre_cruise_test.cc */ #include "modules/planning/scenarios/park_and_go/stage_pre_cruise.h" #include "cyber/common/file.h" #include "cyber/common/log.h" #include "gtest/gtest.h" #include "modules/planning/common/planning_gflags.h" #include "modules/planning/proto/planning_config.pb.h" namespace apollo { namespace planning { namespace scenario { namespace park_and_go { class ParkAndGoStagePreCruiseTest : public ::testing::Test { public: virtual void SetUp() { config_.set_stage_type(StageType::PARK_AND_GO_PRE_CRUISE); injector_ = std::make_shared<DependencyInjector>(); } protected: ScenarioConfig::StageConfig config_; std::shared_ptr<DependencyInjector> injector_; }; TEST_F(ParkAndGoStagePreCruiseTest, Init) { ParkAndGoStagePreCruise park_and_go_stage_pre_cruise(config_, injector_); EXPECT_EQ( park_and_go_stage_pre_cruise.Name(), StageType_Name(StageType::PARK_AND_GO_PRE_CRUISE)); } } // namespace park_and_go } // namespace scenario } // namespace planning } // namespace apollo
0
apollo_public_repos/apollo/modules/planning/scenarios
apollo_public_repos/apollo/modules/planning/scenarios/narrow_street_u_turn/narrow_street_u_turn_scenario_test.cc
/****************************************************************************** * Copyright 2019 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 **/ #include "modules/planning/scenarios/narrow_street_u_turn/narrow_street_u_turn_scenario.h" #include "cyber/common/file.h" #include "cyber/common/log.h" #include "gtest/gtest.h" #include "modules/planning/common/planning_gflags.h" namespace apollo { namespace planning { namespace scenario { namespace narrow_street_u_turn { class NarrowStreetUTurnTest : public ::testing::Test { public: virtual void SetUp() {} protected: std::unique_ptr<NarrowStreetUTurnScenario> scenario_; }; TEST_F(NarrowStreetUTurnTest, Init) { FLAGS_scenario_narrow_street_u_turn_config_file = "/apollo/modules/planning/conf/scenario/" "narrow_street_u_turn_config.pb.txt"; ScenarioConfig config; EXPECT_TRUE(apollo::cyber::common::GetProtoFromFile( FLAGS_scenario_narrow_street_u_turn_config_file, &config)); ScenarioContext context; auto injector = std::make_shared<DependencyInjector>(); scenario_.reset(new NarrowStreetUTurnScenario(config, &context, injector)); EXPECT_EQ(scenario_->scenario_type(), ScenarioType::NARROW_STREET_U_TURN); } } // namespace narrow_street_u_turn } // namespace scenario } // namespace planning } // namespace apollo
0