bool_fun.cpp

  name="google_ads_frame" marginwidth="0" marginheight="0" src="http://pagead2.googlesyndication.com/pagead/ads?client=ca-pub-5572165936844014&dt=1194442938015&lmt=1194190197&format=336x280_as&output=html&correlator=1194442937843&url=file%3A%2F%2F%2FC%3A%2FDocuments%2520and%2520Settings%2Flhh1%2F%E6%A1%8C%E9%9D%A2%2FCLanguage.htm&color_bg=FFFFFF&color_text=000000&color_link=000000&color_url=FFFFFF&color_border=FFFFFF&ad_type=text&ga_vid=583001034.1194442938&ga_sid=1194442938&ga_hid=1942779085&flash=9&u_h=768&u_w=1024&u_ah=740&u_aw=1024&u_cd=32&u_tz=480&u_java=true" frameborder="0" width="336" scrolling="no" height="280" allowtransparency="allowtransparency"> #include <iostream.h>

bool func(void)
 {        // Function returns a bool type
   return false;
   //  return NULL;  // NULL is converted to Boolean false
 }

void main(void)
{
   bool val = false;  // Boolean variable
   int i = 1;         // i is neither Boolean-true nor Boolean-false
   int g = 3;
   int *iptr = 0;     // null pointer
   float j = 1.01;    // j is neither Boolean-true nor Boolean-false

   if (i == true)
      cout << "True: value is 1" << endl;
   if (i == false)
      cout << "False: value is 0" << endl;
   if (g)
      cout << "g is true.";
   else
      cout << "g is false.";

   // Test on pointer
   if (*iptr == false)
      cout << "Invalid pointer." << endl;
   if (*iptr == true)
      cout << "Valid pointer." << endl;

   // To test j's truth value, cast it to bool type.
   if (bool(j) == true)
      cout << "Boolean j is true." << endl;

   // Test Boolean function return value

   val = func();
   if (val == false)
      cout << "func() returned false.";
   if (val == true)
      cout << "func() returned true.";
}

