Apollo 10.0
自动驾驶开放平台
apollo::canbus::VehicleController< SensorType > 模板类 参考abstract

This is the interface class of vehicle controller. 更多...

#include <vehicle_controller.h>

apollo::canbus::VehicleController< SensorType > 的协作图:

Public 成员函数

virtual ~VehicleController ()=default
 
virtual common::ErrorCode Init (const VehicleParameter &params, CanSender< SensorType > *const can_sender, MessageManager< SensorType > *const message_manager)=0
 initialize the vehicle controller.
 
virtual bool Start ()=0
 start the vehicle controller.
 
virtual void Stop ()=0
 stop the vehicle controller.
 
virtual Chassis chassis ()=0
 calculate and return the chassis.
 
virtual common::ErrorCode Update (const control::ControlCommand &command)
 update the vehicle controller.
 
virtual common::ErrorCode Update (const external_command::ChassisCommand &command)
 
virtual common::ErrorCode SetDrivingMode (const Chassis::DrivingMode &driving_mode)
 set vehicle to appointed driving mode.
 
virtual bool CheckChassisCommunicationError ()
 
virtual void AddSendMessage ()
 
virtual SensorType GetNewRecvChassisDetail ()
 
virtual SensorType GetNewSenderChassisDetail ()
 
virtual Chassis::DrivingMode driving_mode ()
 

Protected 成员函数

virtual void set_driving_mode (const Chassis::DrivingMode &driving_mode)
 

Protected 属性

common::VehicleSignal last_chassis_command_
 
common::VehicleSignal last_control_command_
 
canbus::VehicleParameter params_
 
common::VehicleParam vehicle_params_
 
CanSender< SensorType > * can_sender_ = nullptr
 
CanReceiver< SensorType > * can_receiver_ = nullptr
 
MessageManager< SensorType > * message_manager_ = nullptr
 
bool is_initialized_ = false
 
Chassis::DrivingMode driving_mode_ = Chassis::COMPLETE_MANUAL
 
bool is_reset_ = false
 
std::mutex mode_mutex_
 
uint32_t lost_chassis_reveive_detail_count_ = 0
 
bool is_need_count_ = true
 
size_t sender_data_size_previous_ = 0.0
 
int64_t start_time_ = 0
 
bool is_chassis_communication_error_ = false
 

详细描述

template<typename SensorType>
class apollo::canbus::VehicleController< SensorType >

This is the interface class of vehicle controller.

It defines pure virtual functions, and also some implemented common functions.

在文件 vehicle_controller.h60 行定义.

构造及析构函数说明

◆ ~VehicleController()

template<typename SensorType >
virtual apollo::canbus::VehicleController< SensorType >::~VehicleController ( )
virtualdefault

成员函数说明

◆ AddSendMessage()

template<typename SensorType >
void apollo::canbus::VehicleController< SensorType >::AddSendMessage ( )
virtual

◆ chassis()

◆ CheckChassisCommunicationError()

template<typename SensorType >
bool apollo::canbus::VehicleController< SensorType >::CheckChassisCommunicationError ( )
virtual

在文件 vehicle_controller.h234 行定义.

234 {
235 SensorType chassis_detail_sender;
236 if (message_manager_->GetSensorCheckSenderData(&chassis_detail_sender) !=
237 ErrorCode::OK) {
238 AERROR_EVERY(100) << "Get " << typeid(SensorType).name()
239 << " chassis receive detail failed.";
240 }
241 size_t sender_data_size = chassis_detail_sender.ByteSizeLong();
242 ADEBUG << "check chassis detail sender_data_size is " << sender_data_size;
243 int64_t end_time = 0;
244 if ((sender_data_size_previous_ < 2) && (sender_data_size > 2)) {
246 ADEBUG << "end_time is " << end_time;
247 if (start_time_ > 0) {
248 const double sender_diff = (end_time - start_time_) * 1e-3;
249 ADEBUG << "sender protocol preiod is " << sender_diff;
250 }
251 } else if ((sender_data_size_previous_ > 2) && (sender_data_size < 2)) {
253 ADEBUG << "start_time_ is " << start_time_;
254 }
255 sender_data_size_previous_ = sender_data_size;
256 message_manager_->ClearSensorCheckSenderData();
257
258 SensorType chassis_detail_receiver;
259 if (message_manager_->GetSensorCheckRecvData(&chassis_detail_receiver) !=
260 ErrorCode::OK) {
261 AERROR_EVERY(100) << "Get " << typeid(SensorType).name()
262 << " chassis receive detail failed.";
263 }
264 ADEBUG << "chassis_detail_receiver is "
265 << chassis_detail_receiver.ShortDebugString();
266 size_t receiver_data_size = chassis_detail_receiver.ByteSizeLong();
267 ADEBUG << "check chassis detail receiver_data_size is " << receiver_data_size;
268 // check receiver data is null
269 if (receiver_data_size < 2) {
270 if (is_need_count_) {
272 }
273 } else {
275 is_need_count_ = true;
276 }
277 ADEBUG << "lost_chassis_reveive_detail_count_ is "
279 // check receive data lost threshold is (100 * 10)ms
281 is_need_count_ = false;
283 AERROR << typeid(SensorType).name()
284 << " chassis detail is lost, please check the "
285 "communication error.";
286 message_manager_->ClearSensorCheckRecvData();
287 message_manager_->ResetSendMessages();
288 return true;
289 } else {
291 }
292 message_manager_->ClearSensorCheckRecvData();
293
294 return false;
295}
MessageManager< SensorType > * message_manager_
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 ADEBUG
Definition log.h:41
#define AERROR
Definition log.h:44
#define AERROR_EVERY(freq)
Definition log.h:86
SensorType
Sensor types are set in the order of lidar, radar, camera, ultrasonic Please make sure SensorType has...
Definition sensor_meta.h:29

