Apollo 11.0
自动驾驶开放平台
apollo::control::ControlComponent类 参考final

#include <control_component.h>

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

Public 成员函数

 ControlComponent ()
 
bool Init () override
 
bool Proc () override
 The Proc logic of the component, which called by the CyberRT frame.
 
- Public 成员函数 继承自 apollo::cyber::TimerComponent
 TimerComponent ()
 
 ~TimerComponent () override
 
bool Initialize (const TimerComponentConfig &config) override
 init the component by protobuf object.
 
void Clear () override
 
bool Process ()
 
uint32_t GetInterval () const
 
- Public 成员函数 继承自 apollo::cyber::ComponentBase
virtual ~ComponentBase ()
 
virtual bool Initialize (const ComponentConfig &config)
 
virtual void Shutdown ()
 
template<typename T >
bool GetProtoConfig (T *config) const
 

友元

class ControlTestBase
 

额外继承的成员函数

- Public 类型 继承自 apollo::cyber::ComponentBase
template<typename M >
using Reader = cyber::Reader< M >
 
- Protected 成员函数 继承自 apollo::cyber::ComponentBase
const std::string & ConfigFilePath () const
 
void LoadConfigFiles (const ComponentConfig &config)
 
void LoadConfigFiles (const TimerComponentConfig &config)
 
- Protected 属性 继承自 apollo::cyber::ComponentBase
std::atomic< bool > is_shutdown_ = {false}
 
std::shared_ptr< Node > node_ = nullptr
 
std::string config_file_path_ = ""
 
std::vector< std::shared_ptr< ReaderBase > > readers_
 

详细描述

在文件 control_component.h 第 53 行定义.

构造及析构函数说明

◆ ControlComponent()

apollo::control::ControlComponent::ControlComponent ( )

成员函数说明

◆ Init()

bool apollo::control::ControlComponent::Init ( )
overridevirtual

实现了 apollo::cyber::ComponentBase.

在文件 control_component.cc 第 43 行定义.

