Apollo 10.0
自动驾驶开放平台
control_task.h
浏览该文件的文档.
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
22#pragma once
23
24#include <memory>
25#include <string>
26
27#include <cxxabi.h>
28
29#include "modules/common_msgs/control_msgs/control_cmd.pb.h"
30#include "modules/common_msgs/localization_msgs/localization.pb.h"
31#include "modules/common_msgs/planning_msgs/planning.pb.h"
32#include "modules/control/control_component/proto/calibration_table.pb.h"
33
34#include "cyber/common/file.h"
39
44namespace apollo {
45namespace control {
46
53 public:
57 ControlTask() = default;
58
62 virtual ~ControlTask() = default;
63
69 virtual common::Status Init(std::shared_ptr<DependencyInjector> injector) = 0;
70
81 const localization::LocalizationEstimate *localization,
82 const canbus::Chassis *chassis, const planning::ADCTrajectory *trajectory,
84
89 virtual common::Status Reset() = 0;
90
95 virtual std::string Name() const = 0;
96
100 virtual void Stop() = 0;
101
102 protected:
103 template <typename T>
104 bool LoadConfig(T *config);
105
106 bool LoadCalibrationTable(calibration_table *calibration_table_conf) {
107 std::string calibration_table_path = FLAGS_calibration_table_file;
108
109 if (!apollo::cyber::common::GetProtoFromFile(calibration_table_path,
110 calibration_table_conf)) {
111 AERROR << "Load calibration table failed!";
112 return false;
113 }
114 AINFO << "Load the calibraiton table file successfully, file path: "
115 << calibration_table_path;
116 return true;
117 }
118};
119
120template <typename T>
121bool ControlTask::LoadConfig(T *config) {
122 int status;
123 std::string class_name =
124 abi::__cxa_demangle(typeid(*this).name(), 0, 0, &status);
125 // Generate the default task config path from PluginManager.
126 std::string config_path_ =
128 ->GetPluginConfPath<ControlTask>(class_name,
129 "conf/controller_conf.pb.txt");
130
131 if (!apollo::cyber::common::GetProtoFromFile(config_path_, config)) {
132 AERROR << "Load config of " << class_name << " failed!";
133 return false;
134 }
135 AINFO << "Load the [" << class_name
136 << "] config file successfully, file path: " << config_path_;
137 return true;
138}
139
140} // namespace control
141} // namespace apollo
A general class to denote the return status of an API call.
Definition status.h:43
virtual common::Status ComputeControlCommand(const localization::LocalizationEstimate *localization, const canbus::Chassis *chassis, const planning::ADCTrajectory *trajectory, control::ControlCommand *cmd)=0
compute control command based on current vehicle status and target trajectory
virtual std::string Name() const =0
controller name
virtual common::Status Init(std::shared_ptr< DependencyInjector > injector)=0
initialize Controller
virtual void Stop()=0
stop controller
virtual common::Status Reset()=0
reset Controller
virtual ~ControlTask()=default
destructor
bool LoadCalibrationTable(calibration_table *calibration_table_conf)
ControlTask()=default
constructor
std::string GetPluginConfPath(const std::string &class_name, const std::string &conf_name)
get plugin configuration file location
static PluginManager * Instance()
get singleton instance of PluginManager
#define AERROR
Definition log.h:44
#define AINFO
Definition log.h:42
bool GetProtoFromFile(const std::string &file_name, google::protobuf::Message *message)
Parses the content of the file specified by the file_name as a representation of protobufs,...
Definition file.cc:132
class register implement
Definition arena_queue.h:37