Apollo 10.0
自动驾驶开放平台
demo_controller.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2023 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 <string>
20
21#include "modules/common_msgs/basic_msgs/vehicle_signal.pb.h"
22
23#include "cyber/common/log.h"
24#include "cyber/time/time.h"
29
30namespace apollo {
31namespace canbus {
32namespace demo {
33using ::apollo::common::ErrorCode;
34using ::apollo::common::VehicleSignal;
35using ::apollo::control::ControlCommand;
36using ::apollo::drivers::canbus::ProtocolData;
37
38namespace {
39const int32_t kMaxFailAttempt = 10;
40const int32_t CHECK_RESPONSE_STEER_UNIT_FLAG = 1;
41const int32_t CHECK_RESPONSE_SPEED_UNIT_FLAG = 2;
42
43} // namespace
44
46 can_sender_->AddMessage(Brakecommand101::ID, brake_command_101_, false);
47 can_sender_->AddMessage(Gearcommand103::ID, gear_command_103_, false);
48 can_sender_->AddMessage(Parkcommand104::ID, park_command_104_, false);
49 can_sender_->AddMessage(Steeringcommand102::ID, steering_command_102_, false);
50 can_sender_->AddMessage(Throttlecommand100::ID, throttle_command_100_, false);
51 can_sender_->AddMessage(Vehiclemodecommand105::ID, vehicle_mode_command_105_,
52 false);
53}
54
56 const VehicleParameter& params,
57 CanSender<::apollo::canbus::Demo>* const can_sender,
58 MessageManager<::apollo::canbus::Demo>* const message_manager) {
59 if (is_initialized_) {
60 AINFO << "DemoController has already been initiated.";
61 return ErrorCode::CANBUS_ERROR;
62 }
63
64 vehicle_params_.CopyFrom(
65 common::VehicleConfigHelper::Instance()->GetConfig().vehicle_param());
66 params_.CopyFrom(params);
67 if (!params_.has_driving_mode()) {
68 AERROR << "Vehicle conf pb not set driving_mode.";
69 return ErrorCode::CANBUS_ERROR;
70 }
71
72 if (can_sender == nullptr) {
73 AERROR << "Canbus sender is null.";
74 return ErrorCode::CANBUS_ERROR;
75 }
76 can_sender_ = can_sender;
77
78 if (message_manager == nullptr) {
79 AERROR << "protocol manager is null.";
80 return ErrorCode::CANBUS_ERROR;
81 }
82 message_manager_ = message_manager;
83
84 // sender part
85 brake_command_101_ = dynamic_cast<Brakecommand101*>(
86 message_manager_->GetMutableProtocolDataById(Brakecommand101::ID));
87 if (brake_command_101_ == nullptr) {
88 AERROR << "Brakecommand101 does not exist in the DemoMessageManager!";
89 return ErrorCode::CANBUS_ERROR;
90 }
91
92 gear_command_103_ = dynamic_cast<Gearcommand103*>(
93 message_manager_->GetMutableProtocolDataById(Gearcommand103::ID));
94 if (gear_command_103_ == nullptr) {
95 AERROR << "Gearcommand103 does not exist in the DemoMessageManager!";
96 return ErrorCode::CANBUS_ERROR;
97 }
98
99 park_command_104_ = dynamic_cast<Parkcommand104*>(
100 message_manager_->GetMutableProtocolDataById(Parkcommand104::ID));
101 if (park_command_104_ == nullptr) {
102 AERROR << "Parkcommand104 does not exist in the DemoMessageManager!";
103 return ErrorCode::CANBUS_ERROR;
104 }
105
106 steering_command_102_ = dynamic_cast<Steeringcommand102*>(
107 message_manager_->GetMutableProtocolDataById(Steeringcommand102::ID));
108 if (steering_command_102_ == nullptr) {
109 AERROR << "Steeringcommand102 does not exist in the DemoMessageManager!";
110 return ErrorCode::CANBUS_ERROR;
111 }
112
113 throttle_command_100_ = dynamic_cast<Throttlecommand100*>(
114 message_manager_->GetMutableProtocolDataById(Throttlecommand100::ID));
115 if (throttle_command_100_ == nullptr) {
116 AERROR << "Throttlecommand100 does not exist in the DemoMessageManager!";
117 return ErrorCode::CANBUS_ERROR;
118 }
119
120 vehicle_mode_command_105_ = dynamic_cast<Vehiclemodecommand105*>(
121 message_manager_->GetMutableProtocolDataById(Vehiclemodecommand105::ID));
122 if (vehicle_mode_command_105_ == nullptr) {
123 AERROR << "Vehiclemodecommand105 does not exist in the DemoMessageManager!";
124 return ErrorCode::CANBUS_ERROR;
125 }
126
128
129 AINFO << "DemoController is initialized.";
130
131 is_initialized_ = true;
132 return ErrorCode::OK;
133}
134
136
138 if (!is_initialized_) {
139 AERROR << "DemoController has NOT been initiated.";
140 return false;
141 }
142 const auto& update_func = [this] { SecurityDogThreadFunc(); };
143 thread_.reset(new std::thread(update_func));
144
145 return true;
146}
147
149 if (!is_initialized_) {
150 AERROR << "DemoController stops or starts improperly!";
151 return;
152 }
153
154 if (thread_ != nullptr && thread_->joinable()) {
155 thread_->join();
156 thread_.reset();
157 AINFO << "DemoController stopped.";
158 }
159}
160
162 chassis_.Clear();
163 Demo chassis_detail = GetNewRecvChassisDetail();
164
165 // 1, 2
166 // if (driving_mode() == Chassis::EMERGENCY_MODE) {
167 // set_chassis_error_code(Chassis::NO_ERROR);
168 // }
169 chassis_.set_driving_mode(driving_mode());
170 chassis_.set_error_code(chassis_error_code());
171
172 // 3
173 chassis_.set_engine_started(true);
174
175 // 4 chassis spd
176 if (chassis_detail.has_vcu_report_505() &&
177 chassis_detail.vcu_report_505().has_speed()) {
178 chassis_.set_speed_mps(
179 static_cast<float>(chassis_detail.vcu_report_505().speed()));
180 } else {
181 chassis_.set_speed_mps(0);
182 }
183
184 // 5 throttle
185 if (chassis_detail.has_throttle_report_500() &&
186 chassis_detail.throttle_report_500().has_throttle_pedal_actual()) {
187 chassis_.set_throttle_percentage(static_cast<float>(
188 chassis_detail.throttle_report_500().throttle_pedal_actual()));
189 } else {
190 chassis_.set_throttle_percentage(0);
191 }
192
193 // 6 brake
194 if (chassis_detail.has_brake_report_501() &&
195 chassis_detail.brake_report_501().has_brake_pedal_actual()) {
196 chassis_.set_brake_percentage(static_cast<float>(
197 chassis_detail.brake_report_501().brake_pedal_actual()));
198 } else {
199 chassis_.set_brake_percentage(0);
200 }
201
202 // 7 gear
203 if (chassis_detail.has_gear_report_503() &&
204 chassis_detail.gear_report_503().has_gear_actual()) {
206
207 if (chassis_detail.gear_report_503().gear_actual() ==
209 gear_pos = Chassis::GEAR_NEUTRAL;
210 }
211 if (chassis_detail.gear_report_503().gear_actual() ==
213 gear_pos = Chassis::GEAR_REVERSE;
214 }
215 if (chassis_detail.gear_report_503().gear_actual() ==
217 gear_pos = Chassis::GEAR_DRIVE;
218 }
219 if (chassis_detail.gear_report_503().gear_actual() ==
221 gear_pos = Chassis::GEAR_PARKING;
222 }
223
224 chassis_.set_gear_location(gear_pos);
225 } else {
226 chassis_.set_gear_location(Chassis::GEAR_NONE);
227 }
228
229 // 8 steer
230 if (chassis_detail.has_steering_report_502() &&
231 chassis_detail.steering_report_502().has_steer_angle_actual()) {
232 chassis_.set_steering_percentage(static_cast<float>(
233 chassis_detail.steering_report_502().steer_angle_actual() * 100.0 /
235 } else {
236 chassis_.set_steering_percentage(0);
237 }
238
239 // 9 checkresponse signal
240 // 9 checkresponse signal
241 // 9 checkresponse signal
242 if (chassis_detail.has_brake_report_501() &&
243 chassis_detail.brake_report_501().has_brake_en_state()) {
244 chassis_.mutable_check_response()->set_is_esp_online(
245 chassis_detail.brake_report_501().brake_en_state() == 1);
246 }
247
248 if (chassis_detail.has_steering_report_502() &&
249 chassis_detail.steering_report_502().has_steer_en_state()) {
250 chassis_.mutable_check_response()->set_is_eps_online(
251 chassis_detail.steering_report_502().steer_en_state() == 1);
252 }
253
254 if (chassis_detail.has_throttle_report_500() &&
255 chassis_detail.throttle_report_500().has_throttle_en_state()) {
256 chassis_.mutable_check_response()->set_is_vcu_online(
257 chassis_detail.throttle_report_500().throttle_en_state() == 1);
258 }
259
260 // check chassis error
261 if (CheckChassisError()) {
262 chassis_.mutable_engage_advice()->set_advice(
264 chassis_.mutable_engage_advice()->set_reason(
265 "Chassis has some fault, please check the chassis_detail.");
266 }
267
268 // check the chassis detail lost
270 chassis_.mutable_engage_advice()->set_advice(
272 chassis_.mutable_engage_advice()->set_reason(
273 "demo chassis detail is lost! Please check the communication error.");
274 set_chassis_error_code(Chassis::CHASSIS_CAN_LOST);
276 }
277
278 /* ADD YOUR OWN CAR CHASSIS OPERATION
279 // 14 battery soc
280 // 16 sonor list
281 // 17 set vin
282 // 18,19 bumper event
283 // 20 add checkresponse signal
284 */
285
286 return chassis_;
287}
288
289void DemoController::Emergency() {
291 ResetProtocol();
292}
293
294ErrorCode DemoController::EnableAutoMode() {
296 AINFO << "already in COMPLETE_AUTO_DRIVE mode";
297 return ErrorCode::OK;
298 }
299 // set enable
300 brake_command_101_->set_brake_en_ctrl(
302
304
305 steering_command_102_->set_steer_en_ctrl(
307
308 throttle_command_100_->set_throttle_en_ctrl(
310
311 can_sender_->Update();
312 const int32_t flag =
313 CHECK_RESPONSE_STEER_UNIT_FLAG | CHECK_RESPONSE_SPEED_UNIT_FLAG;
314 if (!CheckResponse(flag, true)) {
315 AERROR << "Failed to switch to COMPLETE_AUTO_DRIVE mode. Please check the "
316 "emergency button or chassis.";
317 Emergency();
318 set_chassis_error_code(Chassis::CHASSIS_ERROR);
319 return ErrorCode::CANBUS_ERROR;
320 }
322 AINFO << "Switch to COMPLETE_AUTO_DRIVE mode ok.";
323 return ErrorCode::OK;
324}
325
326ErrorCode DemoController::DisableAutoMode() {
327 ResetProtocol();
328 can_sender_->Update();
330 set_chassis_error_code(Chassis::NO_ERROR);
331 AINFO << "Switch to COMPLETE_MANUAL ok.";
332 return ErrorCode::OK;
333}
334
335ErrorCode DemoController::EnableSteeringOnlyMode() {
339 AINFO << "Already in AUTO_STEER_ONLY mode.";
340 return ErrorCode::OK;
341 }
342 /* ADD YOUR OWN CAR CHASSIS OPERATION
343 // TODO(ALL): CHECK YOUR VEHICLE WHETHER SUPPORT THIS MODE OR NOT
344 // set enable
345 brake_command_101_->set_brake_en_ctrl(
346 Brake_command_101::BRAKE_EN_CTRL_DISABLE);
347
348 gear_command_103_->set_gear_en_ctrl(
349 Gear_command_103::GEAR_EN_CTRL_DISABLE);
350
351 steering_command_102_->set_steer_en_ctrl(
352 Steering_command_102::STEER_EN_CTRL_ENABLE);
353
354 throttle_command_100_->set_throttle_en_ctrl(
355 Throttle_command_100::THROTTLE_EN_CTRL_DISABLE);
356
357
358 can_sender_->Update();
359 if (!CheckResponse(CHECK_RESPONSE_STEER_UNIT_FLAG, true)) {
360 AERROR << "Failed to switch to AUTO_STEER_ONLY mode.";
361 Emergency();
362 set_chassis_error_code(Chassis::CHASSIS_ERROR);
363 return ErrorCode::CANBUS_ERROR;
364 }
365 set_driving_mode(Chassis::AUTO_STEER_ONLY);
366 AINFO << "Switch to AUTO_STEER_ONLY mode ok.";
367 return ErrorCode::OK;
368 */
369 return ErrorCode::OK;
370}
371
372ErrorCode DemoController::EnableSpeedOnlyMode() {
376 AINFO << "Already in AUTO_SPEED_ONLY mode";
377 return ErrorCode::OK;
378 }
379 /* ADD YOUR OWN CAR CHASSIS OPERATION
380 // TODO(ALL): CHECK YOUR VEHICLE WHETHER SUPPORT THIS MODE OR NOT
381 // set enable
382 brake_command_101_->set_brake_en_ctrl(
383 Brake_command_101::BRAKE_EN_CTRL_ENABLE);
384
385 gear_command_103_->set_gear_en_ctrl(
386 Gear_command_103::GEAR_EN_CTRL_ENABLE);
387
388 steering_command_102_->set_steer_en_ctrl(
389 Steering_command_102::STEER_EN_CTRL_DISABLE);
390
391 throttle_command_100_->set_throttle_en_ctrl(
392 Throttle_command_100::THROTTLE_EN_CTRL_ENABLE);
393
394
395 can_sender_->Update();
396 if (!CheckResponse(CHECK_RESPONSE_SPEED_UNIT_FLAG, true)) {
397 AERROR << "Failed to switch to AUTO_SPEED_ONLY mode.";
398 Emergency();
399 set_chassis_error_code(Chassis::CHASSIS_ERROR);
400 return ErrorCode::CANBUS_ERROR;
401 }
402 set_driving_mode(Chassis::AUTO_SPEED_ONLY);
403 AINFO << "Switch to AUTO_SPEED_ONLY mode ok.";
404 return ErrorCode::OK;
405 */
406 return ErrorCode::OK;
407}
408
409// NEUTRAL, REVERSE, DRIVE
410void DemoController::Gear(Chassis::GearPosition gear_position) {
413 AINFO << "This drive mode no need to set gear.";
414 return;
415 }
416 switch (gear_position) {
419 break;
420 }
423 break;
424 }
425 case Chassis::GEAR_DRIVE: {
427 break;
428 }
431 break;
432 }
435 break;
436 }
437 default: {
439 break;
440 }
441 }
442}
443
444// brake with pedal
445// pedal:0.00~99.99, unit:percentage
446void DemoController::Brake(double pedal) {
447 // double real_value = vehicle_params_.max_acceleration() * acceleration /
448 // 100;
449 // TODO(All) : Update brake value based on mode
452 AINFO << "The current drive mode does not need to set brake pedal.";
453 return;
454 }
455 brake_command_101_->set_brake_pedal_target(pedal);
456}
457
458// drive with pedal
459// pedal:0.0~99.9 unit:percentage
460void DemoController::Throttle(double pedal) {
463 AINFO << "The current drive mode does not need to set throttle pedal.";
464 return;
465 }
466 throttle_command_100_->set_throttle_pedal_target(pedal);
467}
468
469// confirm the car is driven by acceleration command instead of
470// throttle/brake pedal drive with acceleration/deceleration acc:-7.0 ~ 5.0,
471// unit:m/s^2
472void DemoController::Acceleration(double acc) {
475 AINFO << "The current drive mode does not need to set acceleration.";
476 return;
477 }
478 /* ADD YOUR OWN CAR CHASSIS OPERATION
479 // TODO(ALL): CHECK YOUR VEHICLE WHETHER SUPPORT THIS DRIVE MODE
480 */
481}
482
483// confirm the car is driven by speed command
484// speed:-xx.0~xx.0, unit:m/s
485void DemoController::Speed(double speed) {
488 AINFO << "The current drive mode does not need to set speed.";
489 return;
490 }
491 /* ADD YOUR OWN CAR CHASSIS OPERATION
492 // TODO(ALL): CHECK YOUR VEHICLE WHETHER SUPPORT THIS DRIVE MODE
493 */
494}
495
496// demo default, +470 ~ -470 or other, left:+, right:-
497// need to be compatible with control module, so reverse
498// steering with steering angle
499// angle:99.99~0.00~-99.99, unit:deg, left:+, right:-
500void DemoController::Steer(double angle) {
503 AINFO << "The current driving mode does not need to set steer.";
504 return;
505 }
506 const double real_angle =
507 vehicle_params_.max_steer_angle() / M_PI * 180 * angle / 100.0;
508 steering_command_102_->set_steer_angle_target(real_angle);
509}
510
511// demo default, steering with new angle and angle speed
512// angle:99.99~0.00~-99.99, unit:deg, left:+, right:-
513// angle_spd:0.00~99.99, unit:deg/s
514void DemoController::Steer(double angle, double angle_spd) {
517 AINFO << "The current driving mode does not need to set steer.";
518 return;
519 }
520 const double real_angle =
521 vehicle_params_.max_steer_angle() / M_PI * 180 * angle / 100.0;
522 steering_command_102_->set_steer_angle_target(real_angle);
523}
524
525void DemoController::SetEpbBreak(const ControlCommand& command) {
526 if (command.parking_brake()) {
527 // None
528 } else {
529 // None
530 }
531}
532
533void DemoController::SetBeam(const VehicleSignal& vehicle_signal) {
534 if (vehicle_signal.high_beam()) {
535 // None
536 } else if (vehicle_signal.low_beam()) {
537 // None
538 } else {
539 // None
540 }
541}
542
543void DemoController::SetHorn(const VehicleSignal& vehicle_signal) {
544 if (vehicle_signal.horn()) {
545 // None
546 } else {
547 // None
548 }
549}
550
551void DemoController::SetTurningSignal(const VehicleSignal& vehicle_signal) {
552 // Set Turn Signal
553 /* ADD YOUR OWN CAR CHASSIS OPERATION
554 auto signal = vehicle_signal.turn_signal();
555 if (signal == common::VehicleSignal::TURN_LEFT) {
556
557 } else if (signal == common::VehicleSignal::TURN_RIGHT) {
558
559 } else {
560
561 }
562 */
563}
564
565ErrorCode DemoController::HandleCustomOperation(
566 const external_command::ChassisCommand& command) {
567 return ErrorCode::OK;
568}
569
570bool DemoController::VerifyID() {
571 if (!CheckVin()) {
572 AERROR << "Failed to get the vin. Get vin again.";
573 GetVin();
574 return false;
575 } else {
576 ResetVin();
577 return true;
578 }
579}
580
581bool DemoController::CheckVin() {
582 /* ADD YOUR OWN CAR CHASSIS OPERATION
583 if (chassis_.vehicle_id().vin().size() >= 7) {
584 AINFO << "Vin check success! Vehicel vin is "
585 << chassis_.vehicle_id().vin();
586 return true;
587 } else {
588 AINFO << "Vin check failed! Current vin size is "
589 << chassis_.vehicle_id().vin().size();
590 return false;
591 }
592 */
593 return false;
594}
595
596void DemoController::GetVin() {
597 // Get vin from vehicle if exist
598 /* ADD YOUR OWN CAR CHASSIS OPERATION
599 vehicle_mode_command_116_->set_vin_req_cmd(
600 Vehicle_mode_command_116::VIN_REQ_CMD_VIN_REQ_ENABLE);
601 AINFO << "Get vin";
602 can_sender_->Update();
603 */
604}
605
606void DemoController::ResetVin() {
607 // Reset vin from vehicle if exist
608 /* ADD YOUR OWN CAR CHASSIS OPERATION
609 vehicle_mode_command_116_->set_vin_req_cmd(
610 Vehicle_mode_command_116::VIN_REQ_CMD_VIN_REQ_DISABLE);
611 AINFO << "Reset vin";
612 can_sender_->Update();
613 */
614}
615
616void DemoController::ResetProtocol() { message_manager_->ResetSendMessages(); }
617
618bool DemoController::CheckChassisError() {
620 AERROR_EVERY(100) << "ChassisDetail has no demo vehicle info.";
621 return false;
622 }
623
624 /* ADD YOUR OWN CAR CHASSIS OPERATION
625 // steer fault
626 // drive fault
627 // brake fault
628 */
629 return false;
630}
631
632void DemoController::SecurityDogThreadFunc() {
633 int32_t vertical_ctrl_fail = 0;
634 int32_t horizontal_ctrl_fail = 0;
635
636 if (can_sender_ == nullptr) {
637 AERROR << "Failed to run SecurityDogThreadFunc() because can_sender_ is "
638 "nullptr.";
639 return;
640 }
641 while (!can_sender_->IsRunning()) {
642 std::this_thread::yield();
643 }
644
645 std::chrono::duration<double, std::micro> default_period{50000};
646 int64_t start = 0;
647 int64_t end = 0;
648 while (can_sender_->IsRunning()) {
650 const Chassis::DrivingMode mode = driving_mode();
651 bool emergency_mode = false;
652
653 // 1. horizontal control check
654 if ((mode == Chassis::COMPLETE_AUTO_DRIVE ||
655 mode == Chassis::AUTO_STEER_ONLY) &&
656 !CheckResponse(CHECK_RESPONSE_STEER_UNIT_FLAG, false)) {
657 ++horizontal_ctrl_fail;
658 if (horizontal_ctrl_fail >= kMaxFailAttempt) {
659 emergency_mode = true;
660 AERROR << "Driving_mode is into emergency by steer manual intervention";
661 set_chassis_error_code(Chassis::MANUAL_INTERVENTION);
662 }
663 } else {
664 horizontal_ctrl_fail = 0;
665 }
666
667 // 2. vertical control check
668 if ((mode == Chassis::COMPLETE_AUTO_DRIVE ||
669 mode == Chassis::AUTO_SPEED_ONLY) &&
670 !CheckResponse(CHECK_RESPONSE_SPEED_UNIT_FLAG, false)) {
671 ++vertical_ctrl_fail;
672 if (vertical_ctrl_fail >= kMaxFailAttempt) {
673 emergency_mode = true;
674 AERROR << "Driving_mode is into emergency by speed manual intervention";
675 set_chassis_error_code(Chassis::MANUAL_INTERVENTION);
676 }
677 } else {
678 vertical_ctrl_fail = 0;
679 }
680
681 // 3. chassis fault check
682 if (CheckChassisError()) {
683 set_chassis_error_code(Chassis::CHASSIS_ERROR);
684 emergency_mode = true;
685 }
686
687 // process emergency_mode
688 if (emergency_mode && mode != Chassis::EMERGENCY_MODE) {
690 message_manager_->ResetSendMessages();
691 can_sender_->Update();
692 }
693
694 // recove error code
695 if (!emergency_mode && !is_chassis_communication_error_ &&
696 mode == Chassis::EMERGENCY_MODE) {
697 set_chassis_error_code(Chassis::NO_ERROR);
698 }
699
701 std::chrono::duration<double, std::micro> elapsed{end - start};
702 if (elapsed < default_period) {
703 std::this_thread::sleep_for(default_period - elapsed);
704 } else {
705 AERROR << "Too much time consumption in DemoController looping process:"
706 << elapsed.count();
707 }
708 }
709}
710
711bool DemoController::CheckResponse(const int32_t flags, bool need_wait) {
712 int32_t retry_num = 20;
713 bool is_eps_online = false;
714 bool is_vcu_online = false;
715 bool is_esp_online = false;
716
717 do {
718 bool check_ok = true;
719 if (flags & CHECK_RESPONSE_STEER_UNIT_FLAG) {
720 is_eps_online = chassis_.has_check_response() &&
721 chassis_.check_response().has_is_eps_online() &&
722 chassis_.check_response().is_eps_online();
723 check_ok = check_ok && is_eps_online;
724 }
725
726 if (flags & CHECK_RESPONSE_SPEED_UNIT_FLAG) {
727 is_vcu_online = chassis_.has_check_response() &&
728 chassis_.check_response().has_is_vcu_online() &&
729 chassis_.check_response().is_vcu_online();
730 is_esp_online = chassis_.has_check_response() &&
731 chassis_.check_response().has_is_esp_online() &&
732 chassis_.check_response().is_esp_online();
733 check_ok = check_ok && is_vcu_online && is_esp_online;
734 }
735 if (check_ok) {
736 return true;
737 } else {
738 AINFO << "Need to check response again.";
739 }
740 if (need_wait) {
741 --retry_num;
742 std::this_thread::sleep_for(
743 std::chrono::duration<double, std::milli>(20));
744 }
745 } while (need_wait && retry_num);
746
747 if (flags & CHECK_RESPONSE_STEER_UNIT_FLAG) {
748 AERROR << "steer check_response fail: is_eps_online:" << is_eps_online;
749 }
750
751 if (flags & CHECK_RESPONSE_SPEED_UNIT_FLAG) {
752 AERROR << "speed check_response fail: " << "is_vcu_online:" << is_vcu_online
753 << ", is_esp_online:" << is_esp_online;
754 }
755
756 return false;
757}
758
759void DemoController::set_chassis_error_mask(const int32_t mask) {
760 std::lock_guard<std::mutex> lock(chassis_mask_mutex_);
761 chassis_error_mask_ = mask;
762}
763
764int32_t DemoController::chassis_error_mask() {
765 std::lock_guard<std::mutex> lock(chassis_mask_mutex_);
766 return chassis_error_mask_;
767}
768
769Chassis::ErrorCode DemoController::chassis_error_code() {
770 std::lock_guard<std::mutex> lock(chassis_error_code_mutex_);
771 return chassis_error_code_;
772}
773
774void DemoController::set_chassis_error_code(
775 const Chassis::ErrorCode& error_code) {
776 std::lock_guard<std::mutex> lock(chassis_error_code_mutex_);
777 chassis_error_code_ = error_code;
778}
779
780} // namespace demo
781} // namespace canbus
782} // namespace apollo
Defines SenderMessage class and CanSender class.
virtual void set_driving_mode(const Chassis::DrivingMode &driving_mode)
MessageManager< ::apollo::canbus::Demo > * message_manager_
Brakecommand101 * set_brake_en_ctrl(Brake_command_101::Brake_en_ctrlType brake_en_ctrl)
Brakecommand101 * set_brake_pedal_target(double brake_pedal_target)
::apollo::common::ErrorCode Init(const VehicleParameter &params, CanSender<::apollo::canbus::Demo > *const can_sender, MessageManager<::apollo::canbus::Demo > *const message_manager) override
void AddSendMessage() override
add the sender message.
bool Start() override
start the vehicle controller.
Chassis chassis() override
calculate and return the chassis.
void Stop() override
stop the vehicle controller.
Gearcommand103 * set_gear_en_ctrl(Gear_command_103::Gear_en_ctrlType gear_en_ctrl)
Gearcommand103 * set_gear_target(Gear_command_103::Gear_targetType gear_target)
Steeringcommand102 * set_steer_angle_target(int steer_angle_target)
Steeringcommand102 * set_steer_en_ctrl(Steering_command_102::Steer_en_ctrlType steer_en_ctrl)
Throttlecommand100 * set_throttle_en_ctrl(Throttle_command_100::Throttle_en_ctrlType throttle_en_ctrl)
Throttlecommand100 * set_throttle_pedal_target(double throttle_pedal_target)
uint64_t ToMicrosecond() const
convert time to microsecond (us).
Definition time.cc:85
static Time Now()
get the current time.
Definition time.cc:57
the class of DemoMessageManager
#define AERROR
Definition log.h:44
#define AERROR_EVERY(freq)
Definition log.h:86
#define AINFO
Definition log.h:42
class register implement
Definition arena_queue.h:37
The class of ProtocolData
optional Brake_en_stateType brake_en_state
Definition demo.proto:194
optional double brake_pedal_actual
Definition demo.proto:188
optional CheckResponse check_response
optional Throttle_report_500 throttle_report_500
Definition demo.proto:480
optional Vcu_report_505 vcu_report_505
Definition demo.proto:485
optional Steering_report_502 steering_report_502
Definition demo.proto:482
optional Gear_report_503 gear_report_503
Definition demo.proto:483
optional Brake_report_501 brake_report_501
Definition demo.proto:481
optional Gear_actualType gear_actual
Definition demo.proto:243
optional Steer_en_stateType steer_en_state
Definition demo.proto:222
optional double throttle_pedal_actual
Definition demo.proto:162
optional Throttle_en_stateType throttle_en_state
Definition demo.proto:168
The class of VehicleController