Apollo 10.0
自动驾驶开放平台
control_task_agent.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2017 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 *****************************************************************************/
16
18
19#include <utility>
20
21#include "cyber/common/log.h"
22#include "cyber/time/clock.h"
24
25namespace apollo {
26namespace control {
27
32
33Status ControlTaskAgent::Init(std::shared_ptr<DependencyInjector> injector,
34 const ControlPipeline &control_pipeline) {
35 if (control_pipeline.controller_size() == 0) {
36 AERROR << "control_pipeline is empty";
37 return Status(ErrorCode::CONTROL_INIT_ERROR, "Empty control_pipeline");
38 }
39
40 injector_ = injector;
41 for (int i = 0; i < control_pipeline.controller_size(); i++) {
43 "apollo::control::" + control_pipeline.controller(i).type());
44 if (!controller->Init(injector_).ok()) {
45 AERROR << "Can not init controller " << controller->Name();
46 return Status(
47 ErrorCode::CONTROL_INIT_ERROR,
48 "Failed to init Controller:" + control_pipeline.controller(i).name());
49 }
50 controller_list_.push_back(controller);
51 AINFO << "Controller <" << controller->Name() << "> init done!";
52 }
53 return Status::OK();
54}
55
57 const localization::LocalizationEstimate *localization,
58 const canbus::Chassis *chassis, const planning::ADCTrajectory *trajectory,
60 for (auto &controller : controller_list_) {
61 ADEBUG << "controller:" << controller->Name() << " processing ...";
62 double start_timestamp = Clock::NowInSeconds();
63 Status controller_status = controller->ComputeControlCommand(
64 localization, chassis, trajectory, cmd);
65 double end_timestamp = Clock::NowInSeconds();
66 const double time_diff_ms = (end_timestamp - start_timestamp) * 1000;
67 ADEBUG << "controller: " << controller->Name()
68 << " calculation time is: " << time_diff_ms << " ms.";
69 cmd->mutable_latency_stats()->add_controller_time_ms(time_diff_ms);
70 if (controller_status != Status::OK()) {
71 return controller_status;
72 }
73 }
74 return Status::OK();
75}
76
78 for (auto &controller : controller_list_) {
79 ADEBUG << "controller:" << controller->Name() << " reset...";
80 controller->Reset();
81 }
82 return Status::OK();
83}
84
85} // namespace control
86} // namespace apollo
A general class to denote the return status of an API call.
Definition status.h:43
static Status OK()
generate a success status.
Definition status.h:60
common::Status Reset()
reset ControlTaskAgent
common::Status Init(std::shared_ptr< DependencyInjector > injector, const ControlPipeline &control_pipeline)
initialize ControlTaskAgent
common::Status ComputeControlCommand(const localization::LocalizationEstimate *localization, const canbus::Chassis *chassis, const planning::ADCTrajectory *trajectory, control::ControlCommand *cmd)
compute control command based on current vehicle status and target trajectory
virtual std::string Name() const =0
controller name
a singleton clock that can be used to get the current timestamp.
Definition clock.h:39
static double NowInSeconds()
gets the current time in second.
Definition clock.cc:56
static PluginManager * Instance()
get singleton instance of PluginManager
std::shared_ptr< Base > CreateInstance(const std::string &derived_class)
create plugin instance of derived class based on Base
Defines the ControlTaskAgent class.
#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
repeated PluginDeclareInfo controller
Definition pipeline.proto:9