提交 ab42a281 编写于 作者: J jmtao 提交者: Xiangquan Xiao

planning: pull_over_emergency scenario

上级 e66c06fa
load("//tools:cpplint.bzl", "cpplint")
package(default_visibility = ["//visibility:public"])
cc_library(
name = "pull_over_emergency_scenario",
srcs = [
"pull_over_emergency_scenario.cc",
],
hdrs = [
"pull_over_emergency_scenario.h",
],
copts = ["-DMODULE_NAME=\\\"planning\\\""],
deps = [
"//cyber/common:log",
"//external:gflags",
"//modules/common/util:factory",
"//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/planning/proto:planning_proto",
"//modules/planning/scenarios:scenario",
"//modules/planning/scenarios/util:scenario_util_lib",
"@eigen",
],
)
cpplint()
/******************************************************************************
* 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_emergency/pull_over_emergency_scenario.h"
#include "cyber/common/log.h"
namespace apollo {
namespace planning {
namespace scenario {
namespace pull_over_emergency {
apollo::common::util::Factory<
ScenarioConfig::StageType, Stage,
Stage* (*)(const ScenarioConfig::StageConfig& stage_config)>
PullOverEmergencyScenario::s_stage_factory_;
void PullOverEmergencyScenario::Init() {
if (init_) {
return;
}
Scenario::Init();
if (!GetScenarioConfig()) {
AERROR << "fail to get scenario specific config";
return;
}
init_ = true;
}
void PullOverEmergencyScenario::RegisterStages() {
if (!s_stage_factory_.Empty()) {
s_stage_factory_.Clear();
}
/*
s_stage_factory_.Register(
ScenarioConfig::PULL_OVER_APPROACH,
[](const ScenarioConfig::StageConfig& config) -> Stage* {
return new PullOverEmergencyStageApproach(config);
});
*/
}
std::unique_ptr<Stage> PullOverEmergencyScenario::CreateStage(
const ScenarioConfig::StageConfig& stage_config) {
if (s_stage_factory_.Empty()) {
RegisterStages();
}
auto ptr = s_stage_factory_.CreateObjectOrNull(stage_config.stage_type(),
stage_config);
if (ptr) {
ptr->SetContext(&context_);
}
return ptr;
}
/*
* read scenario specific configs and set in context_ for stages to read
*/
bool PullOverEmergencyScenario::GetScenarioConfig() {
if (!config_.has_pull_over_emergency_config()) {
AERROR << "miss scenario specific config";
return false;
}
context_.scenario_config.CopyFrom(config_.pull_over_emergency_config());
return true;
}
} // namespace pull_over_emergency
} // namespace scenario
} // namespace planning
} // namespace apollo
/******************************************************************************
* 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_emergency {
// stage context
struct PullOverEmergencyContext {
ScenarioPullOverEmergencyConfig scenario_config;
};
class PullOverEmergencyScenario : public Scenario {
public:
PullOverEmergencyScenario(
const ScenarioConfig& config, const ScenarioContext* context)
: Scenario(config, context) {}
void Init() override;
std::unique_ptr<Stage> CreateStage(
const ScenarioConfig::StageConfig& stage_config);
PullOverEmergencyContext* GetContext() { return &context_; }
private:
static void RegisterStages();
bool GetScenarioConfig();
private:
static apollo::common::util::Factory<
ScenarioConfig::StageType, Stage,
Stage* (*)(const ScenarioConfig::StageConfig& stage_config)>
s_stage_factory_;
bool init_ = false;
PullOverEmergencyContext context_;
};
} // namespace pull_over_emergency
} // namespace scenario
} // namespace planning
} // namespace apollo
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册