/* * safety_function.cpp * Copyright Horizon * Created on: Jan 5, 2021 * Author: Peng07.li */ #include "safety-function/safety_function.h" namespace hobot_adas_function { const SafetyFunctionConfig *SafetyFunction::m_sf_cfg = nullptr; //这是一个 静态成员变量 的定义和初始化语句,属于 SafetyFunction 类 //用结构体指针对SafetyFunctionConfig的成员变量进行初始化 //nullptr:将静态指针初始化为空指针,表示初始状态下它不指向任何配置对象 SafetyFunction::SafetyFunction() noexcept : m_safety_env(),//调用 m_safety_env 成员的默认构造函数进行初始化 m_cllsn_react_ctrl( #if ENABLE_ESS_FUNC m_safety_env.GetEvasionPath(), #endif // ENABLE_ESS_FUNC //使用了条件编译 #if ENABLE_ESS_FUNC: // 如果定义了 ENABLE_ESS_FUNC 宏(通常表示启用紧急避障系统) //则传入 m_safety_env.GetEvasionPath()(获取避障路径) m_safety_env.GetEgoInstance(),//获取自车(本车)实例 m_safety_env.GetThreatAssessorInstance()),//获取威胁评估器实例 m_is_init(false) {//将初始化状态标志 m_is_init 设为 false // 表示对象刚创建时处于"未初始化"状态 } //这是一个 C++ 类 SafetyFunction 的构造函数实现,使用了成员初始化列表的方式进行初始化 // 基本结构:SafetyFunction::SafetyFunction() noexcept //: 初始化列表{ //} //noexcept 关键字表示该构造函数保证不会抛出异常 //构造函数体为空({}),所有初始化工作都在初始化列表中完成 SafetyFunction::~SafetyFunction() = default; void SafetyFunction::Init() { if (m_is_init == false) { m_is_init = true; m_safety_env.Init(); } } int SafetyFunction::SetSafetyFunctionConfig(//这是一个用于设置安全功能配置的方法,它将外部传入的配置分发到各个子模块 const SafetyFunctionConfig *sf_cfg) { int ret = -1; if (nullptr != sf_cfg) { SafetyEnvironment::ncap_status_ = static_cast<SFNcapMaskType>(sf_cfg->ncap_staus); SafetyEnvironment::aes_status = static_cast<SFAesMaskType>(sf_cfg->aes_status); SafetyEnvironment::SetSafetyEnvironmentConfig(&sf_cfg->safety_env_cfg); CllsnReactCtrl::SetCllsnReactCtrlConfig(&sf_cfg->cllsn_react_cfg); CllsnReactComSm::SetFunctionStateConfig(&sf_cfg->fun_state_cfg); CllsnReactConstraint::SetCllsnConstraintConfig( &sf_cfg->cllsn_constraint_cfg); m_sf_cfg = sf_cfg; ret = 0; #if ENABLE_ESS_FUNC EvasionCtrl::SetEvasionCtrlConfig(&sf_cfg->ctrl_cfg); #endif // ENABLE_ESS_FUNC } return ret; } void SafetyFunction::Update(const SFEgoVehicleInfo &sub_vehicle) { // m_update_mutex.lock(); if (nullptr != m_sf_cfg) { m_safety_env.Update(sub_vehicle); } /// m_update_mutex.unlock(); } void SafetyFunction::Update(const SFRoadInfo &road_info) { // m_update_mutex.lock(); if (nullptr != m_sf_cfg) { m_safety_env.Update(road_info); } // m_update_mutex.unlock(); } void SafetyFunction::Update(const SFObstacleList& obs_list) { // m_update_mutex.lock(); if (nullptr != m_sf_cfg) { m_safety_env.Update(obs_list); } // m_update_mutex.unlock(); } //这是一个用于更新威胁评估状态的方法,主要功能是通过安全环境对象(m_safety_env)进行完整的威胁评估流程, //并将结果输出到ta_status参数中 //模块化设计 //将复杂的威胁评估分解为四个清晰的子步骤 //所有实际工作委托给m_safety_env对象完成 void SafetyFunction::UpdateThreatAssessor(ThreatAssessorSta &ta_status) { // m_update_mutex.lock(); if (nullptr != m_sf_cfg) { m_safety_env.SelectKeyObstacles();//筛选出关键障碍物 m_safety_env.RoadAgentUpdate();//更新道路参与者(其他车辆/行人等)的最新信息 m_safety_env.CalcSafetyMarginFrontObjects();//计算与前方物体的安全距离裕度 m_safety_env.ThreatAssess(&ta_status);//评估威胁级别,结果输出到ta_status } else { ta_status = ThreatAssessorSta();// 无效配置时返回默认/空状态 } // m_update_mutex.unlock(); } #if ENABLE_ESS_FUNC void SafetyFunction::UpdatePlanning(const SFRoadInfo &road_info, SFPlanResult &plan_ret) { if (nullptr != m_sf_cfg) { plan_ret = m_safety_env.UpdatePlan(road_info); } else { plan_ret = SFPlanResult(); } } #endif void SafetyFunction::UpdateCllsnReact( #if ENABLE_ESS_FUNC const SFRoadInfo &road_info, const SFPlanResult &plan_ret, const ObstacleListType &obs_list, #endif // ENABLE_ESS_FUNC const ThreatAssessorSta &ta_status, SFResult &sf_ret) { if (nullptr != m_sf_cfg) { sf_ret = m_cllsn_react_ctrl.Update( #if ENABLE_ESS_FUNC road_info, plan_ret, obs_list, #endif // ENABLE_ESS_FUNC ta_status); } } void SafetyFunction::UpdateSFLSSObjInfo() { SafetyTargetSelector *ts_ptr = m_safety_env.GetTargetSelectorPtr(); if (ts_ptr != nullptr) { // todo } else { // do nothing } } void SafetyFunction::UpdateFrameInfo(const SafetyFrameInfo &frame_info) { m_safety_env.systime_diff_ = TOINT32(frame_info.sys_timestamp - m_safety_env.frame_info_.sys_timestamp); m_safety_env.frame_info_ = frame_info; } SafetyFrameInfo &SafetyFunction::GetFrameInfo() { return m_safety_env.frame_info_; } #ifdef AEB_DEBUG_LOG int SafetyFunction::GetEgoDebugInfo(SFEgoDebugInfo *ego_debug_info) { return m_safety_env.GetEgoDebugInfo(ego_debug_info); } int SafetyFunction::GetPathDebugInfo(SFPathDebugInfo *path_debug_info) { return m_safety_env.GetPathDebugInfo(path_debug_info); } int SafetyFunction::GetThreatDebugInfo( SFThreatAssessorDebugInfo *thr_ass_info) { return m_safety_env.GetThreatDebugInfo(thr_ass_info); } int SafetyFunction::GetCtrlDebugInfo(SFCtrlDebugInfo *ctrl_debug_info) { return m_cllsn_react_ctrl.GetCtrlDebugInfo(ctrl_debug_info); } #if ENABLE_ESS_FUNC int SafetyFunction::GetAesCtrlDebugInfo( SFAesCtrlInfoDebug* aes_ctrl_debug_info) { return m_cllsn_react_ctrl.GetAesCtrlDebugInfo(aes_ctrl_debug_info); } int SafetyFunction::GetAesPlanDebugInfo( SFAesPlanInfoDebug* aes_plan_debug_info) { return m_safety_env.GetAesPlanDebugInfo(aes_plan_debug_info); } int SafetyFunction::GetAesThreatDebugInfo(SFAesThreatInfoDebug* aes_threat_debug_info) { return m_safety_env.GetAesThreatInfo(aes_threat_debug_info); } int SafetyFunction::GetAesEgoDebugInfo(SFAesEgoInfoDebug* aes_ego_debug_info) { return m_safety_env.GetAesEgoInfo(aes_ego_debug_info); } int SafetyFunction::GetAesReactDebugInfo(SFAesReactInfoDebug* aes_react_debug_info) { return m_cllsn_react_ctrl.GetAesReactDebugInfo(aes_react_debug_info); } int SafetyFunction::GetAesFSMDebugInfo(SFAesFSMInfoDebug* aes_fsm_debug_info) { return m_cllsn_react_ctrl.GetAesFSMDebugInfo(aes_fsm_debug_info); } int SafetyFunction::GetAesCSMDebugInfo(SFAesCSMInfoDebug* aes_csm_debug_info) { return m_cllsn_react_ctrl.GetAesCSMDebugInfo(aes_csm_debug_info); } #endif // ENABLE_ESS_FUNC #endif // AEB_DEBUG_LOG } // namespace hobot_adas_function 用思维导图表示出来
最新发布
06-19
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值