Skip to content

Commit

Permalink
planning: adjust and integrate traffic-light scenarios
Browse files Browse the repository at this point in the history
  • Loading branch information
jmtao committed Jan 15, 2019
1 parent 3665944 commit 820b735
Show file tree
Hide file tree
Showing 17 changed files with 59 additions and 66 deletions.
4 changes: 2 additions & 2 deletions modules/planning/common/planning_gflags.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ DEFINE_string(scenario_stop_sign_unprotected_config_file,
"/apollo/modules/planning/conf/"
"scenario/stop_sign_unprotected_config.pb.txt",
"stop_sign_unprotected scenario configuration file");
DEFINE_string(scenario_traffic_light_right_turn_unprotected_config_file,
DEFINE_string(scenario_traffic_light_unprotected_right_turn_config_file,
"/apollo/modules/planning/conf/"
"scenario/traffic_light_right_turn_unprotected_config.pb.txt",
"scenario_traffic_light_right_turn_unprotected config file");
Expand All @@ -56,7 +56,7 @@ DEFINE_bool(enable_scenario_side_pass_multiple_parked_obstacles, true,

DEFINE_bool(enable_scenario_stop_sign_unprotected, true,
"enable stop_sign_unprotected scenario in planning");
DEFINE_bool(enable_scenario_traffic_light_right_turn_unprotected, false,
DEFINE_bool(enable_scenario_traffic_light_unprotected_right_turn, false,
"enable traffic_light_right_turn_unprotected scenario in planning");

DEFINE_string(traffic_rule_config_filename,
Expand Down
4 changes: 2 additions & 2 deletions modules/planning/common/planning_gflags.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ DECLARE_string(planning_config_file);
DECLARE_string(scenario_lane_follow_config_file);
DECLARE_string(scenario_side_pass_config_file);
DECLARE_string(scenario_stop_sign_unprotected_config_file);
DECLARE_string(scenario_traffic_light_right_turn_unprotected_config_file);
DECLARE_string(scenario_traffic_light_unprotected_right_turn_config_file);

DECLARE_bool(enable_scenario_side_pass);
DECLARE_double(side_pass_min_signal_intersection_distance);
DECLARE_bool(enable_scenario_side_pass_multiple_parked_obstacles);
DECLARE_bool(enable_scenario_stop_sign_unprotected);
DECLARE_bool(enable_scenario_traffic_light_right_turn_unprotected);
DECLARE_bool(enable_scenario_traffic_light_unprotected_right_turn);

DECLARE_string(traffic_rule_config_filename);
DECLARE_string(smoother_config_filename);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
scenario_type: TRAFFIC_LIGHT_RIGHT_TURN_UNPROTECTED
traffic_light_right_turn_unprotected_config: {
scenario_type: TRAFFIC_LIGHT_UNPROTECTED_RIGHT_TURN
traffic_light_unprotected_right_turn_config: {
max_valid_stop_distance: 3.5
max_adc_stop_speed: 0.3
min_pass_s_distance: 3.0
red_light_right_turn_stop_duration: 3.0
creep_timeout: 10.0
}
stage_type: TRAFFIC_LIGHT_RIGHT_TURN_UNPROTECTED_STOP
stage_type: TRAFFIC_LIGHT_RIGHT_TURN_UNPROTECTED_CREEP
stage_type: TRAFFIC_LIGHT_RIGHT_TURN_UNPROTECTED_INTERSECTION_CRUISE
stage_type: TRAFFIC_LIGHT_UNPROTECTED_RIGHT_TURN_STOP
stage_type: TRAFFIC_LIGHT_UNPROTECTED_RIGHT_TURN_CREEP
stage_type: TRAFFIC_LIGHT_UNPROTECTED_RIGHT_TURN_INTERSECTION_CRUISE

stage_config: {
stage_type: TRAFFIC_LIGHT_RIGHT_TURN_UNPROTECTED_STOP
stage_type: TRAFFIC_LIGHT_UNPROTECTED_RIGHT_TURN_STOP
enabled: true
task_type: DECIDER_RULE_BASED_STOP
task_type: DP_POLY_PATH_OPTIMIZER
Expand Down Expand Up @@ -40,7 +40,7 @@ stage_config: {
}

stage_config: {
stage_type: TRAFFIC_LIGHT_RIGHT_TURN_UNPROTECTED_CREEP
stage_type: TRAFFIC_LIGHT_UNPROTECTED_RIGHT_TURN_CREEP
enabled: true
task_type: DECIDER_RULE_BASED_STOP
task_type: DECIDER_CREEP
Expand Down Expand Up @@ -84,7 +84,7 @@ stage_config: {
}

stage_config: {
stage_type: TRAFFIC_LIGHT_RIGHT_TURN_UNPROTECTED_INTERSECTION_CRUISE
stage_type: TRAFFIC_LIGHT_UNPROTECTED_RIGHT_TURN_INTERSECTION_CRUISE
enabled: true
task_type: DECIDER_RULE_BASED_STOP
task_type: DP_POLY_PATH_OPTIMIZER
Expand Down
2 changes: 1 addition & 1 deletion modules/planning/integration_tests/garage_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class GarageTest : public PlanningTestBase {

FLAGS_enable_scenario_side_pass = false;
FLAGS_enable_scenario_stop_sign_unprotected = false;
FLAGS_enable_scenario_traffic_light_right_turn_unprotected = false;
FLAGS_enable_scenario_traffic_light_unprotected_right_turn = false;
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class SunnyvaleBigLoopTest : public PlanningTestBase {

FLAGS_enable_scenario_side_pass = false;
FLAGS_enable_scenario_stop_sign_unprotected = false;
FLAGS_enable_scenario_traffic_light_right_turn_unprotected = false;
FLAGS_enable_scenario_traffic_light_unprotected_right_turn = false;
FLAGS_enable_rss_info = false;

ENABLE_RULE(TrafficRuleConfig::CROSSWALK, false);
Expand Down
2 changes: 1 addition & 1 deletion modules/planning/integration_tests/sunnyvale_loop_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class SunnyvaleLoopTest : public PlanningTestBase {

FLAGS_enable_scenario_side_pass = false;
FLAGS_enable_scenario_stop_sign_unprotected = false;
FLAGS_enable_scenario_traffic_light_right_turn_unprotected = false;
FLAGS_enable_scenario_traffic_light_unprotected_right_turn = false;
FLAGS_enable_rss_info = false;

ENABLE_RULE(TrafficRuleConfig::CROSSWALK, false);
Expand Down
18 changes: 8 additions & 10 deletions modules/planning/proto/planning_config.proto
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ message ScenarioStopSignUnprotectedConfig {
optional float creep_timeout = 8 [default = 10.0]; // secoond
}

message ScenarioTrafficLightRightTurnUnprotectedConfig {
message ScenarioTrafficLightUnprotectedRightTurnConfig {
optional double max_valid_stop_distance = 1 [default = 3.5]; // meter
optional double max_adc_stop_speed = 2 [default = 0.3]; // m/s
optional double min_pass_s_distance = 3 [default = 3.0]; // meter
Expand All @@ -109,11 +109,9 @@ message ScenarioConfig {
APPROACH = 3; // approach to an intersection
STOP_SIGN_PROTECTED = 4;
STOP_SIGN_UNPROTECTED = 5;
TRAFFIC_LIGHT_LEFT_TURN_PROTECTED = 6;
TRAFFIC_LIGHT_LEFT_TURN_UNPROTECTED = 7;
TRAFFIC_LIGHT_RIGHT_TURN_PROTECTED = 8;
TRAFFIC_LIGHT_RIGHT_TURN_UNPROTECTED = 9;
TRAFFIC_LIGHT_GO_THROUGH = 10;
TRAFFIC_LIGHT_PROTECTED = 6;
TRAFFIC_LIGHT_UNPROTECTED_LEFT_TURN = 7;
TRAFFIC_LIGHT_UNPROTECTED_RIGHT_TURN = 8;
}

// StageType is a superset of stages from all scenarios.
Expand All @@ -135,9 +133,9 @@ message ScenarioConfig {
SIDE_PASS_PASS_OBSTACLE = 204;
SIDE_PASS_BACKUP = 205;

TRAFFIC_LIGHT_RIGHT_TURN_UNPROTECTED_STOP = 300;
TRAFFIC_LIGHT_RIGHT_TURN_UNPROTECTED_CREEP = 301 ;
TRAFFIC_LIGHT_RIGHT_TURN_UNPROTECTED_INTERSECTION_CRUISE = 302;
TRAFFIC_LIGHT_UNPROTECTED_RIGHT_TURN_STOP = 300;
TRAFFIC_LIGHT_UNPROTECTED_RIGHT_TURN_CREEP = 301 ;
TRAFFIC_LIGHT_UNPROTECTED_RIGHT_TURN_INTERSECTION_CRUISE = 302;
};

message StageConfig {
Expand All @@ -154,7 +152,7 @@ message ScenarioConfig {
ScenarioLaneFollowConfig lane_follow_config = 2;
ScenarioSidePassConfig side_pass_config = 3;
ScenarioStopSignUnprotectedConfig stop_sign_unprotected_config = 4;
ScenarioTrafficLightRightTurnUnprotectedConfig traffic_light_right_turn_unprotected_config = 5;
ScenarioTrafficLightUnprotectedRightTurnConfig traffic_light_unprotected_right_turn_config = 5;
}
// a list of stages that are used at runtime. The first one is default stage.
repeated StageType stage_type = 6;
Expand Down
10 changes: 5 additions & 5 deletions modules/planning/scenarios/scenario_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ std::unique_ptr<Scenario> ScenarioManager::CreateScenario(
ptr.reset(new scenario::stop_sign::StopSignUnprotectedScenario(
config_map_[scenario_type], &scenario_context_));
break;
case ScenarioConfig::TRAFFIC_LIGHT_RIGHT_TURN_UNPROTECTED:
case ScenarioConfig::TRAFFIC_LIGHT_UNPROTECTED_RIGHT_TURN:
ptr.reset(
new scenario::traffic_light::TrafficLightRightTurnUnprotectedScenario(
config_map_[scenario_type], &scenario_context_));
Expand All @@ -84,8 +84,8 @@ void ScenarioManager::RegisterScenarios() {
FLAGS_scenario_stop_sign_unprotected_config_file,
&config_map_[ScenarioConfig::STOP_SIGN_UNPROTECTED]));
CHECK(Scenario::LoadConfig(
FLAGS_scenario_traffic_light_right_turn_unprotected_config_file,
&config_map_[ScenarioConfig::TRAFFIC_LIGHT_RIGHT_TURN_UNPROTECTED]));
FLAGS_scenario_traffic_light_unprotected_right_turn_config_file,
&config_map_[ScenarioConfig::TRAFFIC_LIGHT_UNPROTECTED_RIGHT_TURN]));
}

bool ScenarioManager::SelectChangeLaneScenario(
Expand Down Expand Up @@ -220,9 +220,9 @@ void ScenarioManager::Update(const common::TrajectoryPoint& ego_point,
}
} else if (overlap.first == ReferenceLineInfo::SIGNAL) {
// traffic_light scenarios
if (FLAGS_enable_scenario_traffic_light_right_turn_unprotected) {
if (FLAGS_enable_scenario_traffic_light_unprotected_right_turn) {
preferred_scenario =
ScenarioConfig::TRAFFIC_LIGHT_RIGHT_TURN_UNPROTECTED;
ScenarioConfig::TRAFFIC_LIGHT_UNPROTECTED_RIGHT_TURN;
}
}
if (rejected_scenarios.find(preferred_scenario) !=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,9 @@ bool StopSignUnprotectedScenario::IsTransferable(
case ScenarioConfig::STOP_SIGN_UNPROTECTED:
return (current_scenario.GetStatus() !=
Scenario::ScenarioStatus::STATUS_DONE);
case ScenarioConfig::TRAFFIC_LIGHT_LEFT_TURN_PROTECTED:
case ScenarioConfig::TRAFFIC_LIGHT_LEFT_TURN_UNPROTECTED:
case ScenarioConfig::TRAFFIC_LIGHT_RIGHT_TURN_PROTECTED:
case ScenarioConfig::TRAFFIC_LIGHT_RIGHT_TURN_UNPROTECTED:
case ScenarioConfig::TRAFFIC_LIGHT_GO_THROUGH:
case ScenarioConfig::TRAFFIC_LIGHT_PROTECTED:
case ScenarioConfig::TRAFFIC_LIGHT_UNPROTECTED_LEFT_TURN:
case ScenarioConfig::TRAFFIC_LIGHT_UNPROTECTED_RIGHT_TURN:
default:
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class StageCreep : public Stage {
Stage::StageStatus FinishStage();

private:
ScenarioTrafficLightRightTurnUnprotectedConfig scenario_config_;
ScenarioTrafficLightUnprotectedRightTurnConfig scenario_config_;
};

} // namespace traffic_light
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class StageIntersectionCruise : public Stage {
Stage::StageStatus FinishStage();

private:
ScenarioTrafficLightRightTurnUnprotectedConfig scenario_config_;
ScenarioTrafficLightUnprotectedRightTurnConfig scenario_config_;
};

} // namespace traffic_light
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ Stage::StageStatus StageStop::Process(
if (PlanningContext::GetScenarioInfo()->traffic_light_color ==
TrafficLight::GREEN) {
next_stage_ = ScenarioConfig::
TRAFFIC_LIGHT_RIGHT_TURN_UNPROTECTED_INTERSECTION_CRUISE;
TRAFFIC_LIGHT_UNPROTECTED_RIGHT_TURN_INTERSECTION_CRUISE;
return Stage::FINISHED;
}

Expand All @@ -105,7 +105,7 @@ Stage::StageStatus StageStop::FinishStage() {
GetContext()->traffic_light_id;
GetContext()->creep_start_time = Clock::NowInSeconds();

next_stage_ = ScenarioConfig::TRAFFIC_LIGHT_RIGHT_TURN_UNPROTECTED_CREEP;
next_stage_ = ScenarioConfig::TRAFFIC_LIGHT_UNPROTECTED_RIGHT_TURN_CREEP;
return Stage::FINISHED;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class StageStop : public Stage {
Stage::StageStatus FinishStage();

private:
ScenarioTrafficLightRightTurnUnprotectedConfig scenario_config_;
ScenarioTrafficLightUnprotectedRightTurnConfig scenario_config_;
};

} // namespace traffic_light
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,17 @@ void TrafficLightRightTurnUnprotectedScenario::RegisterStages() {
s_stage_factory_.Clear();
}
s_stage_factory_.Register(
ScenarioConfig::TRAFFIC_LIGHT_RIGHT_TURN_UNPROTECTED_STOP,
ScenarioConfig::TRAFFIC_LIGHT_UNPROTECTED_RIGHT_TURN_STOP,
[](const ScenarioConfig::StageConfig& config) -> Stage* {
return new StageStop(config);
});
s_stage_factory_.Register(
ScenarioConfig::TRAFFIC_LIGHT_RIGHT_TURN_UNPROTECTED_CREEP,
ScenarioConfig::TRAFFIC_LIGHT_UNPROTECTED_RIGHT_TURN_CREEP,
[](const ScenarioConfig::StageConfig& config) -> Stage* {
return new StageCreep(config);
});
s_stage_factory_.Register(
ScenarioConfig::TRAFFIC_LIGHT_RIGHT_TURN_UNPROTECTED_INTERSECTION_CRUISE,
ScenarioConfig::TRAFFIC_LIGHT_UNPROTECTED_RIGHT_TURN_INTERSECTION_CRUISE,
[](const ScenarioConfig::StageConfig& config) -> Stage* {
return new StageIntersectionCruise(config);
});
Expand Down Expand Up @@ -128,7 +128,7 @@ bool TrafficLightRightTurnUnprotectedScenario::IsTransferable(
const double adc_speed =
common::VehicleStateProvider::Instance()->linear_velocity();

auto scenario_config = config_.traffic_light_right_turn_unprotected_config();
auto scenario_config = config_.traffic_light_unprotected_right_turn_config();

bool is_stopped_for_traffic_light = true;
if (adc_speed > scenario_config.max_adc_stop_speed() ||
Expand All @@ -151,15 +151,12 @@ bool TrafficLightRightTurnUnprotectedScenario::IsTransferable(
TrafficLight::RED);
case ScenarioConfig::STOP_SIGN_PROTECTED:
case ScenarioConfig::STOP_SIGN_UNPROTECTED:
case ScenarioConfig::TRAFFIC_LIGHT_LEFT_TURN_PROTECTED:
case ScenarioConfig::TRAFFIC_LIGHT_LEFT_TURN_UNPROTECTED:
case ScenarioConfig::TRAFFIC_LIGHT_RIGHT_TURN_PROTECTED:
case ScenarioConfig::TRAFFIC_LIGHT_PROTECTED:
case ScenarioConfig::TRAFFIC_LIGHT_UNPROTECTED_LEFT_TURN:
return false;
case ScenarioConfig::TRAFFIC_LIGHT_RIGHT_TURN_UNPROTECTED:
case ScenarioConfig::TRAFFIC_LIGHT_UNPROTECTED_RIGHT_TURN:
return (current_scenario.GetStatus() !=
Scenario::ScenarioStatus::STATUS_DONE);
case ScenarioConfig::TRAFFIC_LIGHT_GO_THROUGH:
return false;
default:
break;
}
Expand All @@ -171,12 +168,12 @@ bool TrafficLightRightTurnUnprotectedScenario::IsTransferable(
* read scenario specific configs and set in context_ for stages to read
*/
bool TrafficLightRightTurnUnprotectedScenario::GetScenarioConfig() {
if (!config_.has_traffic_light_right_turn_unprotected_config()) {
if (!config_.has_traffic_light_unprotected_right_turn_config()) {
AERROR << "miss scenario specific config";
return false;
}
context_.scenario_config.CopyFrom(
config_.traffic_light_right_turn_unprotected_config());
config_.traffic_light_unprotected_right_turn_config());
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace traffic_light {

// stage context
struct TrafficLightRightTurnUnprotectedContext {
ScenarioTrafficLightRightTurnUnprotectedConfig scenario_config;
ScenarioTrafficLightUnprotectedRightTurnConfig scenario_config;
std::string traffic_light_id;
double stop_start_time = 0.0;
double creep_start_time;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,31 +42,31 @@ class TrafficLightRightTurnUnprotectedScenarioTest : public ::testing::Test {
};

TEST_F(TrafficLightRightTurnUnprotectedScenarioTest, VerifyConf) {
FLAGS_scenario_stop_sign_unprotected_config_file =
FLAGS_scenario_traffic_light_unprotected_right_turn_config_file =
"/apollo/modules/planning/conf/"
"scenario/traffic_light_right_turn_unprotected_config.pb.txt";

ScenarioConfig config;
EXPECT_TRUE(apollo::common::util::GetProtoFromFile(
FLAGS_scenario_traffic_light_right_turn_unprotected_config_file,
FLAGS_scenario_traffic_light_unprotected_right_turn_config_file,
&config));
}

TEST_F(TrafficLightRightTurnUnprotectedScenarioTest, Init) {
FLAGS_scenario_stop_sign_unprotected_config_file =
FLAGS_scenario_traffic_light_unprotected_right_turn_config_file =
"/apollo/modules/planning/testdata/conf/"
"scenario/traffic_light_right_turn_unprotected_config.pb.txt";

ScenarioConfig config;
EXPECT_TRUE(apollo::common::util::GetProtoFromFile(
FLAGS_scenario_traffic_light_right_turn_unprotected_config_file,
FLAGS_scenario_traffic_light_unprotected_right_turn_config_file,
&config));

ScenarioContext context;
scenario_.reset(new TrafficLightRightTurnUnprotectedScenario(config,
&context));
EXPECT_EQ(scenario_->scenario_type(),
ScenarioConfig::TRAFFIC_LIGHT_RIGHT_TURN_UNPROTECTED);
ScenarioConfig::TRAFFIC_LIGHT_UNPROTECTED_RIGHT_TURN);
}

} // namespace traffic_light
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
scenario_type: TRAFFIC_LIGHT_RIGHT_TURN_UNPROTECTED
traffic_light_right_turn_unprotected_config: {
scenario_type: TRAFFIC_LIGHT_UNPROTECTED_RIGHT_TURN
traffic_light_unprotected_right_turn_config: {
max_valid_stop_distance: 3.5
max_adc_stop_speed: 0.3
min_pass_s_distance: 3.0
red_light_right_turn_stop_duration: 3.0
creep_timeout: 10.0
}
stage_type: TRAFFIC_LIGHT_RIGHT_TURN_UNPROTECTED_STOP
stage_type: TRAFFIC_LIGHT_RIGHT_TURN_UNPROTECTED_CREEP
stage_type: TRAFFIC_LIGHT_RIGHT_TURN_UNPROTECTED_INTERSECTION_CRUISE
stage_type: TRAFFIC_LIGHT_UNPROTECTED_RIGHT_TURN_STOP
stage_type: TRAFFIC_LIGHT_UNPROTECTED_RIGHT_TURN_CREEP
stage_type: TRAFFIC_LIGHT_UNPROTECTED_RIGHT_TURN_INTERSECTION_CRUISE

stage_config: {
stage_type: TRAFFIC_LIGHT_RIGHT_TURN_UNPROTECTED_STOP
stage_type: TRAFFIC_LIGHT_UNPROTECTED_RIGHT_TURN_STOP
enabled: true
task_type: DECIDER_RULE_BASED_STOP
task_type: DP_POLY_PATH_OPTIMIZER
Expand Down Expand Up @@ -40,7 +40,7 @@ stage_config: {
}

stage_config: {
stage_type: TRAFFIC_LIGHT_RIGHT_TURN_UNPROTECTED_CREEP
stage_type: TRAFFIC_LIGHT_UNPROTECTED_RIGHT_TURN_CREEP
enabled: true
task_type: DECIDER_RULE_BASED_STOP
task_type: DECIDER_CREEP
Expand Down Expand Up @@ -84,7 +84,7 @@ stage_config: {
}

stage_config: {
stage_type: TRAFFIC_LIGHT_RIGHT_TURN_UNPROTECTED_INTERSECTION_CRUISE
stage_type: TRAFFIC_LIGHT_UNPROTECTED_RIGHT_TURN_INTERSECTION_CRUISE
enabled: true
task_type: DECIDER_RULE_BASED_STOP
task_type: DP_POLY_PATH_OPTIMIZER
Expand Down

0 comments on commit 820b735

Please sign in to comment.