43 {
44 injector_ = std::make_shared<DependencyInjector>();
45 init_time_ = Clock::Now();
46
47 AINFO << "Control init, starting ...";
48
49 ACHECK(
50 cyber::common::GetProtoFromFile(FLAGS_pipeline_file, &control_pipeline_))
51 << "Unable to load control pipeline file: " + FLAGS_pipeline_file;
52
53 AINFO << "ControlTask pipeline config file: " << FLAGS_pipeline_file
54 << " is loaded.";
55
56 // initial controller agent when not using control submodules
57 ADEBUG << "FLAGS_use_control_submodules: " << FLAGS_use_control_submodules;
58 if (!FLAGS_is_control_ut_test_mode) {
59 if (!FLAGS_use_control_submodules &&
60 !control_task_agent_.Init(injector_, control_pipeline_).ok()) {
61 // set controller
62 ADEBUG << "original control";
63 monitor_logger_buffer_.ERROR(
64 "Control init controller failed! Stopping...");
65 return false;
66 }
67 }
68
69 cyber::ReaderConfig chassis_reader_config;
70 chassis_reader_config.channel_name = FLAGS_chassis_topic;
71 chassis_reader_config.pending_queue_size = FLAGS_chassis_pending_queue_size;
72
73 chassis_reader_ =
74 node_->CreateReader<Chassis>(chassis_reader_config, nullptr);
75 ACHECK(chassis_reader_ != nullptr);
76
77 cyber::ReaderConfig planning_reader_config;
78 planning_reader_config.channel_name = FLAGS_planning_trajectory_topic;
79 planning_reader_config.pending_queue_size = FLAGS_planning_pending_queue_size;
80
81 trajectory_reader_ =
82 node_->CreateReader<ADCTrajectory>(planning_reader_config, nullptr);
83 ACHECK(trajectory_reader_ != nullptr);
84
85 cyber::ReaderConfig planning_command_status_reader_config;
86 planning_command_status_reader_config.channel_name =
87 FLAGS_planning_command_status;
88 planning_command_status_reader_config.pending_queue_size =
89 FLAGS_planning_status_msg_pending_queue_size;
90 planning_command_status_reader_ =
91 node_->CreateReader<external_command::CommandStatus>(
92 planning_command_status_reader_config, nullptr);
93 ACHECK(planning_command_status_reader_ != nullptr);
94
95 cyber::ReaderConfig localization_reader_config;
96 localization_reader_config.channel_name = FLAGS_localization_topic;
97 localization_reader_config.pending_queue_size =
98 FLAGS_localization_pending_queue_size;
99
100 localization_reader_ = node_->CreateReader<LocalizationEstimate>(
101 localization_reader_config, nullptr);
102 ACHECK(localization_reader_ != nullptr);
103
104 cyber::ReaderConfig pad_msg_reader_config;
105 pad_msg_reader_config.channel_name = FLAGS_pad_topic;
106 pad_msg_reader_config.pending_queue_size = FLAGS_pad_msg_pending_queue_size;
107
108 pad_msg_reader_ =
109 node_->CreateReader<PadMessage>(pad_msg_reader_config, nullptr);
110 ACHECK(pad_msg_reader_ != nullptr);
111
112 if (!FLAGS_use_control_submodules) {
113 control_cmd_writer_ =
114 node_->CreateWriter<ControlCommand>(FLAGS_control_command_topic);
115 ACHECK(control_cmd_writer_ != nullptr);
116 } else {
117 local_view_writer_ =
118 node_->CreateWriter<LocalView>(FLAGS_control_local_view_topic);
119 ACHECK(local_view_writer_ != nullptr);
120 }
121 control_interactive_writer_ = node_->CreateWriter<ControlInteractiveMsg>(
122 FLAGS_control_interative_topic);
123 ACHECK(control_interactive_writer_ != nullptr);
124
125 // set initial vehicle state by cmd
126 // need to sleep, because advertised channel is not ready immediately
127 // simple test shows a short delay of 80 ms or so
128 AINFO << "Control resetting vehicle state, sleeping for 1000 ms ...";
129 std::this_thread::sleep_for(std::chrono::milliseconds(1000));
130
131 // should init_vehicle first, let car enter work status, then use status msg
132 // trigger control
133
134 AINFO << "Control default driving action is "
135 << DrivingAction_Name((enum DrivingAction)FLAGS_action);
136 pad_msg_.set_action((enum DrivingAction)FLAGS_action);
137
138 return true;
139}
bool ok() const
check whether the return status is OK.
Definition status.h:67
common::Status Init(std::shared_ptr< DependencyInjector > injector, const ControlPipeline &control_pipeline)
initialize ControlTaskAgent
static Time Now()
PRECISION >= 1000000 means the precision is at least 1us.
Definition clock.cc:40
std::shared_ptr< Node > node_
#define ACHECK(cond)
Definition log.h:80
#define ADEBUG
Definition log.h:41
#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

◆ Proc()

bool apollo::control::ControlComponent::Proc ( )
overridevirtual

The Proc logic of the component, which called by the CyberRT frame.

返回
returns true if successful, otherwise returns false

实现了 apollo::cyber::TimerComponent.

在文件 control_component.cc 第 324 行定义.

