Apollo 10.0
自动驾驶开放平台
apollo::control::ControlTestBase类 参考

#include <control_test_base.h>

类 apollo::control::ControlTestBase 继承关系图:
apollo::control::ControlTestBase 的协作图:

Public 成员函数

virtual void SetUp ()
 
bool test_control ()
 
bool test_control (const std::string &test_case_name, int case_num)
 
void LoadControllerPlugin ()
 

静态 Public 成员函数

static void SetUpTestCase ()
 

详细描述

在文件 control_test_base.h50 行定义.

成员函数说明

◆ LoadControllerPlugin()

void apollo::control::ControlTestBase::LoadControllerPlugin ( )

在文件 control_test_base.cc202 行定义.

202 {
203 std::string apollo_root_dir_str = "/apollo";
204 // const char* apollo_root_dir = std::getenv("APOLLO_ROOT_DIR");
205 // if (apollo_root_dir != nullptr) {
206 // apollo_root_dir_str = std::string(apollo_root_dir);
207 // }
208 std::string plugin_lib_path =
209 "APOLLO_PLUGIN_LIB_PATH=" + apollo_root_dir_str +
210 "/bazel-bin:/opt/apollo/neo/lib";
211 std::cout << "plugin_lib_path:" << plugin_lib_path << std::endl;
212 char lib_path_chars[100];
213 memcpy(lib_path_chars, plugin_lib_path.c_str(), plugin_lib_path.size());
214 lib_path_chars[plugin_lib_path.size()] = '\0';
215 std::cout << "lib_path_chars:" << lib_path_chars << std::endl;
216 putenv(lib_path_chars);
217 std::string lat_controller_plugin_xml_file =
218 "modules/control/control_component/testdata/conf/plugins/"
219 "lat_based_lqr_controller/plugins.xml";
220 std::string lon_controller_plugin_xml_file =
221 "modules/control/control_component/testdata/conf/plugins/"
222 "lon_based_pid_controller/plugins.xml";
224 lat_controller_plugin_xml_file);
226 lon_controller_plugin_xml_file);
227}
static PluginManager * Instance()
get singleton instance of PluginManager
bool LoadPlugin(const std::string &plugin_description_file_path)
load plugin clases from file

◆ SetUp()

void apollo::control::ControlTestBase::SetUp ( )
virtual

在文件 control_test_base.cc237 行定义.

237{ ++s_seq_num_; }

◆ SetUpTestCase()

void apollo::control::ControlTestBase::SetUpTestCase ( )
static

在文件 control_test_base.cc229 行定义.

229 {
230 FLAGS_pipeline_file =
231 "modules/control/control_component/testdata/conf/pipeline.pb.txt";
232 FLAGS_is_control_test_mode = true;
233 FLAGS_is_control_ut_test_mode = true;
234 FLAGS_v = 3;
235}

◆ test_control() [1/2]

bool apollo::control::ControlTestBase::test_control ( )

在文件 control_test_base.cc48 行定义.

