Apollo 11.0
自动驾驶开放平台
neolix_edu_controller.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2020 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 "modules/common_msgs/basic_msgs/vehicle_signal.pb.h"
20
21#include "cyber/common/log.h"
22#include "cyber/time/time.h"
27
28namespace apollo {
29namespace canbus {
30namespace neolix_edu {
31
32using ::apollo::common::ErrorCode;
33using ::apollo::common::VehicleSignal;
34using ::apollo::control::ControlCommand;
35using ::apollo::drivers::canbus::ProtocolData;
36
37namespace {
38
39const int32_t kMaxFailAttempt = 10;
40const int32_t CHECK_RESPONSE_STEER_UNIT_FLAG = 1;
41const int32_t CHECK_RESPONSE_SPEED_UNIT_FLAG = 2;
42} // namespace
43
45 can_sender_->AddMessage(Adsbrakecommand46::ID, ads_brake_command_46_, false);
46 can_sender_->AddMessage(Adsdiagnosis628::ID, ads_diagnosis_628_, false);
47 can_sender_->AddMessage(Adsdrivecommand50::ID, ads_drive_command_50_, false);
48 can_sender_->AddMessage(Adsepscommand56::ID, ads_eps_command_56_, false);
50 ads_light_horn_command_310_, false);
51}
52
54 const VehicleParameter& params,
55 CanSender<::apollo::canbus::Neolix_edu>* const can_sender,
56 MessageManager<::apollo::canbus::Neolix_edu>* const message_manager) {
57 if (is_initialized_) {
58 AINFO << "Neolix_eduController has already been initiated.";
59 return ErrorCode::CANBUS_ERROR;
60 }
61
62 vehicle_params_.CopyFrom(
63 common::VehicleConfigHelper::Instance()->GetConfig().vehicle_param());
64 params_.CopyFrom(params);
65 if (!params_.has_driving_mode()) {
66 AERROR << "Vehicle conf pb not set driving_mode.";
67 return ErrorCode::CANBUS_ERROR;
68 }
69
70 if (can_sender == nullptr) {
71 return ErrorCode::CANBUS_ERROR;
72 }
73 can_sender_ = can_sender;
74
75 if (message_manager == nullptr) {
76 AERROR << "protocol manager is null.";
77 return ErrorCode::CANBUS_ERROR;
78 }
79 message_manager_ = message_manager;
80
81 // sender part
82 ads_brake_command_46_ = dynamic_cast<Adsbrakecommand46*>(
83 message_manager_->GetMutableProtocolDataById(Adsbrakecommand46::ID));
84 if (ads_brake_command_46_ == nullptr) {
85 AERROR
86 << "Adsbrakecommand46 does not exist in the Neolix_eduMessageManager!";
87 return ErrorCode::CANBUS_ERROR;
88 }
89
90 ads_diagnosis_628_ = dynamic_cast<Adsdiagnosis628*>(
91 message_manager_->GetMutableProtocolDataById(Adsdiagnosis628::ID));
92 if (ads_diagnosis_628_ == nullptr) {
93 AERROR << "Adsdiagnosis628 does not exist in the Neolix_eduMessageManager!";
94 return ErrorCode::CANBUS_ERROR;
95 }
96
97 ads_drive_command_50_ = dynamic_cast<Adsdrivecommand50*>(
98 message_manager_->GetMutableProtocolDataById(Adsdrivecommand50::ID));
99 if (ads_drive_command_50_ == nullptr) {
100 AERROR
101 << "Adsdrivecommand50 does not exist in the Neolix_eduMessageManager!";
102 return ErrorCode::CANBUS_ERROR;
103 }
104
105 ads_eps_command_56_ = dynamic_cast<Adsepscommand56*>(
106 message_manager_->GetMutableProtocolDataById(Adsepscommand56::ID));
107 if (ads_eps_command_56_ == nullptr) {
108 AERROR << "Adsepscommand56 does not exist in the Neolix_eduMessageManager!";
109 return ErrorCode::CANBUS_ERROR;
110 }
111
112 ads_light_horn_command_310_ = dynamic_cast<Adslighthorncommand310*>(
113 message_manager_->GetMutableProtocolDataById(Adslighthorncommand310::ID));
114 if (ads_light_horn_command_310_ == nullptr) {
115 AERROR << "Adslighthorncommand310 does not exist in the "
116 "Neolix_eduMessageManager!";
117 return ErrorCode::CANBUS_ERROR;
118 }
119
121
122 AINFO << "Neolix_eduController is initialized.";
123
124 is_initialized_ = true;
125 return ErrorCode::OK;
126}
127
129
131 if (!is_initialized_) {
132 AERROR << "Neolix_eduController has NOT been initiated.";
133 return false;
134 }
135 const auto& update_func = [this] { SecurityDogThreadFunc(); };
136 thread_.reset(new std::thread(update_func));
137
138 return true;
139}
140
142 if (!is_initialized_) {
143 AERROR << "Neolix_eduController stops or starts improperly!";
144 return;
145 }
146
147 if (thread_ != nullptr && thread_->joinable()) {
148 thread_->join();
149 thread_.reset();
150 AINFO << "Neolix_eduController stopped.";
151 }
152}
153
155 chassis_.Clear();
156
157 Neolix_edu chassis_detail = GetNewRecvChassisDetail();
158
159 // 1, 2
160 // if (driving_mode() == Chassis::EMERGENCY_MODE) {
161 // set_chassis_error_code(Chassis::NO_ERROR);
162 // }
163
164 chassis_.set_driving_mode(driving_mode());
165 chassis_.set_error_code(chassis_error_code());
166
167 // 3
168 chassis_.set_engine_started(true);
169
170 // 3 speed_mps && wheel_speed
171 auto wheelspeed = chassis_.mutable_wheel_speed();
172 if (chassis_detail.has_aeb_frontwheelspeed_353() &&
173 chassis_detail.has_aeb_rearwheelspeed_354()) {
174 wheelspeed->set_wheel_spd_fl(
175 chassis_detail.aeb_frontwheelspeed_353().wheelspeed_fl() / 3.6);
176 wheelspeed->set_wheel_spd_fr(
177 chassis_detail.aeb_frontwheelspeed_353().wheelspeed_fr() / 3.6);
178 wheelspeed->set_wheel_spd_rl(
179 chassis_detail.aeb_rearwheelspeed_354().wheelspeed_rl() / 3.6);
180 wheelspeed->set_wheel_spd_rr(
181 chassis_detail.aeb_rearwheelspeed_354().wheelspeed_rr() / 3.6);
182 chassis_.set_speed_mps(
183 (chassis_detail.aeb_frontwheelspeed_353().wheelspeed_fl() +
184 chassis_detail.aeb_frontwheelspeed_353().wheelspeed_fr() +
185 chassis_detail.aeb_rearwheelspeed_354().wheelspeed_rl() +
186 chassis_detail.aeb_rearwheelspeed_354().wheelspeed_rr()) /
187 4 / 3.6);
188 } else {
189 chassis_.set_speed_mps(0);
190 }
191 // wheel_speed direction
192 if (chassis_detail.has_vcu_vehicle_status_report_101() &&
193 chassis_detail.vcu_vehicle_status_report_101()
194 .has_vcu_motor_direction()) {
195 if (chassis_detail.vcu_vehicle_status_report_101().vcu_motor_direction() ==
196 0) {
197 wheelspeed->set_wheel_direction_fl(WheelSpeed::STANDSTILL);
198 wheelspeed->set_wheel_direction_fr(WheelSpeed::STANDSTILL);
199 wheelspeed->set_wheel_direction_rl(WheelSpeed::STANDSTILL);
200 wheelspeed->set_wheel_direction_rr(WheelSpeed::STANDSTILL);
201 } else if (chassis_detail.vcu_vehicle_status_report_101()
202 .vcu_motor_direction() == 1) {
203 wheelspeed->set_wheel_direction_fl(WheelSpeed::FORWARD);
204 wheelspeed->set_wheel_direction_fr(WheelSpeed::FORWARD);
205 wheelspeed->set_wheel_direction_rl(WheelSpeed::FORWARD);
206 wheelspeed->set_wheel_direction_rr(WheelSpeed::FORWARD);
207 } else if (chassis_detail.vcu_vehicle_status_report_101()
208 .vcu_motor_direction() == 2) {
209 wheelspeed->set_wheel_direction_fl(WheelSpeed::BACKWARD);
210 wheelspeed->set_wheel_direction_fr(WheelSpeed::BACKWARD);
211 wheelspeed->set_wheel_direction_rl(WheelSpeed::BACKWARD);
212 wheelspeed->set_wheel_direction_rr(WheelSpeed::BACKWARD);
213 } else {
214 wheelspeed->set_wheel_direction_fl(WheelSpeed::INVALID);
215 wheelspeed->set_wheel_direction_fr(WheelSpeed::INVALID);
216 wheelspeed->set_wheel_direction_rl(WheelSpeed::INVALID);
217 wheelspeed->set_wheel_direction_rr(WheelSpeed::INVALID);
218 }
219 } else {
220 wheelspeed->clear_wheel_direction_fl();
221 wheelspeed->clear_wheel_direction_fr();
222 wheelspeed->clear_wheel_direction_rl();
223 wheelspeed->clear_wheel_direction_rr();
224 }
225
226 // 4 SOC
227 if (chassis_detail.has_vcu_vehicle_status_report_101() &&
228 chassis_detail.vcu_vehicle_status_report_101().has_vcu_display_soc()) {
229 chassis_.set_battery_soc_percentage(
231 } else {
232 chassis_.set_battery_soc_percentage(0);
233 }
234 // 5 steering
235 if (chassis_detail.has_vcu_eps_report_57() &&
236 chassis_detail.vcu_eps_report_57().has_vcu_real_angle()) {
237 chassis_.set_steering_percentage(static_cast<float>(
238 chassis_detail.vcu_eps_report_57().vcu_real_angle() * 100 /
239 vehicle_params_.max_steer_angle() * M_PI / 180));
240 } else {
241 chassis_.set_steering_percentage(0);
242 }
243
244 // 6 throttle
245 if (chassis_detail.has_vcu_drive_report_52() &&
246 chassis_detail.vcu_drive_report_52().has_vcu_real_torque()) {
247 chassis_.set_throttle_percentage(
248 chassis_detail.vcu_drive_report_52().vcu_real_torque() * 2);
249 } else {
250 chassis_.set_throttle_percentage(0);
251 }
252
253 // 7 brake
254 if (chassis_detail.has_vcu_brake_report_47() &&
255 chassis_detail.vcu_brake_report_47().has_vcu_real_brake()) {
256 chassis_.set_brake_percentage(
257 chassis_detail.vcu_brake_report_47().vcu_real_brake());
258 } else {
259 chassis_.set_brake_percentage(0);
260 }
261 // 8 gear
262 if (chassis_detail.has_vcu_drive_report_52() &&
263 chassis_detail.vcu_drive_report_52().has_vcu_real_shift()) {
264 chassis_.set_gear_location((apollo::canbus::Chassis_GearPosition)
265 chassis_detail.vcu_drive_report_52()
266 .vcu_real_shift());
267 }
268 // 9 epb
269 if (chassis_detail.has_vcu_brake_report_47() &&
270 chassis_detail.vcu_brake_report_47().has_vcu_real_parking_status()) {
271 if (chassis_detail.vcu_brake_report_47().vcu_real_parking_status() == 1) {
272 chassis_.set_parking_brake(true);
273 } else {
274 chassis_.set_parking_brake(false);
275 }
276 } else {
277 chassis_.set_parking_brake(false);
278 }
279
280 if (chassis_error_mask_) {
281 chassis_.set_chassis_error_mask(chassis_error_mask_);
282 }
283
284 // 10 give engage_advice based on error_code and canbus feedback
285 if (!chassis_error_mask_ && !chassis_.parking_brake() &&
286 (chassis_.throttle_percentage() == 0.0)) {
287 chassis_.mutable_engage_advice()->set_advice(
289 } else {
290 chassis_.mutable_engage_advice()->set_advice(
292 }
293
294 // 11 bumper event
295 if (chassis_detail.has_vcu_brake_report_47() &&
296 chassis_detail.vcu_brake_report_47().has_vcu_ehb_brake_state()) {
297 if (chassis_detail.vcu_brake_report_47().vcu_ehb_brake_state() ==
299 chassis_.set_front_bumper_event(Chassis::BUMPER_PRESSED);
300 chassis_.set_back_bumper_event(Chassis::BUMPER_PRESSED);
301 } else {
302 chassis_.set_front_bumper_event(Chassis::BUMPER_NORMAL);
303 chassis_.set_back_bumper_event(Chassis::BUMPER_NORMAL);
304 }
305 } else {
306 chassis_.set_front_bumper_event(Chassis::BUMPER_INVALID);
307 chassis_.set_back_bumper_event(Chassis::BUMPER_INVALID);
308 }
309
310 // 12 add checkresponse signal
311 if (chassis_detail.has_vcu_brake_report_47() &&
312 chassis_detail.vcu_brake_report_47().has_brake_enable_resp()) {
313 chassis_.mutable_check_response()->set_is_esp_online(
314 chassis_detail.vcu_brake_report_47().brake_enable_resp() == 1);
315 }
316 if (chassis_detail.has_vcu_drive_report_52() &&
317 chassis_detail.vcu_drive_report_52().has_drive_enable_resp()) {
318 chassis_.mutable_check_response()->set_is_vcu_online(
319 chassis_detail.vcu_drive_report_52().drive_enable_resp() == 1);
320 }
321 if (chassis_detail.has_vcu_eps_report_57() &&
322 chassis_detail.vcu_eps_report_57().has_drive_enable_resp()) {
323 chassis_.mutable_check_response()->set_is_eps_online(
324 chassis_detail.vcu_eps_report_57().drive_enable_resp() == 1);
325 }
326
327 if (CheckChassisError()) {
328 chassis_.mutable_engage_advice()->set_advice(
330 chassis_.mutable_engage_advice()->set_reason(
331 "Chassis has some fault, please check the chassis_detail.");
332 }
333
334 // check the chassis detail lost
336 chassis_.mutable_engage_advice()->set_advice(
338 chassis_.mutable_engage_advice()->set_reason(
339 "neolix chassis detail is lost! Please check the communication error.");
340 set_chassis_error_code(Chassis::CHASSIS_CAN_LOST);
342 }
343
344 return chassis_;
345}
346
347bool Neolix_eduController::VerifyID() { return true; }
348
349void Neolix_eduController::Emergency() {
351 ResetProtocol();
352}
353
354ErrorCode Neolix_eduController::EnableAutoMode() {
356 AINFO << "already in COMPLETE_AUTO_DRIVE mode";
357 return ErrorCode::OK;
358 }
359 // set enable
360 ads_brake_command_46_->set_drive_enable(true);
361 ads_drive_command_50_->set_drive_enable(true);
362 ads_eps_command_56_->set_drive_enable(true);
363
364 can_sender_->Update();
365 const int32_t flag =
366 CHECK_RESPONSE_STEER_UNIT_FLAG | CHECK_RESPONSE_SPEED_UNIT_FLAG;
367 if (!CheckResponse(flag, true)) {
368 AERROR << "Failed to switch to COMPLETE_AUTO_DRIVE mode. Please check the "
369 "emergency button or chassis.";
370 Emergency();
371 set_chassis_error_code(Chassis::CHASSIS_ERROR);
372 return ErrorCode::CANBUS_ERROR;
373 }
375 AINFO << "Switch to COMPLETE_AUTO_DRIVE mode ok.";
376 return ErrorCode::OK;
377}
378
379ErrorCode Neolix_eduController::DisableAutoMode() {
380 ResetProtocol();
381 can_sender_->Update();
383 set_chassis_error_code(Chassis::NO_ERROR);
384 AINFO << "Switch to COMPLETE_MANUAL ok.";
385 return ErrorCode::OK;
386}
387
388ErrorCode Neolix_eduController::EnableSteeringOnlyMode() {
392 AINFO << "Already in AUTO_STEER_ONLY mode.";
393 return ErrorCode::OK;
394 }
395 AFATAL << "SpeedOnlyMode is not supported in Neolix_edu!";
396 return ErrorCode::OK;
397}
398
399ErrorCode Neolix_eduController::EnableSpeedOnlyMode() {
403 AINFO << "Already in AUTO_SPEED_ONLY mode";
404 return ErrorCode::OK;
405 }
406 AFATAL << "SpeedOnlyMode is not supported in Neolix_edu!";
407 return ErrorCode::OK;
408}
409
410// NEUTRAL, REVERSE, DRIVE
411void Neolix_eduController::Gear(Chassis::GearPosition gear_position) {
414 AINFO << "This drive mode no need to set gear.";
415 return;
416 }
417 switch (gear_position) {
419 ads_drive_command_50_->set_auto_shift_command(
421 ads_brake_command_46_->set_auto_parking_command(false);
422 break;
423 }
425 ads_drive_command_50_->set_auto_shift_command(
427 break;
428 }
429 case Chassis::GEAR_DRIVE: {
430 ads_drive_command_50_->set_auto_shift_command(
432 break;
433 }
435 ads_brake_command_46_->set_auto_parking_command(true);
436 break;
437 }
438 default:
439 break;
440 }
441}
442
443// brake with pedal
444// pedal:0.00~99.99, unit:
445void Neolix_eduController::Brake(double pedal) {
446 // TODO(All) : Update brake value based on mode
449 AINFO << "The current drive mode does not need to set brake pedal.";
450 return;
451 }
452 ads_brake_command_46_->set_auto_brake_command(pedal);
453}
454
455// drive with old acceleration
456// gas:0.00~99.99 unit:
457void Neolix_eduController::Throttle(double pedal) {
460 AINFO << "The current drive mode does not need to set throttle pedal.";
461 return;
462 }
463 ads_drive_command_50_->set_auto_drive_torque(pedal / 2);
464}
465
466// confirm the car is driven by acceleration command or throttle/brake pedal
467// drive with acceleration/deceleration
468// acc:-7.0 ~ 5.0, unit:m/s^2
469void Neolix_eduController::Acceleration(double acc) {
470 // None
471}
472
473// neolix_edu default, -380 ~ 380, 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 Neolix_eduController::Steer(double angle) {
480 AINFO << "The current driving mode does not need to set steer.";
481 return;
482 }
483 const double real_angle =
484 vehicle_params_.max_steer_angle() / M_PI * 180 * angle / 100.0;
485 ads_eps_command_56_->set_auto_target_angle(real_angle);
486}
487
488// steering with new angle speed
489// angle:-99.99~0.00~99.99, unit:, left:-, right:+
490// angle_spd:0.00~99.99, unit:deg/s
491void Neolix_eduController::Steer(double angle, double angle_spd) {
494 AINFO << "The current driving mode does not need to set steer.";
495 return;
496 }
497 const double real_angle =
498 vehicle_params_.max_steer_angle() / M_PI * 180 * angle / 100.0;
499 ads_eps_command_56_->set_auto_target_angle(real_angle);
500}
501
502void Neolix_eduController::SetEpbBreak(const ControlCommand& command) {
503 if (command.parking_brake()) {
504 ads_brake_command_46_->set_auto_parking_command(true);
505 } else {
506 ads_brake_command_46_->set_auto_parking_command(false);
507 }
508}
509
510ErrorCode Neolix_eduController::HandleCustomOperation(
511 const external_command::ChassisCommand& command) {
512 return ErrorCode::OK;
513}
514
515void Neolix_eduController::SetBeam(const VehicleSignal& vehicle_signal) {
516 if (vehicle_signal.high_beam()) {
517 // None
518 } else if (vehicle_signal.low_beam()) {
519 // None
520 } else {
521 // None
522 }
523}
524
525void Neolix_eduController::SetHorn(const VehicleSignal& vehicle_signal) {
526 if (vehicle_signal.horn()) {
527 // None
528 } else {
529 // None
530 }
531}
532
533void Neolix_eduController::SetTurningSignal(
534 const VehicleSignal& vehicle_signal) {
535 // None
536}
537
538void Neolix_eduController::ResetProtocol() {
539 message_manager_->ResetSendMessages();
540}
541
542bool Neolix_eduController::CheckChassisError() {
544 AERROR_EVERY(100) << "ChassisDetail has no neolix vehicle info.";
545 }
546 /* ADD YOUR OWN CAR CHASSIS OPERATION
547 */
548 return false;
549}
550
551void Neolix_eduController::SecurityDogThreadFunc() {
552 int32_t vertical_ctrl_fail = 0;
553 int32_t horizontal_ctrl_fail = 0;
554
555 if (can_sender_ == nullptr) {
556 AERROR << "Failed to run SecurityDogThreadFunc() because can_sender_ is "
557 "nullptr.";
558 return;
559 }
560 while (!can_sender_->IsRunning()) {
561 std::this_thread::yield();
562 }
563
564 std::chrono::duration<double, std::micro> default_period{50000};
565 int64_t start = 0;
566 int64_t end = 0;
567 while (can_sender_->IsRunning()) {
569 const Chassis::DrivingMode mode = driving_mode();
570 bool emergency_mode = false;
571
572 // 1. horizontal control check
573 if ((mode == Chassis::COMPLETE_AUTO_DRIVE ||
574 mode == Chassis::AUTO_STEER_ONLY) &&
575 CheckResponse(CHECK_RESPONSE_STEER_UNIT_FLAG, false) == false) {
576 ++horizontal_ctrl_fail;
577 if (horizontal_ctrl_fail >= kMaxFailAttempt) {
578 emergency_mode = true;
579 AERROR << "Driving_mode is into emergency by steer manual intervention";
580 set_chassis_error_code(Chassis::MANUAL_INTERVENTION);
581 }
582 } else {
583 horizontal_ctrl_fail = 0;
584 }
585
586 // 2. vertical control check
587 if ((mode == Chassis::COMPLETE_AUTO_DRIVE ||
588 mode == Chassis::AUTO_SPEED_ONLY) &&
589 !CheckResponse(CHECK_RESPONSE_SPEED_UNIT_FLAG, false)) {
590 ++vertical_ctrl_fail;
591 if (vertical_ctrl_fail >= kMaxFailAttempt) {
592 emergency_mode = true;
593 AERROR << "Driving_mode is into emergency by speed manual intervention";
594 set_chassis_error_code(Chassis::MANUAL_INTERVENTION);
595 }
596 } else {
597 vertical_ctrl_fail = 0;
598 }
599
600 // 3. chassis fault check
601 if (CheckChassisError()) {
602 set_chassis_error_code(Chassis::CHASSIS_ERROR);
603 emergency_mode = true;
604 }
605
606 // chassis error process
607 if (emergency_mode && mode != Chassis::EMERGENCY_MODE) {
609 message_manager_->ResetSendMessages();
610 can_sender_->Update();
611 }
612
613 // recove error code
614 if (!emergency_mode && !is_chassis_communication_error_ &&
615 mode == Chassis::EMERGENCY_MODE) {
616 set_chassis_error_code(Chassis::NO_ERROR);
617 }
618
620 std::chrono::duration<double, std::micro> elapsed{end - start};
621 if (elapsed < default_period) {
622 std::this_thread::sleep_for(default_period - elapsed);
623 } else {
624 AERROR << "Too much time consumption in Neolix_eduController looping "
625 "process:"
626 << elapsed.count();
627 }
628 }
629}
630
631bool Neolix_eduController::CheckResponse(const int32_t flags, bool need_wait) {
632 int32_t retry_num = 20;
633 Neolix_edu chassis_detail;
634 bool is_eps_online = false;
635 bool is_vcu_online = false;
636 bool is_esp_online = false;
637
638 do {
639 bool check_ok = true;
640 if (flags & CHECK_RESPONSE_STEER_UNIT_FLAG) {
641 is_eps_online = chassis_.has_check_response() &&
642 chassis_.check_response().has_is_eps_online() &&
643 chassis_.check_response().is_eps_online();
644 check_ok = check_ok && is_eps_online;
645 }
646
647 if (flags & CHECK_RESPONSE_SPEED_UNIT_FLAG) {
648 is_vcu_online = chassis_.has_check_response() &&
649 chassis_.check_response().has_is_vcu_online() &&
650 chassis_.check_response().is_vcu_online();
651 is_esp_online = chassis_.has_check_response() &&
652 chassis_.check_response().has_is_esp_online() &&
653 chassis_.check_response().is_esp_online();
654 check_ok = check_ok && is_vcu_online && is_esp_online;
655 }
656 if (check_ok) {
657 return true;
658 } else {
659 AINFO << "Need to check response again.";
660 }
661 if (need_wait) {
662 --retry_num;
663 std::this_thread::sleep_for(
664 std::chrono::duration<double, std::milli>(20));
665 }
666 } while (need_wait && retry_num);
667
668 if (flags & CHECK_RESPONSE_STEER_UNIT_FLAG) {
669 AERROR << "steer check_response fail: is_eps_online:" << is_eps_online;
670 }
671
672 if (flags & CHECK_RESPONSE_SPEED_UNIT_FLAG) {
673 AERROR << "speed check_response fail: " << "is_vcu_online:" << is_vcu_online
674 << ", is_esp_online:" << is_esp_online;
675 }
676
677 return false;
678}
679
680void Neolix_eduController::set_chassis_error_mask(const int32_t mask) {
681 std::lock_guard<std::mutex> lock(chassis_mask_mutex_);
682 chassis_error_mask_ = mask;
683}
684
685int32_t Neolix_eduController::chassis_error_mask() {
686 std::lock_guard<std::mutex> lock(chassis_mask_mutex_);
687 return chassis_error_mask_;
688}
689
690Chassis::ErrorCode Neolix_eduController::chassis_error_code() {
691 std::lock_guard<std::mutex> lock(chassis_error_code_mutex_);
692 return chassis_error_code_;
693}
694
695void Neolix_eduController::set_chassis_error_code(
696 const Chassis::ErrorCode& error_code) {
697 std::lock_guard<std::mutex> lock(chassis_error_code_mutex_);
698 chassis_error_code_ = error_code;
699}
700
701} // namespace neolix_edu
702} // namespace canbus
703} // namespace apollo
Defines SenderMessage class and CanSender class.
virtual void set_driving_mode(const Chassis::DrivingMode &driving_mode)
MessageManager< ::apollo::canbus::Neolix_edu > * message_manager_
Adsbrakecommand46 * set_auto_brake_command(int auto_brake_command)
Adsbrakecommand46 * set_drive_enable(bool drive_enable)
Adsbrakecommand46 * set_auto_parking_command(bool auto_parking_command)
Adsdrivecommand50 * set_auto_drive_torque(double auto_drive_torque)
Adsdrivecommand50 * set_auto_shift_command(Ads_drive_command_50::Auto_shift_commandType auto_shift_command)
Adsdrivecommand50 * set_drive_enable(bool drive_enable)
Adsepscommand56 * set_drive_enable(bool drive_enable)
Adsepscommand56 * set_auto_target_angle(double auto_target_angle)
void Stop() override
stop the vehicle controller.
void AddSendMessage() override
add the sender message.
Chassis chassis() override
calculate and return the chassis.
bool Start() override
start the vehicle controller.
::apollo::common::ErrorCode Init(const VehicleParameter &params, CanSender<::apollo::canbus::Neolix_edu > *const can_sender, MessageManager<::apollo::canbus::Neolix_edu > *const message_manager) override
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 CheckResponse check_response
optional bool parking_brake
Definition chassis.proto:94
optional float throttle_percentage
Definition chassis.proto:79
optional Vcu_drive_report_52 vcu_drive_report_52
optional Vcu_eps_report_57 vcu_eps_report_57
optional Aeb_frontwheelspeed_353 aeb_frontwheelspeed_353
optional Aeb_rearwheelspeed_354 aeb_rearwheelspeed_354
optional Vcu_vehicle_status_report_101 vcu_vehicle_status_report_101
optional Vcu_brake_report_47 vcu_brake_report_47
optional Vcu_ehb_brakeType vcu_ehb_brake_state
optional Vcu_real_shiftType vcu_real_shift
The class of VehicleController