◆ driving_mode()

template<typename SensorType >
Chassis::DrivingMode apollo::canbus::VehicleController< SensorType >::driving_mode ( )
virtual

在文件 vehicle_controller.h336 行定义.

336 {
337 std::lock_guard<std::mutex> lock(mode_mutex_);
338 return driving_mode_;
339}

◆ GetNewRecvChassisDetail()

template<typename SensorType >
SensorType apollo::canbus::VehicleController< SensorType >::GetNewRecvChassisDetail ( )
virtual

在文件 vehicle_controller.h301 行定义.

301 {
302 SensorType receiver_chassis_detail;
303 if (message_manager_->GetSensorRecvData(&receiver_chassis_detail) !=
304 ErrorCode::OK) {
305 AERROR_EVERY(100) << "Get " << typeid(SensorType).name()
306 << " chassis detail receiver failed.";
307 return receiver_chassis_detail;
308 }
309 ADEBUG << "receiver_chassis_detail is "
310 << receiver_chassis_detail.ShortDebugString();
312 message_manager_->ClearSensorRecvData();
313 }
314 return receiver_chassis_detail;
315}

◆ GetNewSenderChassisDetail()

template<typename SensorType >
SensorType apollo::canbus::VehicleController< SensorType >::GetNewSenderChassisDetail ( )
virtual

在文件 vehicle_controller.h318 行定义.

318 {
319 SensorType sender_chassis_detail;
320 if (message_manager_->GetSensorSenderData(&sender_chassis_detail) !=
321 ErrorCode::OK) {
322 AERROR_EVERY(100) << "Get " << typeid(SensorType).name()
323 << " chassis detail receiver failed.";
324 return sender_chassis_detail;
325 }
326 message_manager_->GetSensorSenderData(&sender_chassis_detail);
327 ADEBUG << "sender_chassis_detail is "
328 << sender_chassis_detail.ShortDebugString();
329 if (can_sender_->IsMessageClear()) {
330 message_manager_->ClearSensorSenderData();
331 }
332 return sender_chassis_detail;
333}
CanSender< SensorType > * can_sender_

◆ Init()

template<typename SensorType >
virtual common::ErrorCode apollo::canbus::VehicleController< SensorType >::Init ( const VehicleParameter params,
CanSender< SensorType > *const  can_sender,
MessageManager< SensorType > *const  message_manager 
)
pure virtual

initialize the vehicle controller.

参数
can_sendera pointer to canbus sender.
message_managera pointer to the message_manager.
返回
error_code

◆ set_driving_mode()

template<typename SensorType >
void apollo::canbus::VehicleController< SensorType >::set_driving_mode ( const Chassis::DrivingMode driving_mode)
protectedvirtual

在文件 vehicle_controller.h342 行定义.

343 {
344 std::lock_guard<std::mutex> lock(mode_mutex_);
346}
virtual Chassis::DrivingMode driving_mode()

◆ SetDrivingMode()

template<typename SensorType >
ErrorCode apollo::canbus::VehicleController< SensorType >::SetDrivingMode ( const Chassis::DrivingMode driving_mode)
virtual

set vehicle to appointed driving mode.