48 {
49 if (!cyber::common::GetProtoFromFile(FLAGS_pipeline_file,
50 &control_.control_pipeline_)) {
51 AERROR << "Unable to load control conf file: " << FLAGS_pipeline_file;
52 exit(EXIT_FAILURE);
53 }
54
55 AINFO << "Pipeline file: " << FLAGS_pipeline_file << " is loaded.";
56
57 // set controller
58 control_.injector_ = std::make_shared<DependencyInjector>();
59
60 if (!control_.control_task_agent_
61 .Init(control_.injector_, control_.control_pipeline_)
62 .ok()) {
63 AERROR << "Control init controller failed! Stopping...";
64 exit(EXIT_FAILURE);
65 }
66 control_.control_task_agent_.Reset();
67
68 // Pad message
69 if (!FLAGS_test_pad_file.empty()) {
70 AINFO << "Into the pad load file.";
71 PadMessage pad_message;
73 FLAGS_test_data_dir + FLAGS_test_pad_file, &pad_message)) {
74 AERROR << "Failed to load PadMesssage from file " << FLAGS_test_data_dir
75 << FLAGS_test_pad_file;
76 return false;
77 }
78 control_.OnPad(std::make_shared<apollo::control::PadMessage>(pad_message));
79 }
80
81 // Localization
82 if (!FLAGS_test_localization_file.empty()) {
83 AINFO << "Into the localization load file.";
84 LocalizationEstimate localization;
86 FLAGS_test_data_dir + FLAGS_test_localization_file,
87 &localization)) {
88 AERROR << "Failed to load localization file " << FLAGS_test_data_dir
89 << FLAGS_test_localization_file;
90 return false;
91 }
92 control_.OnLocalization(
93 std::make_shared<apollo::localization::LocalizationEstimate>(
94 localization));
95 }
96
97 // Planning
98 if (!FLAGS_test_planning_file.empty()) {
99 AINFO << "Into the planning load file.";
100 ADCTrajectory trajectory;
102 FLAGS_test_data_dir + FLAGS_test_planning_file, &trajectory)) {
103 AERROR << "Failed to load planning file " << FLAGS_test_data_dir
104 << FLAGS_test_planning_file;
105 return false;
106 }
107 control_.OnPlanning(
108 std::make_shared<apollo::planning::ADCTrajectory>(trajectory));
109 }
110
111 // Chassis
112 if (!FLAGS_test_chassis_file.empty()) {
113 AINFO << "Into the chassis load file.";
114 Chassis chassis;
116 FLAGS_test_data_dir + FLAGS_test_chassis_file, &chassis)) {
117 AERROR << "Failed to load chassis file " << FLAGS_test_data_dir
118 << FLAGS_test_chassis_file;
119 return false;
120 }
121 control_.OnChassis(std::make_shared<apollo::canbus::Chassis>(chassis));
122 }
123
124 // Monitor
125 if (!FLAGS_test_monitor_file.empty()) {
126 AINFO << "Into the monitor load file.";
127 MonitorMessage monitor_message;
129 FLAGS_test_data_dir + FLAGS_test_monitor_file, &monitor_message)) {
130 AERROR << "Failed to load monitor file " << FLAGS_test_data_dir
131 << FLAGS_test_monitor_file;
132 return false;
133 }
134 control_.OnMonitor(monitor_message);
135 }
136
137 control_.local_view_.mutable_chassis()->CopyFrom(control_.latest_chassis_);
138 control_.local_view_.mutable_trajectory()->CopyFrom(
139 control_.latest_trajectory_);
140 control_.local_view_.mutable_localization()->CopyFrom(
141 control_.latest_localization_);
142
143 auto err = control_.ProduceControlCommand(&control_command_);
144 if (!err.ok()) {
145 ADEBUG << "control ProduceControlCommand failed";
146 return false;
147 }
148 AINFO << "Finish the test_control().";
149 return true;
150}
bool ok() const
check whether the return status is OK.
Definition status.h:67
common::Status Reset()
reset ControlTaskAgent
common::Status Init(std::shared_ptr< DependencyInjector > injector, const ControlPipeline &control_pipeline)
initialize ControlTaskAgent
#define ADEBUG
Definition log.h:41
#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

◆ test_control() [2/2]

bool apollo::control::ControlTestBase::test_control ( const std::string &  test_case_name,
int  case_num 
)

在文件 control_test_base.cc159 行定义.

160 {
161 const std::string golden_result_file =
162 absl::StrCat("result_", test_case_name, "_", case_num, ".pb.txt");
163 std::string tmp_golden_path = "/tmp/" + golden_result_file;
164 std::string full_golden_path = FLAGS_test_data_dir + golden_result_file;
166 control_command_.Clear();
167
168 if (!test_control()) {
169 AERROR << "test control failed";
170 return false;
171 }
172
173 trim_control_command(&control_command_);
174 if (FLAGS_test_update_golden_log) {
175 AINFO << "The golden file is " << tmp_golden_path << " Remember to:\n"
176 << "mv " << tmp_golden_path << " " << FLAGS_test_data_dir << "\n"
177 << "git add " << FLAGS_test_data_dir << "/" << golden_result_file;
178 cyber::common::SetProtoToASCIIFile(control_command_, golden_result_file);
179 } else {
180 ControlCommand golden_result;
181 bool load_success =
182 cyber::common::GetProtoFromASCIIFile(full_golden_path, &golden_result);
183 if (!load_success) {
184 AERROR << "Failed to load golden file: " << full_golden_path;
185 cyber::common::SetProtoToASCIIFile(control_command_, tmp_golden_path);
186 AINFO << "Current result is written to " << tmp_golden_path;
187 return false;
188 }
189 bool same_result =
190 common::util::IsProtoEqual(golden_result, control_command_);
191 if (!same_result) {
192 std::string tmp_test_result_file = tmp_golden_path + ".tmp";
193 cyber::common::SetProtoToASCIIFile(control_command_,
194 tmp_test_result_file);
195 AERROR << "found diff " << tmp_test_result_file << " "
196 << full_golden_path;
197 }
198 }
199 return true;
200}
bool IsProtoEqual(const ProtoA &a, const ProtoB &b)
Definition util.h:47
bool GetProtoFromASCIIFile(const std::string &file_name, google::protobuf::Message *message)
Parses the content of the file specified by the file_name as ascii representation of protobufs,...
Definition file.cc:89
bool SetProtoToASCIIFile(const google::protobuf::Message &message, int file_descriptor)
Definition file.cc:43

该类的文档由以下文件生成: