The Proc logic of the component, which called by the CyberRT frame.
324 {
325 AINFO <<
"control proc start.";
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
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
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
388 if (FLAGS_use_control_submodules) {
389 local_view_.mutable_header()->set_lidar_timestamp(
391 local_view_.mutable_header()->set_camera_timestamp(
393 local_view_.mutable_header()->set_radar_timestamp(
395 common::util::FillHeader(FLAGS_control_local_view_topic, &local_view_);
396
398
399
401 FLAGS_control_local_view_topic);
402 latency_recorder.AppendLatencyRecord(
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";
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
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
456 if (estop_) {
457 control_command.mutable_header()->mutable_status()->set_msg(estop_reason_);
458 }
459
460
461 control_command.mutable_header()->set_lidar_timestamp(
463 control_command.mutable_header()->set_camera_timestamp(
465 control_command.mutable_header()->set_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(),
477 GetVehiclePitchAngle(&control_command);
478 }
479
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
495 FLAGS_control_command_topic);
496 latency_recorder.AppendLatencyRecord(
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(
505 }
506 ADEBUG << control_command.ShortDebugString();
507
508 control_cmd_writer_->Write(control_command);
509
510
511 injector_->Set_pervious_control_command(&control_command);
512 injector_->previous_control_command_mutable()->CopyFrom(control_command);
513
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}
const double kDoubleEpsilon
optional apollo::common::Header header
optional DrivingMode driving_mode
optional apollo::planning::ADCTrajectory trajectory
optional apollo::canbus::Chassis chassis
optional apollo::localization::LocalizationEstimate localization
optional DrivingAction action
optional apollo::common::Header header