324 {
325 AINFO << "control proc start.";
326 const auto start_time = Clock::Now();
327
328 injector_->control_debug_info_clear();
329
330 chassis_reader_->Observe();
331 const auto &chassis_msg = chassis_reader_->GetLatestObserved();
332 if (chassis_msg == nullptr) {
333 AERROR << "Chassis msg is not ready!";
334 injector_->set_control_process(false);
335 return false;
336 }
337 OnChassis(chassis_msg);
338
339 trajectory_reader_->Observe();
340 const auto &trajectory_msg = trajectory_reader_->GetLatestObserved();
341 if (trajectory_msg == nullptr) {
342 AERROR << "planning msg is not ready!";
343 } else {
344 // Check if new planning data received.
345 if (latest_trajectory_.header().sequence_num() !=
346 trajectory_msg->header().sequence_num()) {
347 OnPlanning(trajectory_msg);
348 }
349 }
350
351 planning_command_status_reader_->Observe();
352 const auto &planning_status_msg =
353 planning_command_status_reader_->GetLatestObserved();
354 if (planning_status_msg != nullptr) {
355 OnPlanningCommandStatus(planning_status_msg);
356 ADEBUG << "Planning command status msg is \n"
357 << planning_command_status_.ShortDebugString();
358 }
359 injector_->set_planning_command_status(planning_command_status_);
360
361 localization_reader_->Observe();
362 const auto &localization_msg = localization_reader_->GetLatestObserved();
363 if (localization_msg == nullptr) {
364 AERROR << "localization msg is not ready!";
365 injector_->set_control_process(false);
366 return false;
367 }
368 OnLocalization(localization_msg);
369
370 pad_msg_reader_->Observe();
371 const auto &pad_msg = pad_msg_reader_->GetLatestObserved();
372 if (pad_msg != nullptr) {
373 OnPad(pad_msg);
374 }
375
376 {
377 // TODO(SHU): to avoid redundent copy
378 std::lock_guard<std::mutex> lock(mutex_);
379 local_view_.mutable_chassis()->CopyFrom(latest_chassis_);
380 local_view_.mutable_trajectory()->CopyFrom(latest_trajectory_);
381 local_view_.mutable_localization()->CopyFrom(latest_localization_);
382 if (pad_msg != nullptr) {
383 local_view_.mutable_pad_msg()->CopyFrom(pad_msg_);
384 }
385 }
386
387 // use control submodules
388 if (FLAGS_use_control_submodules) {
389 local_view_.mutable_header()->set_lidar_timestamp(
390 local_view_.trajectory().header().lidar_timestamp());
391 local_view_.mutable_header()->set_camera_timestamp(
392 local_view_.trajectory().header().camera_timestamp());
393 local_view_.mutable_header()->set_radar_timestamp(
394 local_view_.trajectory().header().radar_timestamp());
395 common::util::FillHeader(FLAGS_control_local_view_topic, &local_view_);
396
397 const auto end_time = Clock::Now();
398
399 // measure latency
400 static apollo::common::LatencyRecorder latency_recorder(
401 FLAGS_control_local_view_topic);
402 latency_recorder.AppendLatencyRecord(
403 local_view_.trajectory().header().lidar_timestamp(), start_time,
404 end_time);
405
406 local_view_writer_->Write(local_view_);
407 return true;
408 }
409
410 if (pad_msg != nullptr) {
411 ADEBUG << "pad_msg: " << pad_msg_.ShortDebugString();
412 ADEBUG << "pad_msg is not nullptr";
413 if (pad_msg_.action() == DrivingAction::RESET) {
414 AINFO << "Control received RESET action!";
415 estop_ = false;
416 estop_reason_.clear();
417 }
418 pad_received_ = true;
419 }
420
421 if (FLAGS_is_control_test_mode && FLAGS_control_test_duration > 0 &&
422 (start_time - init_time_).ToSecond() > FLAGS_control_test_duration) {
423 AERROR << "Control finished testing. exit";
424 injector_->set_control_process(false);
425 return false;
426 }
427
428 injector_->set_control_process(true);
429
430 injector_->mutable_control_debug_info()
431 ->mutable_control_component_debug()
432 ->Clear();
433 CheckAutoMode(&local_view_.chassis());
434
435 ControlCommand control_command;
436
437 Status status;
438 if (local_view_.chassis().driving_mode() ==
440 status = ProduceControlCommand(&control_command);
441 ADEBUG << "Produce control command normal.";
442 } else {
443 ADEBUG << "Into reset control command.";
444 ResetAndProduceZeroControlCommand(&latest_chassis_, &control_command);
445 }
446
447 AERROR_IF(!status.ok()) << "Failed to produce control command:"
448 << status.error_message();
449
450 if (pad_received_) {
451 control_command.mutable_pad_msg()->CopyFrom(pad_msg_);
452 pad_received_ = false;
453 }
454
455 // forward estop reason among following control frames.
456 if (estop_) {
457 control_command.mutable_header()->mutable_status()->set_msg(estop_reason_);
458 }
459
460 // set header
461 control_command.mutable_header()->set_lidar_timestamp(
462 local_view_.trajectory().header().lidar_timestamp());
463 control_command.mutable_header()->set_camera_timestamp(
464 local_view_.trajectory().header().camera_timestamp());
465 control_command.mutable_header()->set_radar_timestamp(
466 local_view_.trajectory().header().radar_timestamp());
467
468 if (FLAGS_is_control_test_mode) {
469 ADEBUG << "Skip publish control command in test mode";
470 return true;
471 }
472
473 if (fabs(control_command.debug().simple_lon_debug().vehicle_pitch()) <
475 injector_->vehicle_state()->Update(local_view_.localization(),
476 local_view_.chassis());
477 GetVehiclePitchAngle(&control_command);
478 }
479
480 const auto end_time = Clock::Now();
481 const double time_diff_ms = (end_time - start_time).ToSecond() * 1e3;
482 ADEBUG << "total control time spend: " << time_diff_ms << " ms.";
483
484 control_command.mutable_latency_stats()->set_total_time_ms(time_diff_ms);
485 control_command.mutable_latency_stats()->set_total_time_exceeded(
486 time_diff_ms > FLAGS_control_period * 1e3);
487 if (control_command.mutable_latency_stats()->total_time_exceeded()) {
488 AINFO << "total control cycle time is exceeded: " << time_diff_ms << " ms.";
489 }
490 status.Save(control_command.mutable_header()->mutable_status());
491
492 // measure latency
493 if (local_view_.trajectory().header().has_lidar_timestamp()) {
494 static apollo::common::LatencyRecorder latency_recorder(
495 FLAGS_control_command_topic);
496 latency_recorder.AppendLatencyRecord(
497 local_view_.trajectory().header().lidar_timestamp(), start_time,
498 end_time);
499 }
500
501 common::util::FillHeader(node_->Name(), &control_command);
502 if (FLAGS_sim_by_record) {
503 control_command.mutable_header()->set_timestamp_sec(
504 latest_chassis_.header().timestamp_sec());
505 }
506 ADEBUG << control_command.ShortDebugString();
507
508 control_cmd_writer_->Write(control_command);
509
510 // save current control command
511 injector_->Set_pervious_control_command(&control_command);
512 injector_->previous_control_command_mutable()->CopyFrom(control_command);
513 // save current control debug
514 injector_->previous_control_debug_mutable()->CopyFrom(
515 injector_->control_debug_info());
516
517 PublishControlInteractiveMsg();
518 const auto end_process_control_time = Clock::Now();
519 const double process_control_time_diff =
520 (end_process_control_time - start_time).ToSecond() * 1e3;
521 if (control_command.mutable_latency_stats()->total_time_exceeded()) {
522 AINFO << "control all spend time is exceeded.";
523 }
524 AINFO << "control proc finished, total time spend: "
525 << process_control_time_diff << " ms.";
526 return true;
527}
#define AERROR
Definition log.h:44
#define AERROR_IF(cond)
Definition log.h:74
const double kDoubleEpsilon
optional apollo::common::Header header
optional DrivingMode driving_mode
optional uint32 sequence_num
Definition header.proto:16
optional double timestamp_sec
Definition header.proto:9
optional uint64 camera_timestamp
Definition header.proto:22
optional uint64 lidar_timestamp
Definition header.proto:19
optional uint64 radar_timestamp
Definition header.proto:25
optional apollo::planning::ADCTrajectory trajectory
optional apollo::canbus::Chassis chassis
optional apollo::localization::LocalizationEstimate localization
optional DrivingAction action
Definition pad_msg.proto:17
optional apollo::common::Header header

友元及相关函数文档

◆ ControlTestBase

friend class ControlTestBase
friend

在文件 control_component.h 第 54 行定义.


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