Apollo 11.0
自动驾驶开放平台
task_manager_component.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2020 The Apollo Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *****************************************************************************/
17
18#include "modules/task_manager/proto/task_manager_config.pb.h"
19
20#include "cyber/time/rate.h"
21
22namespace apollo {
23namespace task_manager {
24
33
35 TaskManagerConfig task_manager_conf;
37 << "Unable to load task_manager conf file: "
39
40 AINFO << "Config file: " << cyber::ComponentBase::ConfigFilePath()
41 << " is loaded.";
42
43 localization_reader_ = node_->CreateReader<LocalizationEstimate>(
44 task_manager_conf.topic_config().localization_pose_topic(),
45 [this](const std::shared_ptr<LocalizationEstimate>& localization) {
46 ADEBUG << "Received localization data: run localization callback.";
47 std::lock_guard<std::mutex> lock(mutex_);
48 localization_.CopyFrom(*localization);
49 });
50
51 planning_command_reader_ = node_->CreateReader<PlanningCommand>(
52 task_manager_conf.topic_config().planning_command_topic(),
53 [this](const std::shared_ptr<PlanningCommand>& planning_command) {
54 ADEBUG << "Received planning_command: run response callback.";
55 std::lock_guard<std::mutex> lock(mutex_);
56 planning_command_.CopyFrom(*planning_command);
57 });
58
59 lane_follow_command_client_ =
61 task_manager_conf.topic_config().lane_follow_command_topic());
62 return true;
63}
64
65bool TaskManagerComponent::Proc(const std::shared_ptr<Task>& task) {
66 if (task->task_type() != CYCLE_ROUTING) {
67 AERROR << "Task type is not cycle_routing.";
68 return false;
69 }
70
71 if (task->task_type() == CYCLE_ROUTING) {
72 cycle_routing_manager_ = std::make_shared<CycleRoutingManager>();
73 cycle_routing_manager_->Init(localization_.pose(), task->cycle_routing_task());
74 lane_follow_command_ = task->cycle_routing_task().lane_follow_command();
75 Rate rate(1.0);
76
77 while (cycle_routing_manager_->GetCycle() > 0) {
78 if (cycle_routing_manager_->GetNewRouting(localization_.pose(),
79 &lane_follow_command_)) {
80 auto last_planning_command_ = planning_command_;
81 common::util::FillHeader(node_->Name(), &lane_follow_command_);
82 auto lane_follow_command = std::make_shared<LaneFollowCommand>();
83 lane_follow_command->CopyFrom(lane_follow_command_);
84 lane_follow_command_client_->SendRequest(lane_follow_command);
85 AINFO << "[TaskManagerComponent]Reach begin/end point: "
86 << "routing manager send a routing request. ";
87 rate.Sleep();
88
89 if (!planning_command_.has_header()) {
90 AINFO << "[TaskManagerComponent]routing failed";
91 return false;
92 }
93 if (last_planning_command_.has_header()) {
94 if (last_planning_command_.header().sequence_num() ==
95 planning_command_.header().sequence_num()) {
96 AINFO << "[TaskManagerComponent]No routing response: "
97 << "new routing failed";
98 return false;
99 }
100 }
101 }
102 rate.Sleep();
103 }
104 }
105 return true;
106}
107
108} // namespace task_manager
109} // namespace apollo
bool GetProtoConfig(T *config) const
const std::string & ConfigFilePath() const
std::shared_ptr< Node > node_
bool Proc(const std::shared_ptr< task_manager::Task > &task) override
#define ACHECK(cond)
Definition log.h:80
#define ADEBUG
Definition log.h:41
#define AERROR
Definition log.h:44
#define AINFO
Definition log.h:42
class register implement
Definition arena_queue.h:37
optional uint32 sequence_num
Definition header.proto:16
optional apollo::localization::Pose pose
optional apollo::common::Header header