modules/dreamview/backend/hmi/hmi.cc
// Send PadMessage to change driving mode to target mode.
// Retry for several times to try to guarantee the result.
Send PadMessage to change driving mode to target mode.
Retry for several times to try to guarantee the result.
Send PadMessage to change driving mode to target mode . Retry for several times to try to guarantee the result .
bool GuaranteeDrivingMode(const Chassis::DrivingMode target_mode,
                          const bool reset_first) {
  if (reset_first) {
    if (!GuaranteeDrivingMode(Chassis::COMPLETE_MANUAL, false)) {
      return false;
    }
  }
  control::PadMessage pad;
  switch (target_mode) {
    case Chassis::COMPLETE_MANUAL:
      pad.set_action(DrivingAction::RESET);
      break;
    case Chassis::COMPLETE_AUTO_DRIVE:
      pad.set_action(DrivingAction::START);
      break;
    default:
      AFATAL << "Unknown action to change driving mode to " << target_mode;
  }
  constexpr int kMaxTries = 3;
  constexpr auto kTryInterval = std::chrono::milliseconds(500);
  auto* chassis = CHECK_NOTNULL(AdapterManager::GetChassis());
  for (int i = 0; i < kMaxTries; ++i) {
    AdapterManager::FillPadHeader("HMI", &pad);
    AdapterManager::PublishPad(pad);
    std::this_thread::sleep_for(kTryInterval);
    chassis->Observe();
    if (chassis->Empty()) {
      AERROR << "No Chassis message received!";
    } else if (chassis->GetLatestObserved().driving_mode() == target_mode) {
      return true;
    }
  }
  AERROR << "Failed to change driving mode to " << target_mode;
  return false;
}
bool GuaranteeDrivingMode ( const Chassis :: DrivingMode target_mode , const bool reset_first ) { if ( reset_first ) { if ( ! GuaranteeDrivingMode ( Chassis :: COMPLETE_MANUAL , false ) ) { return false ; } } control :: PadMessage pad ; switch ( target_mode ) { case Chassis :: COMPLETE_MANUAL : pad . set_action ( DrivingAction :: RESET ) ; break ; case Chassis :: COMPLETE_AUTO_DRIVE : pad . set_action ( DrivingAction :: START ) ; break ; default : AFATAL << " " << target_mode ; } constexpr int kMaxTries = 3 ; constexpr auto kTryInterval = std :: chrono :: milliseconds ( 500 ) ; auto * chassis = CHECK_NOTNULL ( AdapterManager :: GetChassis ( ) ) ; for ( int i = 0 ; i < kMaxTries ; ++ i ) { AdapterManager :: FillPadHeader ( " " , & pad ) ; AdapterManager :: PublishPad ( pad ) ; std :: this_thread :: sleep_for ( kTryInterval ) ; chassis -> Observe ( ) ; if ( chassis -> Empty ( ) ) { AERROR << " " ; } else if ( chassis -> GetLatestObserved ( ) . driving_mode ( ) == target_mode ) { return true ; } } AERROR << " " << target_mode ; return false ; }
Send PadMessage to change driving mode to target mode.
Send PadMessage to change driving mode to target mode .
// Send driving action periodically until entering target driving mode.