Apollo2.0 Routing源码(2)

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
// 模块入口
APOLLO_MAIN(apollo::routing::Routing)
int main(int argc, char** argv)
{
google::InitGoogleLogging(arg[0]) ;
google::ParseCommandLineFlags(&argc, &argv, true);
signal(SIGINT, apollo::common::apollo_app_sigint_handler);
apollo::routing::Routing apollo_app_ ;
ros::init(argc, argv, apollo_app_.Name());
apollo_app_.Spin();
return 0;
}
```
`appollo_app_.Spin()` can be found [here](https://zjli2013.github.io/2019/04/28/apollo-planning-源码/)
```c
apollo::common:Status Routing::Init()
{
const auto routing_map_file = apollo::hdmap::RoutingMapFile() ;
navigator_ptr_.reset(new Navigator(routing_map_file)) ;
common::util::GetProtoFromFile(FLAGS_routing_conf_file, &routing_conf_);
hdmap_ = apollo::hdmap::HDMapUtil::BaseMapPtr();
AdapterManager::Init(FLAGS_routing_adapter_config_filename);
AdapterManager::AddRoutingRequestCallback(&Routing::OnRoutingRequest, this);
return apollo::common::Status::OK();
}
/*
DEFINE_string(routing_adapter_config_filename, "modules/routing/conf/adapter.conf", "the adapter config filename")
*/
void AdapterManager::Init()
{
//...
for(const auto &config :: configs.config())
{
case AdapterConfig::ROUTING_REQUEST :
EnableRoutingRequest(FLAGS_routing_request_topic, config);
break;
case AdapterConfig::ROUTING_RESPONSE:
EnableRoutingResponse(FLAGS_routing_response_topic, config);
break;
case AdapterConfig::ROUTING_MONITOR:
EnableMonitor(FLAGS_monitor_topic, config);
break;
//...
}
}

where define EnableRoutingRequest() ?

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
//apollo/modules/common/adapters/adapter_manager.h
#define REGISTER_ADAPTER(name)
static void Enable##name(const std::string &topic_name, const AdapterConfig &config)
{
instance()->InternalEnable##name(topic_name, config);
}
template<class T> static void Add##name##Callback(
void(T::*fp)(const name##Adapter::DataType &data), T *obj){
Add##name##Callback(std::bind(fp, obj, std::placeholders::_1));
}
tempalate<class T> static void Add##name##Callback(void (T::*fp)(const name##Adapter::DataType &data)){
Add##name##Callback(fp);
}
// apollo/modules/common/adapters/message_adapters.h
using RoutingRequestAdapter = Adapter<routing::RoutingRequest> ;
using RoutingResponseAdapter = Adapter<routing::RoutingResponse>;
// apollo/moduels/common/adapters/adapter.h
typedef typename std::function<void(const D&)> Callback ;
// apollo/modules/common/adapters/adapter.h
template <class D> void Adapter<D>:OnReceive(const D& message)
{
last_receive_time_ = apollo::common::time::Clock::NowInSeconds();
EnqueueData(message);
FireCallbacks(message);
}
void AddCallback(Callback callback)
{
receive_callbacks_.push_back(callback);
}
tempplate<class D> void Adapter<D>::FireCallbacks(const D& data)
{
for(const auto& callback : receive_callbacks_)
{
callback(data);
}
}

Dreamview and Planning modules have message publish API. e.g.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
SimulationWorldUpdater::(WebSocketHandler *websocket, SimControl *sim_control, const MapSerivce *map_service, bool routing_from_file) : sim_world_service_(map_service, routing_from_file),
map_service_(map_service),
websocket_(websocket),
sim_control_(sim_control)
{
// ...
websocket_->RegisterMessageHandler("SendRoutingRequest", [this][cosnt Json &json, WebSocketHandler::Connection *conn)
{
RoutingRequest routing_request,
bool succed = ConstructRoutingRequest(json, &routing_request);
if(succed){
AdapterManager::FillRoutingRequestHeader(FLAGS_dreamview_module_name, &routing_request);
AdapterManager::PublishRoutingRequest(routing_request);
}
}

ApapterManager class is used to make sure the connection among each module in ROS message type.

Routing class has GPS and IMU input and generate routing and velocity info as output.

Navigator class is using A start algorthm with hd map, start point and end point as input to generate a navigation route.