参数
drivingmode to be appointed.
返回
error_code

在文件 vehicle_controller.h349 行定义.

350 {
352 AINFO << "Can't set vehicle to EMERGENCY_MODE driving mode.";
353 return ErrorCode::CANBUS_ERROR;
354 }
355
356 // vehicle in emergency mode only response to manual mode to reset.
357 if (this->driving_mode() == Chassis::EMERGENCY_MODE &&
359 AINFO
360 << "Vehicle in EMERGENCY_MODE, only response to COMPLETE_MANUAL mode.";
361 AINFO << "Only response to RESET ACTION.";
362 return ErrorCode::CANBUS_ERROR;
363 }
364
365 // if current mode is same as previous, no need to set.
366 if (this->driving_mode() == driving_mode) {
367 return ErrorCode::OK;
368 }
369
370 switch (driving_mode) {
372 if (EnableAutoMode() != ErrorCode::OK) {
373 AERROR << "Failed to enable auto mode.";
374 return ErrorCode::CANBUS_ERROR;
375 }
376 break;
377 }
379 if (DisableAutoMode() != ErrorCode::OK) {
380 AERROR << "Failed to disable auto mode.";
381 return ErrorCode::CANBUS_ERROR;
382 }
383 break;
384 }
386 if (EnableSteeringOnlyMode() != ErrorCode::OK) {
387 AERROR << "Failed to enable steer only mode.";
388 return ErrorCode::CANBUS_ERROR;
389 }
390 break;
391 }
393 if (EnableSpeedOnlyMode() != ErrorCode::OK) {
394 AERROR << "Failed to enable speed only mode";
395 return ErrorCode::CANBUS_ERROR;
396 }
397 break;
398 }
399 default:
400 break;
401 }
402 return ErrorCode::OK;
403}
#define AINFO
Definition log.h:42

◆ Start()

◆ Stop()

◆ Update() [1/2]

template<typename SensorType >
ErrorCode apollo::canbus::VehicleController< SensorType >::Update ( const control::ControlCommand command)
virtual

update the vehicle controller.

参数
commandthe control command
返回
error_code

在文件 vehicle_controller.h406 行定义.

407 {
408 if (!is_initialized_) {
409 AERROR << "Controller is not initialized.";
410 return ErrorCode::CANBUS_ERROR;
411 }
412
413 if (control_command.has_pad_msg() && control_command.pad_msg().has_action()) {
414 ADEBUG << "Canbus received pad msg: "
415 << control_command.pad_msg().ShortDebugString();
416 const double current_timestamp = Time::Now().ToSecond();
417 // pad_msg_time_diff: s
418 const double pad_msg_time_diff =
419 current_timestamp - control_command.pad_msg().header().timestamp_sec();
420 // Execute action to transform driving mode
421 if ((FLAGS_chassis_debug_mode ||
422 (pad_msg_time_diff < FLAGS_pad_msg_delay_interval)) &&
424 if (control_command.pad_msg().action() ==
426 if (!VerifyID()) {
427 AINFO << "Response vid failed, please request again.";
428 } else {
429 AINFO << "Response vid success!";
430 }
431 } else {
433 switch (control_command.pad_msg().action()) {
436 break;
437 }
439 // In COMPLETE_MANUAL mode
440 AINFO << "Into the Reset action.";
441 break;
442 }
443 default: {
444 AERROR << "No response for this action.";
445 break;
446 }
447 }
448 auto error_code = SetDrivingMode(mode);
449 if (error_code != ErrorCode::OK) {
450 AERROR << "Failed to set driving mode.";
451 } else {
452 AINFO << "Set driving mode success.";
453 }
454 }
455 } else {
456 ADEBUG << "pad msg time out, current time interval is "
457 << pad_msg_time_diff << " s, threshold is "
458 << FLAGS_pad_msg_delay_interval << " s";
459 }
460 }
461
464 Gear(control_command.gear_location());
465 Throttle(control_command.throttle());
466 Acceleration(control_command.acceleration());
467 Speed(control_command.speed());
468 Brake(control_command.brake());
469 SetEpbBreak(control_command);
470 SetLimits();
471 }
472
475 const double steering_rate_threshold = 1.0;
476 if (control_command.steering_rate() > steering_rate_threshold) {
477 Steer(control_command.steering_target(), control_command.steering_rate());
478 } else {
479 Steer(control_command.steering_target());
480 }
481 }
482
486 control_command.has_signal()) {
487 HandleVehicleSignal(
488 ProcessCommandChange(control_command.signal(), &last_control_command_));
489 }
490
491 return ErrorCode::OK;
492}
virtual common::ErrorCode SetDrivingMode(const Chassis::DrivingMode &driving_mode)
set vehicle to appointed driving mode.
common::VehicleSignal last_control_command_
double ToSecond() const
convert time to second.
Definition time.cc:77

