12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310 |
- //
- // Created by huli on 2020/7/2.
- //
- #include "system_executor.h"
- // std::ofstream g_debug_file; // 用于测试滤波功能
- System_executor::System_executor()
- {
- }
- System_executor::~System_executor()
- {
- system_executor_uninit();
- }
- //初始化
- Error_manager System_executor::system_executor_init(int threads_size, int terminal_id)
- {
- m_thread_pool.thread_pool_init(threads_size);
- m_system_executor_status = SYSTEM_EXECUTOR_READY;
- m_terminal_id = terminal_id;
- PathCreator pc;
- pc.Mkdir("./log/");
- return Error_code::SUCCESS;
- }
- //反初始化
- Error_manager System_executor::system_executor_uninit()
- {
- // if(g_debug_file.is_open())
- // g_debug_file.close();
- m_thread_pool.thread_pool_uninit();
- m_system_executor_status = SYSTEM_EXECUTOR_UNKNOW;
- return Error_code::SUCCESS;
- }
- //检查消息是否有效, 主要检查消息类型和接受者, 判断这条消息是不是给我的.
- Error_manager System_executor::check_msg(Communication_message* p_msg)
- {
- if ( p_msg == NULL )
- {
- return Error_manager(Error_code::POINTER_IS_NULL, Error_level::MINOR_ERROR,
- " POINTER IS NULL ");
- }
- //检查消息类型
- switch ( p_msg->get_message_type() )
- {
- case Communication_message::Message_type::eGround_detect_request_msg:
- {
- //检查接受人
- if ( p_msg->get_receiver() == Communication_message::Communicator::eGround_measurer)
- {
- message::Ground_detect_request_msg t_ground_detect_request_msg;
- //针对消息类型, 对消息进行二次解析
- if (t_ground_detect_request_msg.ParseFromString(p_msg->get_message_buf()))
- {
- // //检查终端id
- // 普爱不检查终端id
- // 楚天检查终端id
- // if ( t_ground_detect_request_msg.terminal_id() == m_terminal_id )
- // {
- return Error_code::SUCCESS;
- // }
- }
- }
- break;
- }
- default :
- ;
- break;
- }
- //无效的消息,
- return Error_manager(Error_code::INVALID_MESSAGE, Error_level::NEGLIGIBLE_ERROR,
- " INVALID_MESSAGE error ");
- }
- //检查执行者的状态, 判断能否处理这条消息,
- Error_manager System_executor::check_executer(Communication_message* p_msg)
- {
- //huli DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD 记得删除
- return Error_code::SUCCESS;
- if ( p_msg == NULL )
- {
- return Error_manager(Error_code::POINTER_IS_NULL, Error_level::MINOR_ERROR,
- " POINTER IS NULL ");
- }
- Error_manager t_error;
- //通过 p_msg->get_message_type() 和 p_msg->get_receiver() 找到处理模块的实例对象, 查询执行人是否可以处理这条消息
- switch ( p_msg->get_message_type() )
- {
- case Communication_message::Message_type::eGround_detect_request_msg:
- {
- Error_manager t_executor_result = System_executor::get_instance_references().check_status();
- if (t_executor_result == SUCCESS)
- {
- return Error_code::SUCCESS;
- }
- else
- {
- //整合所有的错误码
- t_error.compare_and_cover_error(t_executor_result);
- if (t_error.get_error_level() == NEGLIGIBLE_ERROR)//一级故障,轻微故障,
- {
- LOG(INFO) << "executer_is_busy , ";
- //返回繁忙之后, 通信模块1秒后再次调用check
- return Error_code::COMMUNICATION_EXCUTER_IS_BUSY;
- }
- else//返回二级故障,可以封装一条答复信息, 返回错误码
- {
- message::Ground_detect_request_msg t_ground_detect_request_msg;
- //针对消息类型, 对消息进行二次解析
- if (t_ground_detect_request_msg.ParseFromString(p_msg->get_message_buf()))
- {
- //创建一条答复消息
- message::Ground_detect_response_msg t_ground_detect_response_msg;
- t_ground_detect_response_msg.mutable_base_info()->set_msg_type(message::Message_type::eGround_detect_response_msg);
- t_ground_detect_response_msg.mutable_base_info()->set_timeout_ms(5000);
- t_ground_detect_response_msg.mutable_base_info()->set_sender(message::Communicator::eGround_measurer);
- t_ground_detect_response_msg.mutable_base_info()->set_receiver(message::Communicator::eMain);
- t_ground_detect_response_msg.set_command_key(t_ground_detect_request_msg.command_key());
- t_ground_detect_response_msg.mutable_id_struct()->set_terminal_id(t_ground_detect_request_msg.id_struct().terminal_id());
- t_ground_detect_response_msg.mutable_error_manager()->set_error_code(t_error.get_error_code());
- t_ground_detect_response_msg.mutable_error_manager()->set_error_level((message::Error_level)t_error.get_error_level());
- t_ground_detect_response_msg.mutable_error_manager()->set_error_description(t_error.get_error_description());
- std::string t_msg = t_ground_detect_response_msg.SerializeAsString();
- System_communication::get_instance_references().encapsulate_msg(t_msg);
- LOG(INFO) << " System_executor::check_executer executer status error "<< this;
- return t_error;
- }
- else
- {
- LOG(INFO) << " System_executor::check_executer second PARSE_ERROR "<< this;
- return Error_manager(Error_code::SYSTEM_EXECUTOR_PARSE_ERROR, Error_level::MINOR_ERROR,
- " message::Measure_request_msg ParseFromString error ");
- }
- }
- }
- break;
- }
- default :
- ;
- break;
- }
- return t_error;
- }
- //处理消息的执行函数
- Error_manager System_executor::execute_msg(Communication_message* p_msg)
- {
- if ( p_msg == NULL )
- {
- return Error_manager(Error_code::POINTER_IS_NULL, Error_level::MINOR_ERROR,
- " POINTER IS NULL ");
- }
- // std::cout << " huli test ::333333333333333333333333333333:: " << " p_msg->get_message_type() = " << p_msg->get_message_type() << std::endl;
- switch ( p_msg->get_message_type() )
- {
- case Communication_message::eGround_detect_request_msg:
- {
- message::Ground_detect_request_msg t_ground_detect_request_msg;
- //针对消息类型, 对消息进行二次解析
- if (t_ground_detect_request_msg.ParseFromString(p_msg->get_message_buf()) && t_ground_detect_request_msg.id_struct().has_terminal_id())
- {
- //往线程池添加执行任务, 之后会唤醒一个线程去执行他.
- m_thread_pool.enqueue(&System_executor::execute_for_measure, this,
- t_ground_detect_request_msg.command_key(), t_ground_detect_request_msg.id_struct().terminal_id(),
- p_msg->get_receive_time());
- }
- else
- {
- return Error_manager(Error_code::SYSTEM_EXECUTOR_PARSE_ERROR, Error_level::MINOR_ERROR,
- " message::Measure_request_msg ParseFromString error ");
- }
- break;
- }
- default:
- {
- }
- }
- return Error_code::SUCCESS;
- }
- //检查状态
- Error_manager System_executor::check_status()
- {
- if ( m_system_executor_status == SYSTEM_EXECUTOR_READY )
- {
- if ( m_thread_pool.thread_is_full_load() == false )
- {
- return Error_code::SUCCESS;
- }
- else
- {
- return Error_manager(Error_code::SYSTEM_EXECUTOR_STATUS_BUSY, Error_level::NEGLIGIBLE_ERROR,
- " System_executor::check_status error ");
- }
- }
- else
- {
- return Error_manager(Error_code::SYSTEM_EXECUTOR_STATUS_ERROR, Error_level::MINOR_ERROR,
- " System_executor::check_status error ");
- }
- }
- int System_executor::transMeasureStatus(const int &measure_status) {
- switch (measure_status) {
- case message::Ground_statu::Car_correct:
- return 0;
- case message::Ground_statu::Nothing:
- return 1;
- case message::Ground_statu::Noise:
- return 2;
- case message::Ground_statu::Car_border_reached:
- return 3;
- default:
- return 2;
- }
- }
- // 更新消息中关于定位结果与超界信息的内容
- bool System_executor::update_measure_info(message::Ground_status_msg &msg, Common_data::Car_wheel_information &measure_info, int cloud_size)
- {
- Error_manager t_error;
- //无论定位结果如何, 都要填充数据, 即使全部写0, 必须保证通信格式正确.
- message::Locate_information t_locate_information;
- //= t_multi_status_msg.add_locate_information_realtime();
- t_locate_information.set_locate_x(measure_info.car_center_x);
- t_locate_information.set_locate_y(measure_info.car_center_y);
- t_locate_information.set_locate_angle(measure_info.car_angle);
- t_locate_information.set_locate_length(0);
- t_locate_information.set_locate_width(0);
- t_locate_information.set_locate_height(0);
- t_locate_information.set_locate_wheel_base(measure_info.car_wheel_base);
- t_locate_information.set_locate_wheel_width(measure_info.car_wheel_width);
- t_locate_information.set_locate_front_theta(measure_info.car_front_theta);
- t_locate_information.set_locate_correct(measure_info.correctness);
- t_locate_information.set_uniformed_car_x(measure_info.uniform_car_x);
- t_locate_information.set_uniformed_car_y(measure_info.uniform_car_y);
- msg.mutable_locate_information_realtime()->CopyFrom(t_locate_information);
- // 当前超界提示仅保留一项
- // 20211026已修改,分离为电子围栏状态与超界状态,只有测量正确时超界状态才有意义
- msg.set_border_status(measure_info.range_status);
- if (!measure_info.correctness)
- {
- if (cloud_size > 0)
- msg.set_ground_status(message::Ground_statu::Noise);
- else
- msg.set_ground_status(message::Ground_statu::Nothing);
- }
- else if (measure_info.range_status == int(Ground_region::Range_status::Range_correct))
- {
- msg.set_ground_status(message::Ground_statu::Car_correct);
- }
- else
- {
- msg.set_ground_status(message::Ground_statu::Car_border_reached);
- // 更新待提示错误信息
- std::string t_error_str;
- if (measure_info.range_status & Ground_region::Range_status::Range_front != 0)
- {
- t_error_str.append("前超界 ");
- }
- if (measure_info.range_status & Ground_region::Range_status::Range_back != 0)
- {
- t_error_str.append("后超界 ");
- }
- if (measure_info.range_status & Ground_region::Range_status::Range_left != 0)
- {
- t_error_str.append("左超界 ");
- }
- if (measure_info.range_status & Ground_region::Range_status::Range_right != 0)
- {
- t_error_str.append("右超界 ");
- }
- if (measure_info.range_status & Ground_region::Range_status::Range_bottom != 0)
- {
- t_error_str.append("底盘超界 ");
- }
- if (measure_info.range_status & Ground_region::Range_status::Range_top != 0)
- {
- t_error_str.append("顶超界 ");
- }
- if (measure_info.range_status & Ground_region::Range_status::Range_car_width != 0)
- {
- t_error_str.append("车宽超界 ");
- }
- if (measure_info.range_status & Ground_region::Range_status::Range_car_wheelbase != 0)
- {
- t_error_str.append("轴距超界 ");
- }
- if (measure_info.range_status & Ground_region::Range_status::Range_angle_anti_clock != 0)
- {
- t_error_str.append("车辆角度左超界 ");
- }
- if (measure_info.range_status & Ground_region::Range_status::Range_angle_clock != 0)
- {
- t_error_str.append("车辆角度右超界 ");
- }
- if (measure_info.range_status & Ground_region::Range_status::Range_steering_wheel_nozero != 0)
- {
- t_error_str.append("车辆前轮角超界 ");
- }
- t_error.set_error_description(t_error_str);
- }
- msg.mutable_error_manager()->set_error_code(t_error.get_error_code());
- msg.mutable_error_manager()->set_error_level((message::Error_level)t_error.get_error_level());
- msg.mutable_error_manager()->set_error_description(t_error.get_error_description());
- return true;
- }
- // 更新消息中关于定位结果与超界信息的内容
- bool System_executor::update_terminal_measure_info(message::Ground_status_msg &msg, Common_data::Car_wheel_information &measure_info, int cloud_size)
- {
- Error_manager t_error;
- //无论定位结果如何, 都要填充数据, 即使全部写0, 必须保证通信格式正确.
- message::Locate_information t_locate_information;
- //= t_multi_status_msg.add_locate_information_realtime();
- t_locate_information.set_locate_x(measure_info.car_center_x);
- t_locate_information.set_locate_y(measure_info.car_center_y);
- t_locate_information.set_locate_angle(measure_info.car_angle);
- t_locate_information.set_locate_length(0);
- t_locate_information.set_locate_width(0);
- t_locate_information.set_locate_height(0);
- t_locate_information.set_locate_wheel_base(measure_info.car_wheel_base);
- t_locate_information.set_locate_wheel_width(measure_info.car_wheel_width);
- t_locate_information.set_locate_front_theta(measure_info.car_front_theta);
- t_locate_information.set_locate_correct(measure_info.correctness);
- t_locate_information.set_uniformed_car_x(measure_info.uniform_car_x);
- t_locate_information.set_uniformed_car_y(measure_info.uniform_car_y);
- msg.mutable_locate_information_realtime()->CopyFrom(t_locate_information);
- // 当前超界提示仅保留一项
- // 20211026已修改,分离为电子围栏状态与超界状态,只有测量正确时超界状态才有意义
- msg.set_border_status(measure_info.terminal_range_status);
- if (!measure_info.correctness)
- {
- if (cloud_size > 0)
- msg.set_ground_status(message::Ground_statu::Noise);
- else
- msg.set_ground_status(message::Ground_statu::Nothing);
- }
- else if (measure_info.terminal_range_status == int(Ground_region::Range_status::Range_correct))
- {
- msg.set_ground_status(message::Ground_statu::Car_correct);
- }
- else
- {
- msg.set_ground_status(message::Ground_statu::Car_border_reached);
- // 更新待提示错误信息
- std::string t_error_str;
- if (measure_info.terminal_range_status & Ground_region::Range_status::Range_front != 0)
- {
- t_error_str.append("前超界 ");
- }
- if (measure_info.terminal_range_status & Ground_region::Range_status::Range_back != 0)
- {
- t_error_str.append("后超界 ");
- }
- if (measure_info.terminal_range_status & Ground_region::Range_status::Range_left != 0)
- {
- t_error_str.append("左超界 ");
- }
- if (measure_info.terminal_range_status & Ground_region::Range_status::Range_right != 0)
- {
- t_error_str.append("右超界 ");
- }
- if (measure_info.terminal_range_status & Ground_region::Range_status::Range_bottom != 0)
- {
- t_error_str.append("底盘超界 ");
- }
- if (measure_info.terminal_range_status & Ground_region::Range_status::Range_top != 0)
- {
- t_error_str.append("顶超界 ");
- }
- if (measure_info.terminal_range_status & Ground_region::Range_status::Range_car_width != 0)
- {
- t_error_str.append("车宽超界 ");
- }
- if (measure_info.terminal_range_status & Ground_region::Range_status::Range_car_wheelbase != 0)
- {
- t_error_str.append("轴距超界 ");
- }
- if (measure_info.terminal_range_status & Ground_region::Range_status::Range_angle_anti_clock != 0)
- {
- t_error_str.append("车辆角度左超界 ");
- }
- if (measure_info.terminal_range_status & Ground_region::Range_status::Range_angle_clock != 0)
- {
- t_error_str.append("车辆角度右超界 ");
- }
- if (measure_info.terminal_range_status & Ground_region::Range_status::Range_steering_wheel_nozero != 0)
- {
- t_error_str.append("车辆前轮角超界 ");
- }
- t_error.set_error_description(t_error_str);
- }
- msg.mutable_error_manager()->set_error_code(t_error.get_error_code());
- msg.mutable_error_manager()->set_error_level((message::Error_level)t_error.get_error_level());
- msg.mutable_error_manager()->set_error_description(t_error.get_error_description());
- return true;
- }
- // ***************************** rabbitmq *********************************
- Error_manager System_executor::encapsulate_send_mq_status()
- {
- static int cloud_count=-1;
- cloud_count++;
- // if(!g_debug_file.is_open())
- // {
- // g_debug_file.open("./filter_debug_result.txt", std::ios::app);
- // }
- Error_manager t_error;
- //创建一条状态消息
- message::Ground_status_msg t_ground_status_msg;
- t_ground_status_msg.mutable_base_info()->set_msg_type(message::Message_type::eGround_status_msg);
- t_ground_status_msg.mutable_base_info()->set_timeout_ms(5000);
- t_ground_status_msg.mutable_base_info()->set_sender(message::Communicator::eGround_measurer);
- t_ground_status_msg.mutable_base_info()->set_receiver(message::Communicator::eEmpty);
- // t_ground_status_msg.set_terminal_id(m_terminal_id);
- t_ground_status_msg.mutable_id_struct()->set_terminal_id(m_terminal_id);
- // 创建各区域状态消息,
- // 注意!!!目前公共消息名字依旧使用wj,不做修改
- // manager
- #if WJ_VELO == 1
- {
- Velodyne_manager::Velodyne_manager_status t_velodyne_manager_status = Velodyne_manager::get_instance_references().get_status();
- t_ground_status_msg.set_wanji_manager_status((message::Wanji_manager_status)t_velodyne_manager_status);
- // lidar
- std::map<int, Velodyne_lidar_device *> t_velodyne_lidar_device_map = Velodyne_manager::get_instance_references().get_velodyne_lidar_device_map();
- std::map<int, Velodyne_lidar_device::Velodyne_lidar_device_status> t_velodyne_lidar_status_map;
- for (auto iter = t_velodyne_lidar_device_map.begin(); iter != t_velodyne_lidar_device_map.end(); ++iter)
- {
- t_velodyne_lidar_status_map.emplace(std::pair<int, Velodyne_lidar_device::Velodyne_lidar_device_status>(iter->second->get_lidar_id(), iter->second->get_status()));
- }
- // region
- std::map<int, Ground_region *> t_ground_region_map = Velodyne_manager::get_instance_references().get_ground_region_map();
- int region_index = 0;
- for (auto iter = t_ground_region_map.begin(); iter != t_ground_region_map.end(); ++iter)
- {
- // 以t_ground_status_msg为模板创建各区域心跳消息
- message::Ground_status_msg t_multi_status_msg;
- t_multi_status_msg.CopyFrom(t_ground_status_msg);
- t_multi_status_msg.mutable_id_struct()->set_terminal_id(iter->second->get_terminal_id());
- t_multi_status_msg.set_region_worker_status((message::Region_worker_status)(iter->second->get_status()));
- velodyne::Region t_param = iter->second->get_param();
- for (size_t j = 0; j < t_param.lidar_exts_size(); j++)
- {
- std::map<int, Velodyne_lidar_device::Velodyne_lidar_device_status>::iterator t_status_iter = t_velodyne_lidar_status_map.find(t_param.lidar_exts(j).lidar_id());
- if (t_status_iter == t_velodyne_lidar_status_map.end())
- {
- LOG(WARNING) << "lidar status " << t_param.lidar_exts(j).lidar_id() << " cannot be found, param error";
- }
- else
- {
- t_multi_status_msg.add_wanji_lidar_device_status((message::Wanji_lidar_device_status)t_status_iter->second);
- }
- }
- //velodyne雷达的自动定位信息
- Common_data::Car_wheel_information t_car_wheel_information;
- t_error = (*iter).second->get_last_wheel_information(&t_car_wheel_information, std::chrono::system_clock::now());
- // 获取区域点云填入信息
- pcl::PointCloud<pcl::PointXYZ>::Ptr t_region_cloud = pcl::PointCloud<pcl::PointXYZ>::Ptr(new pcl::PointCloud<pcl::PointXYZ>);
- iter->second->get_region_cloud(t_region_cloud, Ground_region::Region_cloud_type::filtered);
- if (cloud_count == 5)
- {
- std::string t_filename = std::string("region_") + std::to_string(iter->first) + "_cloud.txt";
- save_cloud_txt(t_region_cloud, t_filename);
- LOG(INFO) << "region " << iter->first << " cloud has been saved in " + t_filename;
- }
- // for (size_t j = 0; j < t_region_cloud->size(); j++)
- // {
- // message::Cloud_coordinate *tp_cloud = t_multi_status_msg.add_cloud();
- // tp_cloud->set_x(t_region_cloud->points[j].x);
- // tp_cloud->set_y(t_region_cloud->points[j].y);
- // tp_cloud->set_z(t_region_cloud->points[j].z);
- // }
- update_measure_info(t_multi_status_msg, t_car_wheel_information, t_region_cloud->size());
- std::string t_msg = t_multi_status_msg.SerializeAsString();
- System_communication::get_instance_references().encapsulate_msg(t_msg);
- if (t_multi_status_msg.id_struct().terminal_id() == DISP_TERM_ID)
- std::cout << t_multi_status_msg.DebugString() << std::endl
- << std::endl;
- }
- }
- #elif WJ_VELO == 0
- {
- // wj_support 20220718
- Wanji_manager::Wanji_manager_status t_wj_manager_status = Wanji_manager::get_instance_references().get_status();
- t_ground_status_msg.set_wanji_manager_status((message::Wanji_manager_status)t_wj_manager_status);
- // lidar
- std::map<int, Wanji_lidar_device *> t_wj_lidar_device_map = Wanji_manager::get_instance_references().get_wanji_lidar_device_map();
- std::map<int, Wanji_lidar_device::Wanji_lidar_device_status> t_wj_lidar_status_map;
- for (auto iter = t_wj_lidar_device_map.begin(); iter != t_wj_lidar_device_map.end(); ++iter)
- {
- t_wj_lidar_status_map.emplace(std::pair<int, Wanji_lidar_device::Wanji_lidar_device_status>(iter->second->get_lidar_id(), iter->second->get_status()));
- }
- // region
- std::map<int, Region_worker *> t_region_worker_map = Wanji_manager::get_instance_references().get_region_worker_map();
- int region_index = 0;
- for (auto iter = t_region_worker_map.begin(); iter != t_region_worker_map.end(); ++iter)
- {
- // 以t_ground_status_msg为模板创建各区域心跳消息
- message::Ground_status_msg t_multi_status_msg;
- t_multi_status_msg.CopyFrom(t_ground_status_msg);
- t_multi_status_msg.mutable_id_struct()->set_terminal_id(iter->second->get_terminal_id());
- t_multi_status_msg.set_region_worker_status((message::Region_worker_status)(iter->second->get_status()));
- wj::Region t_param = iter->second->get_param();
- for (size_t j = 0; j < t_param.lidar_exts_size(); j++)
- {
- std::map<int, Wanji_lidar_device::Wanji_lidar_device_status>::iterator t_status_iter = t_wj_lidar_status_map.find(t_param.lidar_exts(j).lidar_id());
- if (t_status_iter == t_wj_lidar_status_map.end())
- {
- LOG(WARNING) << "lidar status " << t_param.lidar_exts(j).lidar_id() << " cannot be found, param error";
- }
- else
- {
- t_multi_status_msg.add_wanji_lidar_device_status((message::Wanji_lidar_device_status)t_status_iter->second);
- }
- }
- //velodyne雷达的自动定位信息
- Common_data::Car_wheel_information t_car_wheel_information;
- t_error = (*iter).second->get_last_wheel_information(&t_car_wheel_information, std::chrono::system_clock::now());
- // 获取区域点云填入信息
- pcl::PointCloud<pcl::PointXYZ>::Ptr t_region_cloud = pcl::PointCloud<pcl::PointXYZ>::Ptr(new pcl::PointCloud<pcl::PointXYZ>);
- iter->second->get_region_cloud(t_region_cloud);
- if (cloud_count == 5)
- {
- std::string t_filename = std::string("region_") + std::to_string(iter->first) + "_cloud.txt";
- save_cloud_txt(t_region_cloud, t_filename);
- LOG(INFO) << "region " << iter->first << " cloud has been saved in " + t_filename;
- }
- // for (size_t j = 0; j < t_region_cloud->size(); j++)
- // {
- // message::Cloud_coordinate *tp_cloud = t_multi_status_msg.add_cloud();
- // tp_cloud->set_x(t_region_cloud->points[j].x);
- // tp_cloud->set_y(t_region_cloud->points[j].y);
- // tp_cloud->set_z(t_region_cloud->points[j].z);
- // }
- update_measure_info(t_multi_status_msg, t_car_wheel_information, t_region_cloud->size());
- std::string t_msg = t_multi_status_msg.SerializeAsString();
- System_communication::get_instance_references().encapsulate_msg(t_msg);
- if (t_multi_status_msg.id_struct().terminal_id() == DISP_TERM_ID)
- LOG(INFO) << t_multi_status_msg.DebugString();
- }
- }
- // std::cout << " huli test :::: " << " t_ground_status_msg.DebugString() = " << std::endl;
- // std::cout << t_ground_status_msg.DebugString() << std::endl;
- // std::cout << " huli test :::: " << " t_ground_status_msg.DebugString() = " << t_ground_status_msg.DebugString() << std::endl;
- #else
- {
- // mix vlp16 and wj716
- // 以多线雷达为主
- Velodyne_manager::Velodyne_manager_status t_velodyne_manager_status = Velodyne_manager::get_instance_references().get_status();
- t_ground_status_msg.set_wanji_manager_status((message::Wanji_manager_status)t_velodyne_manager_status);
- // vlp16 lidar
- std::map<int, Velodyne_lidar_device *> t_velodyne_lidar_device_map = Velodyne_manager::get_instance_references().get_velodyne_lidar_device_map();
- std::map<int, Velodyne_lidar_device::Velodyne_lidar_device_status> t_velodyne_lidar_status_map;
- for (auto iter = t_velodyne_lidar_device_map.begin(); iter != t_velodyne_lidar_device_map.end(); ++iter)
- {
- t_velodyne_lidar_status_map.emplace(std::pair<int, Velodyne_lidar_device::Velodyne_lidar_device_status>(iter->second->get_lidar_id(), iter->second->get_status()));
- }
- // wj lidar
- #if LIDAR_TYPE == 1
- std::map<int, Wanji_lidar_device *> t_wj_lidar_device_map = Wanji_manager::get_instance_references().get_wanji_lidar_device_map();
- std::map<int, Wanji_lidar_device::Wanji_lidar_device_status> t_wj_lidar_status_map;
- for (auto iter = t_wj_lidar_device_map.begin(); iter != t_wj_lidar_device_map.end(); ++iter)
- {
- t_wj_lidar_status_map.emplace(std::pair<int, Wanji_lidar_device::Wanji_lidar_device_status>(iter->second->get_lidar_id(), iter->second->get_status()));
- }
- #else
- std::map<int, Wanji_716N_lidar_device *> t_wj_lidar_device_map = Wanji_manager::get_instance_references().get_wanji_lidar_device_map();
- std::map<int, Wanji_716N_lidar_device::Wanji_716N_device_status> t_wj_lidar_status_map;
- for (auto iter = t_wj_lidar_device_map.begin(); iter != t_wj_lidar_device_map.end(); ++iter)
- {
- t_wj_lidar_status_map.emplace(std::pair<int, Wanji_716N_lidar_device::Wanji_716N_device_status>(iter->second->get_lidar_id(), iter->second->get_status()));
- }
- #endif
-
-
- // wj region
- std::map<int, Region_worker *> t_region_worker_map = Wanji_manager::get_instance_references().get_region_worker_map();
- // vlp16 region
- std::map<int, Ground_region *> t_ground_region_map = Velodyne_manager::get_instance_references().get_ground_region_map();
- int region_index = 0;
- for (auto iter = t_ground_region_map.begin(); iter != t_ground_region_map.end(); ++iter)
- {
- // 以t_ground_status_msg为模板创建各区域心跳消息
- message::Ground_status_msg t_multi_status_msg;
- t_multi_status_msg.CopyFrom(t_ground_status_msg);
- t_multi_status_msg.mutable_id_struct()->set_terminal_id(iter->second->get_terminal_id());
- t_multi_status_msg.set_region_worker_status((message::Region_worker_status)(iter->second->get_status()));
- // 查找多线区域内对应多线激光雷达
- velodyne::Region t_param = iter->second->get_param();
- for (size_t j = 0; j < t_param.lidar_exts_size(); j++)
- {
- std::map<int, Velodyne_lidar_device::Velodyne_lidar_device_status>::iterator t_status_iter = t_velodyne_lidar_status_map.find(t_param.lidar_exts(j).lidar_id());
- if (t_status_iter == t_velodyne_lidar_status_map.end())
- {
- LOG(WARNING) << "vlp16 lidar status " << t_param.lidar_exts(j).lidar_id() << " cannot be found, param error";
- }
- else
- {
- t_multi_status_msg.add_wanji_lidar_device_status((message::Wanji_lidar_device_status)t_status_iter->second);
- }
- }
- //velodyne雷达的自动定位信息
- Common_data::Car_wheel_information t_car_wheel_information;
- t_error = (*iter).second->get_last_wheel_information(&t_car_wheel_information, std::chrono::system_clock::now());
- // 获取区域点云填入信息
- pcl::PointCloud<pcl::PointXYZ>::Ptr t_region_cloud = pcl::PointCloud<pcl::PointXYZ>::Ptr(new pcl::PointCloud<pcl::PointXYZ>);
- iter->second->get_region_cloud(t_region_cloud, Ground_region::Region_cloud_type::filtered);
- if (cloud_count == 10)
- {
- std::string t_filename = std::string("vlp16_region_") + std::to_string(iter->first) + "_cloud.txt";
- save_cloud_txt(t_region_cloud, t_filename);
- LOG(INFO) << " vlp16 region " << iter->first << " cloud has been saved in " + t_filename;
- }
- // for (size_t j = 0; j < t_region_cloud->size(); j++)
- // {
- // message::Cloud_coordinate *tp_cloud = t_multi_status_msg.add_cloud();
- // tp_cloud->set_x(t_region_cloud->points[j].x);
- // tp_cloud->set_y(t_region_cloud->points[j].y);
- // tp_cloud->set_z(t_region_cloud->points[j].z);
- // }
- // 检查vlp16区域与wj区域对应关系,wj存在对应区域则填充设备状态,并融合测量结果
- auto t_wj_region_iter = t_region_worker_map.find(iter->first);
- if(t_wj_region_iter != t_region_worker_map.end())
- {
- wj::Region t_param = t_wj_region_iter->second->get_param();
- //
- for (size_t j = 0; j < t_param.lidar_exts_size(); j++)
- {
- #if LIDAR_TYPE == 1
- std::map<int, Wanji_lidar_device::Wanji_lidar_device_status>::iterator t_status_iter = t_wj_lidar_status_map.find(t_param.lidar_exts(j).lidar_id());
- #else
- std::map<int, Wanji_716N_lidar_device::Wanji_716N_device_status>::iterator t_status_iter = t_wj_lidar_status_map.find(t_param.lidar_exts(j).lidar_id());
- #endif
- if (t_status_iter == t_wj_lidar_status_map.end())
- {
- LOG(WARNING) << "wj lidar status " << t_param.lidar_exts(j).lidar_id() << " cannot be found, param error";
- }
- else
- {
- t_multi_status_msg.add_wanji_lidar_device_status((message::Wanji_lidar_device_status)t_status_iter->second);
- }
- }
- //wj雷达的自动定位信息
- Common_data::Car_wheel_information t_wj_car_wheel_information;
- t_error = t_wj_region_iter->second->get_last_wheel_information(&t_wj_car_wheel_information, std::chrono::system_clock::now());
- // 获取区域点云填入信息
- pcl::PointCloud<pcl::PointXYZ>::Ptr t_wj_region_cloud = pcl::PointCloud<pcl::PointXYZ>::Ptr(new pcl::PointCloud<pcl::PointXYZ>);
- t_wj_region_iter->second->get_region_cloud(t_wj_region_cloud);
- if (cloud_count == 8)
- {
- std::string t_filename = std::string("wj_region_") + std::to_string(t_wj_region_iter->first) + "_cloud.txt";
- save_cloud_txt(t_wj_region_cloud, t_filename);
- LOG(INFO) << "wj region " << t_wj_region_iter->first << " cloud has been saved in " + t_filename;
- }
- // for (size_t j = 0; j < t_wj_region_cloud->size(); j++)
- // {
- // message::Cloud_coordinate *tp_cloud = t_multi_status_msg.add_cloud();
- // tp_cloud->set_x(t_wj_region_cloud->points[j].x);
- // tp_cloud->set_y(t_wj_region_cloud->points[j].y);
- // tp_cloud->set_z(t_wj_region_cloud->points[j].z);
- // }
- // LOG_IF(WARNING, iter->second->get_terminal_id() == DISP_TERM_ID)<<"\n"<<t_car_wheel_information.to_string()<<"\n"
- // <<t_wj_car_wheel_information.to_string()<<"\n"
- // <<t_car_wheel_information.range_status<<", "<<t_wj_car_wheel_information.range_status;
- // 融合测量结果,验证中心点差异x<0.03, y<0.06, 角度差异ang<0.6, 轴距差异wb<0.055
- double dx = t_car_wheel_information.car_center_x - t_wj_car_wheel_information.car_center_x;
- double dy = t_car_wheel_information.car_center_y - t_wj_car_wheel_information.car_center_y;
- double dang = t_car_wheel_information.car_angle - t_wj_car_wheel_information.car_angle;
- double dwb = t_car_wheel_information.car_wheel_base - t_wj_car_wheel_information.car_wheel_base;
- if(fabs(dx) < 0.03 && fabs(dy) < 0.06 && fabs(dang) < 0.6 && fabs(dwb) < 0.055)
- {
- t_car_wheel_information.car_wheel_base = t_car_wheel_information.car_wheel_base*0.3 + t_car_wheel_information.car_wheel_base*0.7;
- }else
- {
- LOG_IF(WARNING, iter->second->get_terminal_id() == DISP_TERM_ID)<<
- "detect mismatch, region "<<iter->first<<", dx dy dang dwb: "<<dx<<", "<<dy<<", "<<dang<<", "<< dwb << std::endl
- << t_car_wheel_information.to_string() << std::endl
- << t_wj_car_wheel_information.to_string() << std::endl;
- }
- }else{
- LOG_IF(WARNING, iter->second->get_terminal_id() == DISP_TERM_ID)<<"region mismatch, vlp16 "<<iter->first<<", wj doesn't have corresponding region id";
- }
- int rabbit_send_status_msg_id = t_multi_status_msg.id_struct().terminal_id();
- int rabbit_send_terminal_status_msg_id = t_multi_status_msg.id_struct().terminal_id() + 6; // 6是因为目前楚天plc有六个队列
- message::Ground_status_msg t_multi_terminal_status_msg = t_multi_status_msg;
- update_measure_info(t_multi_status_msg, t_car_wheel_information, t_region_cloud->size());
- update_terminal_measure_info(t_multi_terminal_status_msg, t_car_wheel_information, t_region_cloud->size());
- if(t_multi_status_msg.id_struct().terminal_id() == 4 ||
- t_multi_status_msg.id_struct().terminal_id() == 0||
- t_multi_status_msg.id_struct().terminal_id() == 5||
- t_multi_status_msg.id_struct().terminal_id() == 1||
- t_multi_status_msg.id_struct().terminal_id() == 3||
- t_multi_status_msg.id_struct().terminal_id() == 2)
- {
- // plc测量结果转换
- measure_info t_multi_measure_info_msg;
- t_multi_measure_info_msg.set_cx(t_car_wheel_information.uniform_car_x);
- t_multi_measure_info_msg.set_cy(t_car_wheel_information.uniform_car_y);
- t_multi_measure_info_msg.set_theta(t_car_wheel_information.car_angle);
- t_multi_measure_info_msg.set_length(0.0f);
- t_multi_measure_info_msg.set_width(t_car_wheel_information.car_wheel_width);
- t_multi_measure_info_msg.set_height(0.0f);
- t_multi_measure_info_msg.set_wheelbase(t_car_wheel_information.car_wheel_base);
- t_multi_measure_info_msg.set_front_theta(t_car_wheel_information.car_front_theta);
- t_multi_measure_info_msg.set_border_statu(t_car_wheel_information.range_status);
- // 终端测量结果copy,只改变超界状态
- measure_info t_multi_terminal_measure_info_msg;
- t_multi_terminal_measure_info_msg = t_multi_measure_info_msg;
- t_multi_terminal_measure_info_msg.set_border_statu(t_car_wheel_information.terminal_range_status);
- // 变更超界状态,因为发出去的和旧的状态不太一样
- t_multi_measure_info_msg.set_ground_status(transMeasureStatus(t_multi_status_msg.ground_status()));
- t_multi_terminal_measure_info_msg.set_ground_status(transMeasureStatus(t_multi_terminal_status_msg.ground_status()));
- // 分别发送到两个队列
- System_communication_mq::get_instance_references().encapsulate_status_msg(t_multi_measure_info_msg.DebugString(), rabbit_send_status_msg_id);
- System_communication_mq::get_instance_references().encapsulate_status_msg(t_multi_terminal_measure_info_msg.DebugString(), rabbit_send_terminal_status_msg_id);
- // if (t_multi_status_msg.id_struct().terminal_id() == 1)
- // {
- // LOG(WARNING) << "-------------------------------------------------------" <<std::endl;
- // LOG(WARNING) << "t_msg = " << t_msg <<std::endl;
- // LOG(WARNING) << "+++++++++++++++++++++++++++++++++++++++++++++++++++++++" <<std::endl;
- // LOG(WARNING) << "t_multi_status_msg.ground_status() = " << t_ground_status <<std::endl;
- // LOG(WARNING) << "t_multi_measure_info_msg.set_ground_status(0) = " << t_multi_measure_info_msg.ground_status() <<std::endl;
- // }
- }
- if (t_multi_status_msg.id_struct().terminal_id() == DISP_TERM_ID)
- {
- // LOG(WARNING) << t_car_wheel_information.range_status<<std::endl;
- LOG(INFO) << t_multi_status_msg.DebugString() << std::endl
- << std::endl;
- }
- }
- }
- #endif
- return Error_code::SUCCESS;
- }
- // ***************************** nanomsg *********************************
- //定时发送状态信息
- Error_manager System_executor::encapsulate_send_status()
- {
- static int cloud_count=-1;
- cloud_count++;
- // if(!g_debug_file.is_open())
- // {
- // g_debug_file.open("./filter_debug_result.txt", std::ios::app);
- // }
- Error_manager t_error;
- //创建一条状态消息
- message::Ground_status_msg t_ground_status_msg;
- t_ground_status_msg.mutable_base_info()->set_msg_type(message::Message_type::eGround_status_msg);
- t_ground_status_msg.mutable_base_info()->set_timeout_ms(5000);
- t_ground_status_msg.mutable_base_info()->set_sender(message::Communicator::eGround_measurer);
- t_ground_status_msg.mutable_base_info()->set_receiver(message::Communicator::eEmpty);
- // t_ground_status_msg.set_terminal_id(m_terminal_id);
- t_ground_status_msg.mutable_id_struct()->set_terminal_id(m_terminal_id);
- // 创建各区域状态消息,
- // 注意!!!目前公共消息名字依旧使用wj,不做修改
- // manager
- #if WJ_VELO == 1
- {
- Velodyne_manager::Velodyne_manager_status t_velodyne_manager_status = Velodyne_manager::get_instance_references().get_status();
- t_ground_status_msg.set_wanji_manager_status((message::Wanji_manager_status)t_velodyne_manager_status);
- // lidar
- std::map<int, Velodyne_lidar_device *> t_velodyne_lidar_device_map = Velodyne_manager::get_instance_references().get_velodyne_lidar_device_map();
- std::map<int, Velodyne_lidar_device::Velodyne_lidar_device_status> t_velodyne_lidar_status_map;
- for (auto iter = t_velodyne_lidar_device_map.begin(); iter != t_velodyne_lidar_device_map.end(); ++iter)
- {
- t_velodyne_lidar_status_map.emplace(std::pair<int, Velodyne_lidar_device::Velodyne_lidar_device_status>(iter->second->get_lidar_id(), iter->second->get_status()));
- }
- // region
- std::map<int, Ground_region *> t_ground_region_map = Velodyne_manager::get_instance_references().get_ground_region_map();
- int region_index = 0;
- for (auto iter = t_ground_region_map.begin(); iter != t_ground_region_map.end(); ++iter)
- {
- // 以t_ground_status_msg为模板创建各区域心跳消息
- message::Ground_status_msg t_multi_status_msg;
- t_multi_status_msg.CopyFrom(t_ground_status_msg);
- t_multi_status_msg.mutable_id_struct()->set_terminal_id(iter->second->get_terminal_id());
- t_multi_status_msg.set_region_worker_status((message::Region_worker_status)(iter->second->get_status()));
- velodyne::Region t_param = iter->second->get_param();
- for (size_t j = 0; j < t_param.lidar_exts_size(); j++)
- {
- std::map<int, Velodyne_lidar_device::Velodyne_lidar_device_status>::iterator t_status_iter = t_velodyne_lidar_status_map.find(t_param.lidar_exts(j).lidar_id());
- if (t_status_iter == t_velodyne_lidar_status_map.end())
- {
- LOG(WARNING) << "lidar status " << t_param.lidar_exts(j).lidar_id() << " cannot be found, param error";
- }
- else
- {
- t_multi_status_msg.add_wanji_lidar_device_status((message::Wanji_lidar_device_status)t_status_iter->second);
- }
- }
- //velodyne雷达的自动定位信息
- Common_data::Car_wheel_information t_car_wheel_information;
- t_error = (*iter).second->get_last_wheel_information(&t_car_wheel_information, std::chrono::system_clock::now());
- // 获取区域点云填入信息
- pcl::PointCloud<pcl::PointXYZ>::Ptr t_region_cloud = pcl::PointCloud<pcl::PointXYZ>::Ptr(new pcl::PointCloud<pcl::PointXYZ>);
- iter->second->get_region_cloud(t_region_cloud, Ground_region::Region_cloud_type::filtered);
- // if (cloud_count == 5)
- // {
- // std::string t_filename = std::string("region_") + std::to_string(iter->first) + "_cloud.txt";
- // save_cloud_txt(t_region_cloud, t_filename);
- // LOG(INFO) << "region " << iter->first << " cloud has been saved in " + t_filename;
- // }
- // for (size_t j = 0; j < t_region_cloud->size(); j++)
- // {
- // message::Cloud_coordinate *tp_cloud = t_multi_status_msg.add_cloud();
- // tp_cloud->set_x(t_region_cloud->points[j].x);
- // tp_cloud->set_y(t_region_cloud->points[j].y);
- // tp_cloud->set_z(t_region_cloud->points[j].z);
- // }
- update_measure_info(t_multi_status_msg, t_car_wheel_information, t_region_cloud->size());
- std::string t_msg = t_multi_status_msg.SerializeAsString();
- System_communication::get_instance_references().encapsulate_msg(t_msg);
- if (t_multi_status_msg.id_struct().terminal_id() == DISP_TERM_ID)
- std::cout << t_multi_status_msg.DebugString() << std::endl
- << std::endl;
- }
- }
- #elif WJ_VELO == 0
- {
- // wj_support 20220718
- Wanji_manager::Wanji_manager_status t_wj_manager_status = Wanji_manager::get_instance_references().get_status();
- t_ground_status_msg.set_wanji_manager_status((message::Wanji_manager_status)t_wj_manager_status);
- // lidar
- std::map<int, Wanji_lidar_device *> t_wj_lidar_device_map = Wanji_manager::get_instance_references().get_wanji_lidar_device_map();
- std::map<int, Wanji_lidar_device::Wanji_lidar_device_status> t_wj_lidar_status_map;
- for (auto iter = t_wj_lidar_device_map.begin(); iter != t_wj_lidar_device_map.end(); ++iter)
- {
- t_wj_lidar_status_map.emplace(std::pair<int, Wanji_lidar_device::Wanji_lidar_device_status>(iter->second->get_lidar_id(), iter->second->get_status()));
- }
- // region
- std::map<int, Region_worker *> t_region_worker_map = Wanji_manager::get_instance_references().get_region_worker_map();
- int region_index = 0;
- for (auto iter = t_region_worker_map.begin(); iter != t_region_worker_map.end(); ++iter)
- {
- // 以t_ground_status_msg为模板创建各区域心跳消息
- message::Ground_status_msg t_multi_status_msg;
- t_multi_status_msg.CopyFrom(t_ground_status_msg);
- t_multi_status_msg.mutable_id_struct()->set_terminal_id(iter->second->get_terminal_id());
- t_multi_status_msg.set_region_worker_status((message::Region_worker_status)(iter->second->get_status()));
- wj::Region t_param = iter->second->get_param();
- for (size_t j = 0; j < t_param.lidar_exts_size(); j++)
- {
- std::map<int, Wanji_lidar_device::Wanji_lidar_device_status>::iterator t_status_iter = t_wj_lidar_status_map.find(t_param.lidar_exts(j).lidar_id());
- if (t_status_iter == t_wj_lidar_status_map.end())
- {
- LOG(WARNING) << "lidar status " << t_param.lidar_exts(j).lidar_id() << " cannot be found, param error";
- }
- else
- {
- t_multi_status_msg.add_wanji_lidar_device_status((message::Wanji_lidar_device_status)t_status_iter->second);
- }
- }
- //velodyne雷达的自动定位信息
- Common_data::Car_wheel_information t_car_wheel_information;
- t_error = (*iter).second->get_last_wheel_information(&t_car_wheel_information, std::chrono::system_clock::now());
- // 获取区域点云填入信息
- pcl::PointCloud<pcl::PointXYZ>::Ptr t_region_cloud = pcl::PointCloud<pcl::PointXYZ>::Ptr(new pcl::PointCloud<pcl::PointXYZ>);
- iter->second->get_region_cloud(t_region_cloud);
- // if (cloud_count == 5)
- // {
- // std::string t_filename = std::string("region_") + std::to_string(iter->first) + "_cloud.txt";
- // save_cloud_txt(t_region_cloud, t_filename);
- // LOG(INFO) << "region " << iter->first << " cloud has been saved in " + t_filename;
- // }
- // for (size_t j = 0; j < t_region_cloud->size(); j++)
- // {
- // message::Cloud_coordinate *tp_cloud = t_multi_status_msg.add_cloud();
- // tp_cloud->set_x(t_region_cloud->points[j].x);
- // tp_cloud->set_y(t_region_cloud->points[j].y);
- // tp_cloud->set_z(t_region_cloud->points[j].z);
- // }
- update_measure_info(t_multi_status_msg, t_car_wheel_information, t_region_cloud->size());
- std::string t_msg = t_multi_status_msg.SerializeAsString();
- System_communication::get_instance_references().encapsulate_msg(t_msg);
- if (t_multi_status_msg.id_struct().terminal_id() == DISP_TERM_ID)
- LOG(INFO) << t_multi_status_msg.DebugString();
- }
- }
- // std::cout << " huli test :::: " << " t_ground_status_msg.DebugString() = " << std::endl;
- // std::cout << t_ground_status_msg.DebugString() << std::endl;
- // std::cout << " huli test :::: " << " t_ground_status_msg.DebugString() = " << t_ground_status_msg.DebugString() << std::endl;
- #else
- {
- // mix vlp16 and wj716
- // 以多线雷达为主
- Velodyne_manager::Velodyne_manager_status t_velodyne_manager_status = Velodyne_manager::get_instance_references().get_status();
- t_ground_status_msg.set_wanji_manager_status((message::Wanji_manager_status)t_velodyne_manager_status);
- // vlp16 lidar
- std::map<int, Velodyne_lidar_device *> t_velodyne_lidar_device_map = Velodyne_manager::get_instance_references().get_velodyne_lidar_device_map();
- std::map<int, Velodyne_lidar_device::Velodyne_lidar_device_status> t_velodyne_lidar_status_map;
- for (auto iter = t_velodyne_lidar_device_map.begin(); iter != t_velodyne_lidar_device_map.end(); ++iter)
- {
- t_velodyne_lidar_status_map.emplace(std::pair<int, Velodyne_lidar_device::Velodyne_lidar_device_status>(iter->second->get_lidar_id(), iter->second->get_status()));
- }
- // wj lidar
- #if LIDAR_TYPE == 1
- std::map<int, Wanji_lidar_device *> t_wj_lidar_device_map = Wanji_manager::get_instance_references().get_wanji_lidar_device_map();
- std::map<int, Wanji_lidar_device::Wanji_lidar_device_status> t_wj_lidar_status_map;
- for (auto iter = t_wj_lidar_device_map.begin(); iter != t_wj_lidar_device_map.end(); ++iter)
- {
- t_wj_lidar_status_map.emplace(std::pair<int, Wanji_lidar_device::Wanji_lidar_device_status>(iter->second->get_lidar_id(), iter->second->get_status()));
- }
- #else
- std::map<int, Wanji_716N_lidar_device *> t_wj_lidar_device_map = Wanji_manager::get_instance_references().get_wanji_lidar_device_map();
- std::map<int, Wanji_716N_lidar_device::Wanji_716N_device_status> t_wj_lidar_status_map;
- for (auto iter = t_wj_lidar_device_map.begin(); iter != t_wj_lidar_device_map.end(); ++iter)
- {
- t_wj_lidar_status_map.emplace(std::pair<int, Wanji_716N_lidar_device::Wanji_716N_device_status>(iter->second->get_lidar_id(), iter->second->get_status()));
- }
- #endif
-
-
- // wj region
- std::map<int, Region_worker *> t_region_worker_map = Wanji_manager::get_instance_references().get_region_worker_map();
- // vlp16 region
- std::map<int, Ground_region *> t_ground_region_map = Velodyne_manager::get_instance_references().get_ground_region_map();
- int region_index = 0;
- for (auto iter = t_ground_region_map.begin(); iter != t_ground_region_map.end(); ++iter)
- {
- // 以t_ground_status_msg为模板创建各区域心跳消息
- message::Ground_status_msg t_multi_status_msg;
- t_multi_status_msg.CopyFrom(t_ground_status_msg);
- t_multi_status_msg.mutable_id_struct()->set_terminal_id(iter->second->get_terminal_id());
- t_multi_status_msg.set_region_worker_status((message::Region_worker_status)(iter->second->get_status()));
- // 查找多线区域内对应多线激光雷达
- velodyne::Region t_param = iter->second->get_param();
- for (size_t j = 0; j < t_param.lidar_exts_size(); j++)
- {
- std::map<int, Velodyne_lidar_device::Velodyne_lidar_device_status>::iterator t_status_iter = t_velodyne_lidar_status_map.find(t_param.lidar_exts(j).lidar_id());
- if (t_status_iter == t_velodyne_lidar_status_map.end())
- {
- LOG(WARNING) << "vlp16 lidar status " << t_param.lidar_exts(j).lidar_id() << " cannot be found, param error";
- }
- else
- {
- t_multi_status_msg.add_wanji_lidar_device_status((message::Wanji_lidar_device_status)t_status_iter->second);
- }
- }
- //velodyne雷达的自动定位信息
- Common_data::Car_wheel_information t_car_wheel_information;
- t_error = (*iter).second->get_last_wheel_information(&t_car_wheel_information, std::chrono::system_clock::now());
- // 获取区域点云填入信息
- // 20221211 changed by yct, nanomsg dont save cloud
- pcl::PointCloud<pcl::PointXYZ>::Ptr t_region_cloud = pcl::PointCloud<pcl::PointXYZ>::Ptr(new pcl::PointCloud<pcl::PointXYZ>);
- iter->second->get_region_cloud(t_region_cloud, Ground_region::Region_cloud_type::filtered);
- // if (cloud_count == 5)
- // {
- // std::string t_filename = std::string("vlp16_region_") + std::to_string(iter->first) + "_cloud.txt";
- // save_cloud_txt(t_region_cloud, t_filename);
- // LOG(INFO) << "vlp16 region " << iter->first << " cloud has been saved in " + t_filename;
- // }
- // for (size_t j = 0; j < t_region_cloud->size(); j++)
- // {
- // message::Cloud_coordinate *tp_cloud = t_multi_status_msg.add_cloud();
- // tp_cloud->set_x(t_region_cloud->points[j].x);
- // tp_cloud->set_y(t_region_cloud->points[j].y);
- // tp_cloud->set_z(t_region_cloud->points[j].z);
- // }
- // 检查vlp16区域与wj区域对应关系,wj存在对应区域则填充设备状态,并融合测量结果
- auto t_wj_region_iter = t_region_worker_map.find(iter->first);
- if(t_wj_region_iter != t_region_worker_map.end())
- {
- wj::Region t_param = t_wj_region_iter->second->get_param();
- //
- for (size_t j = 0; j < t_param.lidar_exts_size(); j++)
- {
- #if LIDAR_TYPE == 1
- std::map<int, Wanji_lidar_device::Wanji_lidar_device_status>::iterator t_status_iter = t_wj_lidar_status_map.find(t_param.lidar_exts(j).lidar_id());
- #else
- std::map<int, Wanji_716N_lidar_device::Wanji_716N_device_status>::iterator t_status_iter = t_wj_lidar_status_map.find(t_param.lidar_exts(j).lidar_id());
- #endif
- if (t_status_iter == t_wj_lidar_status_map.end())
- {
- LOG(WARNING) << "wj lidar status " << t_param.lidar_exts(j).lidar_id() << " cannot be found, param error";
- }
- else
- {
- t_multi_status_msg.add_wanji_lidar_device_status((message::Wanji_lidar_device_status)t_status_iter->second);
- }
- }
- //wj雷达的自动定位信息
- Common_data::Car_wheel_information t_wj_car_wheel_information;
- t_error = t_wj_region_iter->second->get_last_wheel_information(&t_wj_car_wheel_information, std::chrono::system_clock::now());
- // 获取区域点云填入信息
- pcl::PointCloud<pcl::PointXYZ>::Ptr t_wj_region_cloud = pcl::PointCloud<pcl::PointXYZ>::Ptr(new pcl::PointCloud<pcl::PointXYZ>);
- t_wj_region_iter->second->get_region_cloud(t_wj_region_cloud);
- // if (cloud_count == 8)
- // {
- // std::string t_filename = std::string("wj_region_") + std::to_string(t_wj_region_iter->first) + "_cloud.txt";
- // save_cloud_txt(t_wj_region_cloud, t_filename);
- // LOG(INFO) << "wj region " << t_wj_region_iter->first << " cloud has been saved in " + t_filename;
- // }
- // for (size_t j = 0; j < t_wj_region_cloud->size(); j++)
- // {
- // message::Cloud_coordinate *tp_cloud = t_multi_status_msg.add_cloud();
- // tp_cloud->set_x(t_wj_region_cloud->points[j].x);
- // tp_cloud->set_y(t_wj_region_cloud->points[j].y);
- // tp_cloud->set_z(t_wj_region_cloud->points[j].z);
- // }
- // LOG_IF(WARNING, iter->second->get_terminal_id() == DISP_TERM_ID)<<"\n"<<t_car_wheel_information.to_string()<<"\n"
- // <<t_wj_car_wheel_information.to_string()<<"\n"
- // <<t_car_wheel_information.range_status<<", "<<t_wj_car_wheel_information.range_status;
- // 融合测量结果,验证中心点差异x<0.03, y<0.06, 角度差异ang<0.6, 轴距差异wb<0.055
- double dx = t_car_wheel_information.car_center_x - t_wj_car_wheel_information.car_center_x;
- double dy = t_car_wheel_information.car_center_y - t_wj_car_wheel_information.car_center_y;
- double dang = t_car_wheel_information.car_angle - t_wj_car_wheel_information.car_angle;
- double dwb = t_car_wheel_information.car_wheel_base - t_wj_car_wheel_information.car_wheel_base;
- // 使用rabbit mq 中函数计算偏差与提示,此处不处理!!
- if(fabs(dx) < 0.03 && fabs(dy) < 0.06 && fabs(dang) < 0.6 && fabs(dwb) < 0.055)
- {
- // t_car_wheel_information.car_wheel_base = t_car_wheel_information.car_wheel_base*0.3 + t_car_wheel_information.car_wheel_base*0.7;
- }else
- {
- // LOG_IF(WARNING, iter->second->get_terminal_id() == DISP_TERM_ID)<<
- // "detect mismatch, region "<<iter->first<<", dx dy dang dwb: "<<dx<<", "<<dy<<", "<<dang<<", "<< dwb << std::endl
- // << t_car_wheel_information.to_string() << std::endl
- // << t_wj_car_wheel_information.to_string() << std::endl;
- }
- }else{
- LOG_IF(WARNING, iter->second->get_terminal_id() == DISP_TERM_ID)<<"region mismatch, vlp16 "<<iter->first<<", wj doesn't have corresponding region id";
- }
- update_measure_info(t_multi_status_msg, t_car_wheel_information, t_region_cloud->size());
- std::string t_msg = t_multi_status_msg.SerializeAsString();
- System_communication::get_instance_references().encapsulate_msg(t_msg);
- // if (t_multi_status_msg.id_struct().terminal_id() == DISP_TERM_ID)
- // std::cout << t_multi_status_msg.DebugString() << std::endl
- // << std::endl;
- }
- }
- #endif
- return Error_code::SUCCESS;
- }
- //判断是否为待机,如果已经准备好,则可以执行任务。
- bool System_executor::is_ready()
- {
- if (m_system_executor_status == SYSTEM_EXECUTOR_READY && m_thread_pool.thread_is_full_load() == false)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- System_executor::System_executor_status System_executor::get_system_executor_status()
- {
- return m_system_executor_status;
- }
- int System_executor::get_terminal_id()
- {
- return m_terminal_id;
- }
- //雷达感测定位 的处理函数
- //input::command_id, 消息指令id, 由主控制系统生成的唯一码
- //input::command_id, 终端id, 对应具体的某个车位
- //return::void, 没有返回, 执行结果直接生成一条答复消息, 然后通过通信返回
- void System_executor::execute_for_measure(std::string command_info, int terminal_id, std::chrono::system_clock::time_point receive_time)
- {
- Error_manager t_error;
- Error_manager t_result;
- LOG(INFO) << " System_executor::execute_for_measure run " << this;
- //第1步, 按照时间生成中间文件的保存路径
- time_t nowTime;
- nowTime = time(NULL);
- struct tm *sysTime = localtime(&nowTime);
- char t_save_path[256] = {0};
- sprintf(t_save_path, "../data/%04d%02d%02d_%02d%02d%02d",
- sysTime->tm_year + 1900, sysTime->tm_mon + 1, sysTime->tm_mday, sysTime->tm_hour, sysTime->tm_min, sysTime->tm_sec);
- //第2步, 创建万集管理模块的任务单, 并发送到 wanji_manager
- // Wanji_manager_task t_wanji_manager_task ;
- // Common_data::Car_wheel_information t_car_information_by_wanji;
- // t_wanji_manager_task.task_init(TASK_CREATED,"",NULL,std::chrono::milliseconds(3000),
- // terminal_id, receive_time);
- // t_error = Task_command_manager::get_instance_references().execute_task(&t_wanji_manager_task);
- // 或者创建velodyne管理模块任务单,并发送到velodyne_manager
- Velodyne_manager_task t_velodyne_manager_task;
- Common_data::Car_wheel_information t_car_information_by_velodyne;
- t_velodyne_manager_task.task_init(TASK_CREATED, "", NULL, std::chrono::milliseconds(3000),
- terminal_id, receive_time);
- t_error = Task_command_manager::get_instance_references().execute_task(&t_velodyne_manager_task);
- //第3步, 等待任务单完成
- if (t_error != Error_code::SUCCESS)
- {
- LOG(INFO) << " Velodyne_manager/Velodyne_manager execute_task error " << this;
- }
- else
- {
- // //判断任务是否结束, 阻塞 等待, 直到任务完成或者超时
- // while ( t_wanji_manager_task.is_task_end() == false)
- // {
- // if ( t_wanji_manager_task.is_over_time() )
- // {
- // //超时处理。取消任务。
- // Wanji_manager::get_instance_pointer()->cancel_task(&t_wanji_manager_task);
- // t_error.error_manager_reset(Error_code::WJ_MANAGER_TASK_OVER_TIME, Error_level::MINOR_ERROR,
- // " t_wanjestaui_manager_task is_over_time ");
- // t_wanji_manager_task.set_task_error_manager(t_error);
- // }
- // else
- // {
- // //继续等待
- // std::this_thread::sleep_for(std::chrono::microseconds(1));
- // std::this_thread::yield();
- // }
- // }
- // //提取任务单 的错误码
- // t_error = t_wanji_manager_task.get_task_error_manager();
- // if ( t_error == Error_code::SUCCESS )
- // {
- // t_car_information_by_wanji = t_wanji_manager_task.get_car_wheel_information();
- // }
- // else
- // {
- // LOG(INFO) << " wanji_manager_task error :::::::" << t_wanji_manager_task.get_task_error_manager().to_string() << this;
- // }
- // ------------------- 切换为velodyne ------------------
- //判断任务是否结束, 阻塞 等待, 直到任务完成或者超时
- while (t_velodyne_manager_task.is_task_end() == false)
- {
- if (t_velodyne_manager_task.is_over_time())
- {
- //超时处理。取消任务。
- Velodyne_manager::get_instance_pointer()->cancel_task(&t_velodyne_manager_task);
- t_error.error_manager_reset(Error_code::VELODYNE_MANAGER_TASK_OVER_TIME, Error_level::MINOR_ERROR,
- " t_velodyne_manager_task is_over_time ");
- t_velodyne_manager_task.set_task_error_manager(t_error);
- }
- else
- {
- //继续等待
- std::this_thread::sleep_for(std::chrono::microseconds(1));
- std::this_thread::yield();
- }
- }
- //提取任务单 的错误码
- t_error = t_velodyne_manager_task.get_task_error_manager();
- if (t_error == Error_code::SUCCESS)
- {
- t_car_information_by_velodyne = t_velodyne_manager_task.get_car_wheel_information();
- }
- else
- {
- LOG(INFO) << " velodyne_manager_task error :::::::" << t_velodyne_manager_task.get_task_error_manager().to_string() << this;
- }
- }
- t_result.compare_and_cover_error(t_error);
- //measure 测量模块的最终结果
- Common_data::Car_measure_information t_car_information_result;
- //第4步, 生成反馈消息
- // if(t_car_information_by_wanji.correctness == true )
- // {
- // t_car_information_result.center_x = t_car_information_by_wanji.center_x;
- // t_car_information_result.center_y = t_car_information_by_wanji.center_y;
- // t_car_information_result.car_angle = t_car_information_by_wanji.car_angle;
- // t_car_information_result.wheel_base = t_car_information_by_wanji.wheel_base;
- // t_car_information_result.wheel_width = t_car_information_by_wanji.wheel_width;
- // t_car_information_result.correctness = true;
- // }else{
- // t_result.set_error_level_down(NEGLIGIBLE_ERROR);
- // }
- // ------------------- 切换为velodyne ------------------
- if (t_car_information_by_velodyne.correctness == true)
- {
- t_car_information_result.car_center_x = t_car_information_by_velodyne.car_center_x;
- t_car_information_result.car_center_y = t_car_information_by_velodyne.car_center_y;
- t_car_information_result.car_angle = t_car_information_by_velodyne.car_angle;
- t_car_information_result.car_wheel_base = t_car_information_by_velodyne.car_wheel_base;
- t_car_information_result.car_wheel_width = t_car_information_by_velodyne.car_wheel_width;
- t_car_information_result.correctness = true;
- }
- else
- {
- t_result.set_error_level_down(NEGLIGIBLE_ERROR);
- }
- //第七步, 创建一条答复消息
- message::Ground_detect_response_msg t_ground_detect_response_msg;
- t_ground_detect_response_msg.mutable_base_info()->set_msg_type(message::Message_type::eGround_detect_response_msg);
- t_ground_detect_response_msg.mutable_base_info()->set_timeout_ms(5000);
- t_ground_detect_response_msg.mutable_base_info()->set_sender(message::Communicator::eGround_measurer);
- t_ground_detect_response_msg.mutable_base_info()->set_receiver(message::Communicator::eMain);
- t_ground_detect_response_msg.set_command_key(command_info);
- t_ground_detect_response_msg.mutable_id_struct()->set_terminal_id(terminal_id);
- t_ground_detect_response_msg.mutable_error_manager()->set_error_code(t_result.get_error_code());
- t_ground_detect_response_msg.mutable_error_manager()->set_error_level((message::Error_level)t_result.get_error_level());
- t_ground_detect_response_msg.mutable_error_manager()->set_error_description(t_result.get_error_description());
- t_ground_detect_response_msg.mutable_locate_information()->set_locate_x(t_car_information_result.car_center_x);
- t_ground_detect_response_msg.mutable_locate_information()->set_locate_y(t_car_information_result.car_center_y);
- t_ground_detect_response_msg.mutable_locate_information()->set_locate_angle(t_car_information_result.car_angle);
- t_ground_detect_response_msg.mutable_locate_information()->set_locate_length(t_car_information_result.car_length);
- t_ground_detect_response_msg.mutable_locate_information()->set_locate_width(t_car_information_result.car_width);
- t_ground_detect_response_msg.mutable_locate_information()->set_locate_height(t_car_information_result.car_height);
- t_ground_detect_response_msg.mutable_locate_information()->set_locate_wheel_base(t_car_information_result.car_wheel_base);
- t_ground_detect_response_msg.mutable_locate_information()->set_locate_wheel_width(t_car_information_result.car_wheel_width);
- t_ground_detect_response_msg.mutable_locate_information()->set_locate_front_theta(t_car_information_result.car_front_theta);
- t_ground_detect_response_msg.mutable_locate_information()->set_locate_correct(t_car_information_result.correctness);
- std::string t_msg = t_ground_detect_response_msg.SerializeAsString();
- System_communication::get_instance_references().encapsulate_msg(t_msg);
- std::cout << "huli t_measure_response_msg = " << t_ground_detect_response_msg.DebugString() << std::endl;
- return;
- }
|