Apollo 2.0 Planning 源码(1)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// 模块入口
APOLLO_MAIN(apollo::planning::Planning)
int main(int argc, char **argv)
{
google::InitGoogleLogging(argv[0]);
google::ParseCommandLineFlags(&argc, &argv, true);
signal(SIGINT, apollo::common::apollo_app_sigint_handler);
apollo::planning::Planning apollo_app_ ;
ros::init(argc, argv, apollo_app_.Name());
apollo_app_.Spin();
return 0;
}
///////////////////////////////////////////////////////
int ApolloApp::Spin()
{
ros::AsyncSpinner spinner(callback_thread_num_);
auto status = Init();
status = Start();
spinner.start();
ros::waitForShutdown();
Stop();
return 0;
}
///////////////////////////////////////////////////////
Status Planning::Init()
{
hdmap_ = apollo::hdmap::HDMapUtil::BaseMapPtr();
apollo::common::util::GetProtoFromFile(FLAGS_planning_config_file, &config);
if(!AdapterManager::Initialized()){
AdaapterManager::Init(FLAGS_planning_adapter_config_filename);
}
AdapterManager::GetLocalization();
AdapterManager::GetChassis();
AdapterManager::GetRoutingResponse();
AdapterManager::GetRoutingRequest();
if(FLAGS_enable_prediction)
AdapterManager::GetPrediction();
if(FLAGS_enable_traffic_light)
AdapterManager::GetTrafficLightDetection();
ReferenceLineProvider::instance()->Init(hdmap_, config_.qp_spline_reference_line_smoother_config());
RegisterPlanners();
planner_ = planner_factory_.CreateObject(config_.planner_type());
return planner_->Init(config_);
}
/* DEFINE_string(planning_adapter_config_filename,
"modules/planning/conf/adapter.conf",
"The adapter configuration file")
*/
///////////////////////////////////////////////////////////////
void AdapterManager::Init(const std::string &adapter_config_filename)
{
AdapterManagerConfig configs;
util::GetProtoFromFile(adapter_config_filename, &configs);
Init(configs);
}
//////////////////////////////////////////////////////////////
void AdapterManager::Init(const AdapterManagerConfig& configs)
{
if(Initialized()) return;
instance()->initialized_ = true;
if(configs.is_ros()){
instance()->node_handle_.reset(new ros::NodeHandle());
}
for(const auto &config : configs.config())
{
case AdapterConfig::CHASSIS:
EnableChassis(FLAGS_chassis_topic, config);
break;
case AdapterConfig::LOCALIZATION:
EnableLocalization(FLAGS_localization_topic, config);
break;
// ...
}
}
/* DEFINE_string 宏
FLAGS_chassis_topic -> /apollo/canbus/chassis
FLAGS_localization_topic -> /apollo/localization/pose
*/

where is EnableChassis ?

in /apollo/modules/common/adapters/message_adapters.h

1
2
3
4
5
using ChassisAdapter=Adapter<::apollo::canbus::Chassis>;
using GpsAdapter = Adapter<apollo::localization::Gps>;
using PlanningAdapter = Adapter<planning::ADCTrajectory>;

in /apollo/modules/common/adapters/adapter_manager.h

1
2
3
4
#define REGISTER_ADAPTER(name)
public static void Enable##name(const std::string &topic_name, const AdapterConfig& config)
{
}
continue tomorrow