◆ Update() [2/2]

template<typename SensorType >
ErrorCode apollo::canbus::VehicleController< SensorType >::Update ( const external_command::ChassisCommand command)
virtual

在文件 vehicle_controller.h495 行定义.

496 {
497 if (!is_initialized_) {
498 AERROR << "Controller is not initialized.";
499 return ErrorCode::CANBUS_ERROR;
500 }
501
505 chassis_command.has_basic_signal()) {
506 HandleVehicleSignal(ProcessCommandChange(chassis_command.basic_signal(),
508 }
509
510 if (chassis_command.has_custom_operation()) {
511 auto result = HandleCustomOperation(chassis_command);
512 if (result != ErrorCode::OK) {
513 return result;
514 }
515 }
516
517 return ErrorCode::OK;
518}
common::VehicleSignal last_chassis_command_

类成员变量说明

◆ can_receiver_

template<typename SensorType >
CanReceiver<SensorType>* apollo::canbus::VehicleController< SensorType >::can_receiver_ = nullptr
protected

在文件 vehicle_controller.h216 行定义.

◆ can_sender_

template<typename SensorType >
CanSender<SensorType>* apollo::canbus::VehicleController< SensorType >::can_sender_ = nullptr
protected

在文件 vehicle_controller.h215 行定义.

◆ driving_mode_

template<typename SensorType >
Chassis::DrivingMode apollo::canbus::VehicleController< SensorType >::driving_mode_ = Chassis::COMPLETE_MANUAL
protected

在文件 vehicle_controller.h219 行定义.

◆ is_chassis_communication_error_

template<typename SensorType >
bool apollo::canbus::VehicleController< SensorType >::is_chassis_communication_error_ = false
protected

在文件 vehicle_controller.h226 行定义.

◆ is_initialized_

template<typename SensorType >
bool apollo::canbus::VehicleController< SensorType >::is_initialized_ = false
protected

在文件 vehicle_controller.h218 行定义.

◆ is_need_count_

template<typename SensorType >
bool apollo::canbus::VehicleController< SensorType >::is_need_count_ = true
protected

在文件 vehicle_controller.h223 行定义.

◆ is_reset_

template<typename SensorType >
bool apollo::canbus::VehicleController< SensorType >::is_reset_ = false
protected

在文件 vehicle_controller.h220 行定义.

◆ last_chassis_command_

template<typename SensorType >
common::VehicleSignal apollo::canbus::VehicleController< SensorType >::last_chassis_command_
protected

在文件 vehicle_controller.h211 行定义.

◆ last_control_command_

template<typename SensorType >
common::VehicleSignal apollo::canbus::VehicleController< SensorType >::last_control_command_
protected

在文件 vehicle_controller.h212 行定义.

◆ lost_chassis_reveive_detail_count_

template<typename SensorType >
uint32_t apollo::canbus::VehicleController< SensorType >::lost_chassis_reveive_detail_count_ = 0
protected

在文件 vehicle_controller.h222 行定义.

◆ message_manager_

template<typename SensorType >
MessageManager<SensorType>* apollo::canbus::VehicleController< SensorType >::message_manager_ = nullptr
protected

在文件 vehicle_controller.h217 行定义.

◆ mode_mutex_

template<typename SensorType >
std::mutex apollo::canbus::VehicleController< SensorType >::mode_mutex_
protected

在文件 vehicle_controller.h221 行定义.

◆ params_

template<typename SensorType >
canbus::VehicleParameter apollo::canbus::VehicleController< SensorType >::params_
protected

在文件 vehicle_controller.h213 行定义.

◆ sender_data_size_previous_

template<typename SensorType >
size_t apollo::canbus::VehicleController< SensorType >::sender_data_size_previous_ = 0.0
protected

在文件 vehicle_controller.h224 行定义.

◆ start_time_

template<typename SensorType >
int64_t apollo::canbus::VehicleController< SensorType >::start_time_ = 0
protected

在文件 vehicle_controller.h225 行定义.

◆ vehicle_params_

template<typename SensorType >
common::VehicleParam apollo::canbus::VehicleController< SensorType >::vehicle_params_
protected

在文件 vehicle_controller.h214 行定义.


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