Apollo 10.0
自动驾驶开放平台
ch_controller.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2019 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 ch {
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 const VehicleParameter& params,
47 CanSender<::apollo::canbus::Ch>* const can_sender,
48 MessageManager<::apollo::canbus::Ch>* const message_manager) {
49 if (is_initialized_) {
50 AINFO << "ChController has already been initiated.";
51 return ErrorCode::CANBUS_ERROR;
52 }
53
54 vehicle_params_.CopyFrom(
55 common::VehicleConfigHelper::Instance()->GetConfig().vehicle_param());
56 params_.CopyFrom(params);
57 if (!params_.has_driving_mode()) {
58 AERROR << "Vehicle conf pb not set driving_mode.";
59 return ErrorCode::CANBUS_ERROR;
60 }
61
62 if (can_sender == nullptr) {
63 AERROR << "Canbus sender is null.";
64 return ErrorCode::CANBUS_ERROR;
65 }
66 can_sender_ = can_sender;
67
68 if (message_manager == nullptr) {
69 AERROR << "protocol manager is null.";
70 return ErrorCode::CANBUS_ERROR;
71 }
72 message_manager_ = message_manager;
73
74 // sender part
75 brake_command_111_ = dynamic_cast<Brakecommand111*>(
76 message_manager_->GetMutableProtocolDataById(Brakecommand111::ID));
77 if (brake_command_111_ == nullptr) {
78 AERROR << "Brakecommand111 does not exist in the ChMessageManager!";
79 return ErrorCode::CANBUS_ERROR;
80 }
81
82 gear_command_114_ = dynamic_cast<Gearcommand114*>(
83 message_manager_->GetMutableProtocolDataById(Gearcommand114::ID));
84 if (gear_command_114_ == nullptr) {
85 AERROR << "Gearcommand114 does not exist in the ChMessageManager!";
86 return ErrorCode::CANBUS_ERROR;
87 }
88
89 steer_command_112_ = dynamic_cast<Steercommand112*>(
90 message_manager_->GetMutableProtocolDataById(Steercommand112::ID));
91 if (steer_command_112_ == nullptr) {
92 AERROR << "Steercommand112 does not exist in the ChMessageManager!";
93 return ErrorCode::CANBUS_ERROR;
94 }
95
96 throttle_command_110_ = dynamic_cast<Throttlecommand110*>(
97 message_manager_->GetMutableProtocolDataById(Throttlecommand110::ID));
98 if (throttle_command_110_ == nullptr) {
99 AERROR << "Throttlecommand110 does not exist in the ChMessageManager!";
100 return ErrorCode::CANBUS_ERROR;
101 }
102
103 turnsignal_command_113_ = dynamic_cast<Turnsignalcommand113*>(
104 message_manager_->GetMutableProtocolDataById(Turnsignalcommand113::ID));
105 if (turnsignal_command_113_ == nullptr) {
106 AERROR << "Turnsignalcommand113 does not exist in the ChMessageManager!";
107 return ErrorCode::CANBUS_ERROR;
108 }
109
110 vehicle_mode_command_116_ = dynamic_cast<Vehiclemodecommand116*>(
111 message_manager_->GetMutableProtocolDataById(Vehiclemodecommand116::ID));
112 if (vehicle_mode_command_116_ == nullptr) {
113 AERROR << "Vehiclemodecommand116 does not exist in the ChMessageManager!";
114 return ErrorCode::CANBUS_ERROR;
115 }
116
117 can_sender_->AddMessage(Brakecommand111::ID, brake_command_111_, false);
118 can_sender_->AddMessage(Gearcommand114::ID, gear_command_114_, false);
119 can_sender_->AddMessage(Steercommand112::ID, steer_command_112_, false);
120 can_sender_->AddMessage(Throttlecommand110::ID, throttle_command_110_, false);
121 can_sender_->AddMessage(Turnsignalcommand113::ID, turnsignal_command_113_,
122 false);
123 can_sender_->AddMessage(Vehiclemodecommand116::ID, vehicle_mode_command_116_,
124 false);
125
126 // need sleep to ensure all messages received
127 AINFO << "ChController is initialized.";
128
129 is_initialized_ = true;
130 return ErrorCode::OK;
131}
132
134
136 if (!is_initialized_) {
137 AERROR << "ChController has NOT been initiated.";
138 return false;
139 }
140 const auto& update_func = [this] { SecurityDogThreadFunc(); };
141 thread_.reset(new std::thread(update_func));
142
143 return true;
144}
145
147 if (!is_initialized_) {
148 AERROR << "ChController stops or starts improperly!";
149 return;
150 }
151
152 if (thread_ != nullptr && thread_->joinable()) {
153 thread_->join();
154 thread_.reset();
155 AINFO << "ChController stopped.";
156 }
157}
158
160 chassis_.Clear();
161
162 Ch chassis_detail = GetNewRecvChassisDetail();
163
164 // 1, 2
165 // if (driving_mode() == Chassis::EMERGENCY_MODE) {
166 // set_chassis_error_code(Chassis::NO_ERROR);
167 // }
168
169 chassis_.set_driving_mode(driving_mode());
170 chassis_.set_error_code(chassis_error_code());
171 // 3
172 chassis_.set_engine_started(true);
173 // 4 engine rpm ch has no engine rpm
174 // chassis_.set_engine_rpm(0);
175 // 5 ch has no wheel spd.
176 if (chassis_detail.has_ecu_status_1_515() &&
177 chassis_detail.ecu_status_1_515().has_speed()) {
178 chassis_.set_speed_mps(
179 static_cast<float>(chassis_detail.ecu_status_1_515().speed()));
180 } else {
181 chassis_.set_speed_mps(0);
182 }
183 // 6 ch has no odometer
184 // chassis_.set_odometer_m(0);
185 // 7 ch has no fuel. do not set;
186 // chassis_.set_fuel_range_m(0);
187 // 8 throttle
188 if (chassis_detail.has_throttle_status__510() &&
189 chassis_detail.throttle_status__510().has_throttle_pedal_sts()) {
190 chassis_.set_throttle_percentage(static_cast<float>(
191 chassis_detail.throttle_status__510().throttle_pedal_sts()));
192 } else {
193 chassis_.set_throttle_percentage(0);
194 }
195 // 9 brake
196 if (chassis_detail.has_brake_status__511() &&
197 chassis_detail.brake_status__511().has_brake_pedal_sts()) {
198 chassis_.set_brake_percentage(static_cast<float>(
199 chassis_detail.brake_status__511().brake_pedal_sts()));
200 } else {
201 chassis_.set_brake_percentage(0);
202 }
203 // 10 gear
204 if (chassis_detail.has_gear_status_514() &&
205 chassis_detail.gear_status_514().has_gear_sts()) {
207
208 if (chassis_detail.gear_status_514().gear_sts() ==
210 gear_pos = Chassis::GEAR_NEUTRAL;
211 }
212 if (chassis_detail.gear_status_514().gear_sts() ==
214 gear_pos = Chassis::GEAR_REVERSE;
215 }
216 if (chassis_detail.gear_status_514().gear_sts() ==
218 gear_pos = Chassis::GEAR_DRIVE;
219 }
220 if (chassis_detail.gear_status_514().gear_sts() ==
222 gear_pos = Chassis::GEAR_PARKING;
223 }
224
225 chassis_.set_gear_location(gear_pos);
226 } else {
227 chassis_.set_gear_location(Chassis::GEAR_NONE);
228 }
229 // 11 steering
230 if (chassis_detail.has_steer_status__512() &&
231 chassis_detail.steer_status__512().has_steer_angle_sts()) {
232 chassis_.set_steering_percentage(static_cast<float>(
233 chassis_detail.steer_status__512().steer_angle_sts() * 100.0 /
235 } else {
236 chassis_.set_steering_percentage(0);
237 }
238 // 12 battery soc
239 if (chassis_detail.has_ecu_status_2_516() &&
240 chassis_detail.ecu_status_2_516().has_battery_soc()) {
241 chassis_.set_battery_soc_percentage(
242 chassis_detail.ecu_status_2_516().battery_soc());
243 }
244 // 13
245 // 14 give engage_advice based on error_code and battery low soc warn
246 if (!chassis_error_mask_ && chassis_.battery_soc_percentage() > 15.0) {
247 chassis_.mutable_engage_advice()->set_advice(
249 } else {
250 chassis_.mutable_engage_advice()->set_advice(
252 if (chassis_.battery_soc_percentage() > 0) {
253 chassis_.mutable_engage_advice()->set_reason(
254 "Battery soc percentage is lower than 15%, please charge it "
255 "quickly!");
256 }
257 }
258 // 15 set vin
259 // vin set 17 bits, like LSBN1234567890123 is prased as
260 // vin17(L),vin16(S),vin15(B),.....,vin03(1)vin02(2),vin01(3)
261 std::string vin = "";
262 if (chassis_detail.has_vin_resp1_51b()) {
263 Vin_resp1_51b vin_51b = chassis_detail.vin_resp1_51b();
264 vin += vin_51b.vin01();
265 vin += vin_51b.vin02();
266 vin += vin_51b.vin03();
267 vin += vin_51b.vin04();
268 vin += vin_51b.vin05();
269 vin += vin_51b.vin06();
270 vin += vin_51b.vin07();
271 vin += vin_51b.vin08();
272 }
273 if (chassis_detail.has_vin_resp2_51c()) {
274 Vin_resp2_51c vin_51c = chassis_detail.vin_resp2_51c();
275 vin += vin_51c.vin09();
276 vin += vin_51c.vin10();
277 vin += vin_51c.vin11();
278 vin += vin_51c.vin12();
279 vin += vin_51c.vin13();
280 vin += vin_51c.vin14();
281 vin += vin_51c.vin15();
282 vin += vin_51c.vin16();
283 }
284 if (chassis_detail.has_vin_resp3_51d()) {
285 Vin_resp3_51d vin_51d = chassis_detail.vin_resp3_51d();
286 vin += vin_51d.vin17();
287 }
288 std::reverse(vin.begin(), vin.end());
289 chassis_.mutable_vehicle_id()->set_vin(vin);
290
291 // 16 front bumper event
292 if (chassis_detail.has_brake_status__511() &&
293 chassis_detail.brake_status__511().has_front_bump_env()) {
294 if (chassis_detail.brake_status__511().front_bump_env() ==
296 chassis_.set_front_bumper_event(Chassis::BUMPER_PRESSED);
297 } else {
298 chassis_.set_front_bumper_event(Chassis::BUMPER_NORMAL);
299 }
300 } else {
301 chassis_.set_front_bumper_event(Chassis::BUMPER_INVALID);
302 }
303 // 17 back bumper event
304 if (chassis_detail.has_brake_status__511() &&
305 chassis_detail.brake_status__511().has_back_bump_env()) {
306 if (chassis_detail.brake_status__511().back_bump_env() ==
308 chassis_.set_back_bumper_event(Chassis::BUMPER_PRESSED);
309 } else {
310 chassis_.set_back_bumper_event(Chassis::BUMPER_NORMAL);
311 }
312 } else {
313 chassis_.set_back_bumper_event(Chassis::BUMPER_INVALID);
314 }
315 // 18 add checkresponse signal
316 if (chassis_detail.has_brake_status__511() &&
317 chassis_detail.brake_status__511().has_brake_pedal_en_sts()) {
318 chassis_.mutable_check_response()->set_is_esp_online(
319 chassis_detail.brake_status__511().brake_pedal_en_sts() == 1);
320 }
321 if (chassis_detail.has_steer_status__512() &&
322 chassis_detail.steer_status__512().has_steer_angle_en_sts()) {
323 chassis_.mutable_check_response()->set_is_eps_online(
324 chassis_detail.steer_status__512().steer_angle_en_sts() == 1);
325 }
326 if (chassis_detail.has_throttle_status__510() &&
327 chassis_detail.throttle_status__510().has_throttle_pedal_en_sts()) {
328 chassis_.mutable_check_response()->set_is_vcu_online(
329 chassis_detail.throttle_status__510().throttle_pedal_en_sts() == 1);
330 }
331
332 if (CheckChassisError()) {
333 chassis_.mutable_engage_advice()->set_advice(
335 chassis_.mutable_engage_advice()->set_reason(
336 "Chassis has some fault, please check the chassis_detail.");
337 }
338
339 // check the chassis detail lost
341 chassis_.mutable_engage_advice()->set_advice(
343 chassis_.mutable_engage_advice()->set_reason(
344 "ch chassis detail is lost! Please check the communication error.");
345 set_chassis_error_code(Chassis::CHASSIS_CAN_LOST);
347 }
348
349 return chassis_;
350}
351
352void ChController::Emergency() {
354 ResetProtocol();
355}
356
357ErrorCode ChController::EnableAutoMode() {
359 AINFO << "already in COMPLETE_AUTO_DRIVE mode";
360 return ErrorCode::OK;
361 }
362
363 brake_command_111_->set_brake_pedal_en_ctrl(
365 throttle_command_110_->set_throttle_pedal_en_ctrl(
367 steer_command_112_->set_steer_angle_en_ctrl(
369 AINFO << "set enable";
370
371 can_sender_->Update();
372 const int32_t flag =
373 CHECK_RESPONSE_STEER_UNIT_FLAG | CHECK_RESPONSE_SPEED_UNIT_FLAG;
374 if (!CheckResponse(flag, true)) {
375 AERROR << "Failed to switch to COMPLETE_AUTO_DRIVE mode. Please check the "
376 "emergency button or chassis.";
377 Emergency();
378 set_chassis_error_code(Chassis::CHASSIS_ERROR);
379 return ErrorCode::CANBUS_ERROR;
380 } else {
382 AINFO << "Switch to COMPLETE_AUTO_DRIVE mode ok.";
383 return ErrorCode::OK;
384 }
385}
386
387ErrorCode ChController::DisableAutoMode() {
388 ResetProtocol();
389 can_sender_->Update();
391 set_chassis_error_code(Chassis::NO_ERROR);
392 AINFO << "Switch to COMPLETE_MANUAL OK!";
393 return ErrorCode::OK;
394}
395
396ErrorCode ChController::EnableSteeringOnlyMode() {
397 AFATAL << "SteeringOnlyMode Not supported!";
398 return ErrorCode::OK;
399}
400
401ErrorCode ChController::EnableSpeedOnlyMode() {
402 AFATAL << "SpeedOnlyMode Not supported!";
403 return ErrorCode::OK;
404}
405
406// NEUTRAL, REVERSE, DRIVE
407void ChController::Gear(Chassis::GearPosition gear_position) {
410 AINFO << "this drive mode no need to set gear.";
411 return;
412 }
413
414 // ADD YOUR OWN CAR CHASSIS OPERATION
415 switch (gear_position) {
418 break;
419 }
422 break;
423 }
424 case Chassis::GEAR_DRIVE: {
426 break;
427 }
430 break;
431 }
433 // AERROR << "Gear command is invalid!";
435 break;
436 }
437 default: {
439 break;
440 }
441 }
442}
443
444// brake with new acceleration
445// acceleration:0.00~99.99, unit:
446// acceleration:0.0 ~ 7.0, unit:m/s^2
447// acceleration_spd:60 ~ 100, suggest: 90
448void ChController::Brake(double pedal) {
449 // Update brake value based on mode
452 AINFO << "The current drive mode does not need to set acceleration.";
453 return;
454 }
455 // ADD YOUR OWN CAR CHASSIS OPERATION
456 brake_command_111_->set_brake_pedal_cmd(static_cast<int>(pedal));
457}
458
459// drive with old acceleration
460// gas:0.00~99.99 unit:
461void ChController::Throttle(double pedal) {
464 AINFO << "The current drive mode does not need to set acceleration.";
465 return;
466 }
467 // ADD YOUR OWN CAR CHASSIS OPERATION
468 throttle_command_110_->set_throttle_pedal_cmd(static_cast<int>(pedal));
469}
470
471void ChController::Acceleration(double acc) {}
472
473// ch default, 23 ~ -23, left:+, right:-
474// need to be compatible with control module, so reverse
475// steering with old angle speed
476// angle:99.99~0.00~-99.99, unit:, left:+, right:-
477void ChController::Steer(double angle) {
480 AINFO << "The current driving mode does not need to set steer.";
481 return;
482 }
483 const double real_angle = vehicle_params_.max_steer_angle() * angle / 100.0;
484 // reverse sign
485 // ADD YOUR OWN CAR CHASSIS OPERATION
486 steer_command_112_->set_steer_angle_cmd(real_angle);
487}
488
489// steering with new angle speed
490// angle:-99.99~0.00~99.99, unit:, left:-, right:+
491// angle_spd:0.00~99.99, unit:deg/s
492void ChController::Steer(double angle, double angle_spd) {
495 AINFO << "The current driving mode does not need to set steer.";
496 return;
497 }
498 // ADD YOUR OWN CAR CHASSIS OPERATION
499 const double real_angle = vehicle_params_.max_steer_angle() * angle / 100.0;
500 steer_command_112_->set_steer_angle_cmd(real_angle);
501}
502
503void ChController::SetEpbBreak(const ControlCommand& command) {}
504
505ErrorCode ChController::HandleCustomOperation(
506 const external_command::ChassisCommand& command) {
507 return ErrorCode::OK;
508}
509
510void ChController::SetBeam(const VehicleSignal& vehicle_signal) {
511 // Set low beam
512 if (vehicle_signal.has_low_beam() && vehicle_signal.low_beam()) {
513 turnsignal_command_113_->set_low_beam_cmd(
515 } else if (vehicle_signal.has_low_beam() && !vehicle_signal.low_beam()) {
516 turnsignal_command_113_->set_low_beam_cmd(
518 }
519}
520
521void ChController::SetHorn(const VehicleSignal& vehicle_signal) {}
522
523void ChController::SetTurningSignal(const VehicleSignal& vehicle_signal) {
524 // Set Turn Signal
525 auto signal = vehicle_signal.turn_signal();
526 if (signal == common::VehicleSignal::TURN_LEFT) {
527 turnsignal_command_113_->set_turn_signal_cmd(
529 } else if (signal == common::VehicleSignal::TURN_RIGHT) {
530 turnsignal_command_113_->set_turn_signal_cmd(
532 } else if (signal == common::VehicleSignal::TURN_HAZARD_WARNING) {
533 turnsignal_command_113_->set_turn_signal_cmd(
535 } else {
536 turnsignal_command_113_->set_turn_signal_cmd(
538 }
539}
540
541bool ChController::VerifyID() {
542 if (!CheckVin()) {
543 AERROR << "Failed to get the vin. Get vin again.";
544 GetVin();
545 return false;
546 } else {
547 ResetVin();
548 return true;
549 }
550}
551
552bool ChController::CheckVin() {
553 if (chassis_.vehicle_id().vin().size() >= 7) {
554 AINFO << "Vin check success! Vehicel vin is "
555 << chassis_.vehicle_id().vin();
556 return true;
557 } else {
558 AINFO << "Vin check failed! Current vin size is "
559 << chassis_.vehicle_id().vin().size();
560 return false;
561 }
562}
563
564void ChController::GetVin() {
565 vehicle_mode_command_116_->set_vin_req_cmd(
567 AINFO << "Get vin";
568 can_sender_->Update();
569}
570
571void ChController::ResetVin() {
572 vehicle_mode_command_116_->set_vin_req_cmd(
574 AINFO << "Reset vin";
575 can_sender_->Update();
576}
577
578void ChController::ResetProtocol() { message_manager_->ResetSendMessages(); }
579
580bool ChController::CheckChassisError() {
582 AERROR_EVERY(100) << "ChassisDetail has no devkit vehicle info.";
583 return false;
584 }
585 Ch chassis_detail = GetNewRecvChassisDetail();
586 // steer motor fault
587 if (chassis_detail.has_steer_status__512()) {
589 chassis_detail.steer_status__512().steer_err()) {
590 return true;
591 }
592 }
593 // drive error
594 if (chassis_detail.has_throttle_status__510()) {
596 chassis_detail.throttle_status__510().drive_motor_err()) {
597 return true;
598 }
599 // cancel the battery err check bacause of always causing this error block
600 // the vehicle use
601 // if (Throttle_status__510::BATTERY_BMS_ERR_BATTERY_ERR ==
602 // chassis_detail.throttle_status__510().battery_bms_err()) {
603 // return false;
604 // }
605 }
606 // brake error
607 if (chassis_detail.has_brake_status__511()) {
609 chassis_detail.brake_status__511().brake_err()) {
610 return true;
611 }
612 }
613 return false;
614}
615
616void ChController::SecurityDogThreadFunc() {
617 int32_t vertical_ctrl_fail = 0;
618 int32_t horizontal_ctrl_fail = 0;
619
620 if (can_sender_ == nullptr) {
621 AERROR << "Fail to run SecurityDogThreadFunc() because can_sender_ is "
622 "nullptr.";
623 return;
624 }
625 while (!can_sender_->IsRunning()) {
626 std::this_thread::yield();
627 }
628
629 std::chrono::duration<double, std::micro> default_period{50000};
630 int64_t start = 0;
631 int64_t end = 0;
632 while (can_sender_->IsRunning()) {
634 const Chassis::DrivingMode mode = driving_mode();
635 bool emergency_mode = false;
636
637 // 1. horizontal control check
638 if ((mode == Chassis::COMPLETE_AUTO_DRIVE ||
639 mode == Chassis::AUTO_STEER_ONLY) &&
640 CheckResponse(CHECK_RESPONSE_STEER_UNIT_FLAG, false) == false) {
641 ++horizontal_ctrl_fail;
642 if (horizontal_ctrl_fail >= kMaxFailAttempt) {
643 emergency_mode = true;
644 AERROR << "Driving_mode is into emergency by steer manual intervention";
645 set_chassis_error_code(Chassis::MANUAL_INTERVENTION);
646 }
647 } else {
648 horizontal_ctrl_fail = 0;
649 }
650
651 // 2. vertical control check
652 if ((mode == Chassis::COMPLETE_AUTO_DRIVE ||
653 mode == Chassis::AUTO_SPEED_ONLY) &&
654 CheckResponse(CHECK_RESPONSE_SPEED_UNIT_FLAG, false) == false) {
655 ++vertical_ctrl_fail;
656 if (vertical_ctrl_fail >= kMaxFailAttempt) {
657 emergency_mode = true;
658 AERROR << "Driving_mode is into emergency by speed manual intervention";
659 set_chassis_error_code(Chassis::MANUAL_INTERVENTION);
660 }
661 } else {
662 vertical_ctrl_fail = 0;
663 }
664
665 // 3. chassis fault check
666 if (CheckChassisError()) {
667 set_chassis_error_code(Chassis::CHASSIS_ERROR);
668 emergency_mode = true;
669 }
670
671 if (emergency_mode && mode != Chassis::EMERGENCY_MODE) {
673 message_manager_->ResetSendMessages();
674 can_sender_->Update();
675 }
676
677 // recove error code
678 if (!emergency_mode && !is_chassis_communication_error_ &&
679 mode == Chassis::EMERGENCY_MODE) {
680 set_chassis_error_code(Chassis::NO_ERROR);
681 }
682
684 std::chrono::duration<double, std::micro> elapsed{end - start};
685 if (elapsed < default_period) {
686 std::this_thread::sleep_for(default_period - elapsed);
687 } else {
688 AERROR << "Too much time consumption in ChController looping process:"
689 << elapsed.count();
690 }
691 }
692}
693
694bool ChController::CheckResponse(const int32_t flags, bool need_wait) {
695 int32_t retry_num = 20;
696 Ch chassis_detail;
697 bool is_eps_online = false;
698 bool is_vcu_online = false;
699 bool is_esp_online = false;
700
701 do {
702 bool check_ok = true;
703 if (flags & CHECK_RESPONSE_STEER_UNIT_FLAG) {
704 is_eps_online = chassis_.has_check_response() &&
705 chassis_.check_response().has_is_eps_online() &&
706 chassis_.check_response().is_eps_online();
707 check_ok = check_ok && is_eps_online;
708 }
709
710 if (flags & CHECK_RESPONSE_SPEED_UNIT_FLAG) {
711 is_vcu_online = chassis_.has_check_response() &&
712 chassis_.check_response().has_is_vcu_online() &&
713 chassis_.check_response().is_vcu_online();
714 is_esp_online = chassis_.has_check_response() &&
715 chassis_.check_response().has_is_esp_online() &&
716 chassis_.check_response().is_esp_online();
717 check_ok = check_ok && is_vcu_online && is_esp_online;
718 }
719 if (check_ok) {
720 return true;
721 } else {
722 AINFO << "Need to check response again.";
723 }
724 if (need_wait) {
725 --retry_num;
726 std::this_thread::sleep_for(
727 std::chrono::duration<double, std::milli>(20));
728 }
729 } while (need_wait && retry_num);
730
731 if (flags & CHECK_RESPONSE_STEER_UNIT_FLAG) {
732 AERROR << "steer check_response fail: is_eps_online:" << is_eps_online;
733 }
734
735 if (flags & CHECK_RESPONSE_SPEED_UNIT_FLAG) {
736 AERROR << "speed check_response fail: " << "is_vcu_online:" << is_vcu_online
737 << ", is_esp_online:" << is_esp_online;
738 }
739
740 return false;
741}
742
743void ChController::set_chassis_error_mask(const int32_t mask) {
744 std::lock_guard<std::mutex> lock(chassis_mask_mutex_);
745 chassis_error_mask_ = mask;
746}
747
748int32_t ChController::chassis_error_mask() {
749 std::lock_guard<std::mutex> lock(chassis_mask_mutex_);
750 return chassis_error_mask_;
751}
752
753Chassis::ErrorCode ChController::chassis_error_code() {
754 std::lock_guard<std::mutex> lock(chassis_error_code_mutex_);
755 return chassis_error_code_;
756}
757
758void ChController::set_chassis_error_code(
759 const Chassis::ErrorCode& error_code) {
760 std::lock_guard<std::mutex> lock(chassis_error_code_mutex_);
761 chassis_error_code_ = error_code;
762}
763
764} // namespace ch
765} // namespace canbus
766} // namespace apollo
Defines SenderMessage class and CanSender class.
the class of ChMessageManager
virtual void set_driving_mode(const Chassis::DrivingMode &driving_mode)
MessageManager< ::apollo::canbus::Ch > * message_manager_
Brakecommand111 * set_brake_pedal_cmd(int brake_pedal_cmd)
Brakecommand111 * set_brake_pedal_en_ctrl(Brake_command_111::Brake_pedal_en_ctrlType brake_pedal_en_ctrl)
::apollo::common::ErrorCode Init(const VehicleParameter &params, CanSender<::apollo::canbus::Ch > *const can_sender, MessageManager<::apollo::canbus::Ch > *const message_manager) override
Chassis chassis() override
calculate and return the chassis.
bool Start() override
start the vehicle controller.
void Stop() override
stop the vehicle controller.
Gearcommand114 * set_gear_cmd(Gear_command_114::Gear_cmdType gear_cmd)
Steercommand112 * set_steer_angle_cmd(double steer_angle_cmd)
Steercommand112 * set_steer_angle_en_ctrl(Steer_command_112::Steer_angle_en_ctrlType steer_angle_en_ctrl)
Throttlecommand110 * set_throttle_pedal_cmd(int throttle_pedal_cmd)
Throttlecommand110 * set_throttle_pedal_en_ctrl(Throttle_command_110::Throttle_pedal_en_ctrlType throttle_pedal_en_ctrl)
Turnsignalcommand113 * set_turn_signal_cmd(Turnsignal_command_113::Turn_signal_cmdType turn_signal_cmd)
Turnsignalcommand113 * set_low_beam_cmd(Turnsignal_command_113::Low_beam_cmdType low_beam_cmd)
Vehiclemodecommand116 * set_vin_req_cmd(Vehicle_mode_command_116::Vin_req_cmdType vin_req_cmd)
uint64_t ToMicrosecond() const
convert time to microsecond (us).
Definition time.cc:85
static Time Now()
get the current time.
Definition time.cc:57
#define AERROR
Definition log.h:44
#define AERROR_EVERY(freq)
Definition log.h:86
#define AFATAL
Definition log.h:45
#define AINFO
Definition log.h:42
class register implement
Definition arena_queue.h:37
The class of ProtocolData
optional Brake_pedal_en_stsType brake_pedal_en_sts
Definition ch.proto:150
optional Back_bump_envType back_bump_env
Definition ch.proto:160
optional Front_bump_envType front_bump_env
Definition ch.proto:158
optional Vin_resp1_51b vin_resp1_51b
Definition ch.proto:426
optional Vin_resp3_51d vin_resp3_51d
Definition ch.proto:428
optional Ecu_status_1_515 ecu_status_1_515
Definition ch.proto:421
optional Throttle_status__510 throttle_status__510
Definition ch.proto:416
optional Steer_status__512 steer_status__512
Definition ch.proto:418
optional Gear_status_514 gear_status_514
Definition ch.proto:420
optional Ecu_status_2_516 ecu_status_2_516
Definition ch.proto:422
optional Brake_status__511 brake_status__511
Definition ch.proto:417
optional Vin_resp2_51c vin_resp2_51c
Definition ch.proto:427
optional apollo::common::VehicleID vehicle_id
optional CheckResponse check_response
optional int32 battery_soc_percentage
optional Gear_stsType gear_sts
Definition ch.proto:219
optional double steer_angle_sts
Definition ch.proto:185
optional Steer_angle_en_stsType steer_angle_en_sts
Definition ch.proto:183
optional Throttle_pedal_en_stsType throttle_pedal_en_sts
Definition ch.proto:108
optional string vin05
Definition ch.proto:360
optional string vin03
Definition ch.proto:364
optional string vin07
Definition ch.proto:356
optional string vin01
Definition ch.proto:368
optional string vin02
Definition ch.proto:366
optional string vin06
Definition ch.proto:358
optional string vin04
Definition ch.proto:362
optional string vin08
Definition ch.proto:354
optional string vin10
Definition ch.proto:386
optional string vin16
Definition ch.proto:374
optional string vin14
Definition ch.proto:378
optional string vin13
Definition ch.proto:380
optional string vin11
Definition ch.proto:384
optional string vin09
Definition ch.proto:388
optional string vin12
Definition ch.proto:382
optional string vin15
Definition ch.proto:376
optional string vin17
Definition ch.proto:394
The class of VehicleController