Selaa lähdekoodia

内存泄露仍未解决,现场代码

yct 5 vuotta sitten
vanhempi
commit
02c655a68b

+ 8 - 4
CMakeLists.txt

@@ -43,10 +43,14 @@ aux_source_directory(${CMAKE_CURRENT_LIST_DIR}/system_manager SYS_SRC )
 aux_source_directory(${CMAKE_CURRENT_LIST_DIR}/wj_lidar WJLIDAR_SRC )
 
 
-# plc test module
-#add_executable(plc_test  ./test/plc_test.cpp ${PLC_SRC} ${TASK_MANAGER_SRC} ${TOOL_SRC} ${ERROR_CODE_SRC})
-#target_link_libraries(plc_test ${OpenCV_LIBS}
-#        ${GLOG_LIBRARIES} ${PCL_LIBRARIES} ${PROTOBUF_LIBRARIES} ipopt modbus libnanomsg.so libnnxx.a libglog.a libgflags.a)
+
+add_executable(locate_sample  test/locate_sample.cpp ${LOCATE_SRC}  ${TASK_MANAGER_SRC} ${ERROR_SRC}
+        ${TOOL_SRC})
+target_link_libraries(locate_sample ${OpenCV_LIBS}
+        ${GLOG_LIBRARIES} ${PCL_LIBRARIES} ${PROTOBUF_LIBRARIES} libtensorflow_cc.so
+        tf_3dcnn_api.so pointSIFT_API.so dark.so /usr/local/lib/libglog.a
+        /usr/local/lib/libgflags.a snap7 nnxx nanomsg)
+
 add_executable(fence_debug  test/plc_s7.cpp wj_lidar/wj_lidar_msg.pb.cc)
 target_link_libraries(fence_debug ${GLOG_LIBRARIES} ${PROTOBUF_LIBRARIES} /usr/local/lib/libglog.a
         /usr/local/lib/libgflags.a nnxx nanomsg)

+ 19 - 18
laser/Laser.cpp

@@ -1,7 +1,7 @@
 
 
 #include "Laser.h"
-
+#include "laser_message.pb.h"
 
 Laser_base::Laser_base(int laser_id, Laser_proto::laser_parameter laser_param)
 :m_laser_id(laser_id)
@@ -204,7 +204,7 @@ Error_manager Laser_base::end_task()
 	if(mp_laser_task !=NULL)
 	{
 		//判断任务单的错误等级,
-		if ( mp_laser_task->get_task_error_manager().get_error_level() > Error_level::MINOR_ERROR)
+		if ( mp_laser_task->get_task_error_manager().get_error_level() <= Error_level::MINOR_ERROR)
 		{
 			if ( m_laser_statu == LASER_BUSY )
 			{
@@ -451,24 +451,25 @@ void Laser_base::thread_transform()
 
 
 //公开发布雷达信息的功能函数,
+#include "../tool/MeasureTopicPublisher.h"
 Error_manager Laser_base::publish_laser_to_message()
 {
-	return Error_code::SUCCESS;
-/*
-	globalmsg::msg msg;
-	msg.set_msg_type(globalmsg::eLaser);
-
-	globalmsg::laserStatus status;
-	if(GetStatu()==eLaser_ready) status=globalmsg::eLaserConnected;
-	else if(GetStatu()==eLaser_disconnect) status=globalmsg::eLaserDisconnected;
-	else if(GetStatu()==eLaser_busy) status=globalmsg::eLaserBusy;
-	else  status=globalmsg::eLaserUnknown;
-
-	msg.mutable_laser_msg()->set_id(m_laser_id);
-	msg.mutable_laser_msg()->set_laser_status(status);
-	msg.mutable_laser_msg()->set_queue_data_count(m_queue_laser_data.size());
-	msg.mutable_laser_msg()->set_cloud_count(m_points_count);
-	MeasureTopicPublisher::GetInstance()->Publish(msg.SerializeAsString());*/
+    //usleep(5*1000*1000);
+	laser_message::laserMsg msg;
+	laser_message::laserStatus status;
+	if(get_laser_statu()==LASER_READY) status=laser_message::eLaserConnected;
+	else if(get_laser_statu()==LASER_DISCONNECT) status=laser_message::eLaserDisconnected;
+	else if(get_laser_statu()==LASER_BUSY) status=laser_message::eLaserBusy;
+	else if(get_laser_statu()==LASER_FAULT) status=laser_message::eLaserDisconnected;
+	else  status=laser_message::eLaserUnknown;
+
+	msg.set_id(m_laser_id);
+	msg.set_laser_status(status);
+	msg.set_queue_data_count(m_queue_laser_data.size());
+	msg.set_cloud_count(m_points_count);
+	MeasureTopicPublisher::GetInstance()->Publish(msg.SerializeAsString());
+
+	return SUCCESS;
 
 }
 //线程执行函数,公开发布雷达的相关信息,用作上位机的监视。

+ 1 - 9
laser/LivoxLaser.cpp

@@ -406,15 +406,7 @@ void CLivoxLaser::LidarDataCallback(uint8_t handle, LivoxEthPacket *data, uint32
 			g_count[handle]++;
 
 		}
-	/*	else
-		{
-			std::cout << "huli 1z error " << "data = "<< data  << std::endl;
-			std::cout << "huli 1z error " << "livox = "<< livox  << std::endl;
-
-			//?????????????????
-			livox->m_laser_statu = LASER_READY;
-			usleep(10*1000);
-		}*/
+        livox->m_laser_statu = LASER_READY;
 	}
 	/*else
 	{

+ 1 - 1
locate/locate_task.cpp

@@ -15,7 +15,7 @@ Locate_task::~Locate_task()
 
 Error_manager Locate_task::set_locate_cloud(pcl::PointCloud<pcl::PointXYZ>::Ptr cloud)
 {
-    if(cloud==0)
+    if(cloud.get()==0)
     {
         return Error_manager(LOCATER_TASK_INPUT_CLOUD_UNINIT,NORMAL,"locate task set input cloud uninit");
     }

+ 0 - 0
locate/locate_task.h


+ 0 - 0
locate/locate_uml.wsd


+ 8 - 5
locate/locater.cpp

@@ -95,7 +95,7 @@ Error_manager Locater::execute_task(Task_Base* task,double time_out)
     ///第一步,获取task中input点云,文件保存路径
     pcl::PointCloud<pcl::PointXYZ>::Ptr t_cloud_input=locate_task->get_locate_cloud();
     std::string save_path=locate_task->get_save_path();
-    if(t_cloud_input==0)
+    if(t_cloud_input.get()==0)
     {
         locate_task->update_statu(TASK_OVER,"Task set cloud is uninit");
         return Error_manager(LOCATER_INPUT_CLOUD_UNINIT,NORMAL,"Task set cloud is uninit");
@@ -189,7 +189,7 @@ Error_manager Locater::locate_sift(pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_in,
     maxp.x = minp.x + yolo_box.w;
     maxp.y = minp.y + yolo_box.h;
 
-    //pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_input_sift(new pcl::PointCloud<pcl::PointXYZ>());
+    pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_input_sift(new pcl::PointCloud<pcl::PointXYZ>());
     pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_downsample(new pcl::PointCloud<pcl::PointXYZ>());
     ///	///体素网格 下采样
     pcl::VoxelGrid<pcl::PointXYZ> vgfilter;
@@ -226,10 +226,13 @@ Error_manager Locater::locate_sift(pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_in,
     {
         return Error_manager(LOCATER_SIFT_PREDICT_NO_CAR_POINT,NORMAL,"sift predict no car or wheel");
     }
+    pcl::PointCloud<pcl::PointXYZ>::Ptr t_cloud_car(new pcl::PointCloud<pcl::PointXYZ>);
+    pcl::PointCloud<pcl::PointXYZ>::Ptr t_cloud_wheel(new pcl::PointCloud<pcl::PointXYZ>);
     //第0类即是轮胎点云,第二类为车身点云
-    pcl::copyPointCloud(*segmentation_clouds[0], *cloud_wheel);
-    pcl::copyPointCloud(*segmentation_clouds[2], *cloud_car);
-
+    pcl::copyPointCloud(*segmentation_clouds[0], *t_cloud_wheel);
+    pcl::copyPointCloud(*segmentation_clouds[2], *t_cloud_car);
+    cloud_wheel=t_cloud_wheel;
+    cloud_car=t_cloud_car;
     return SUCCESS;
 }
 

+ 0 - 0
locate/locater.h


+ 0 - 0
locate/locater_parameter.pb.cc


+ 0 - 0
locate/locater_parameter.pb.h


+ 0 - 0
locate/locater_parameter.proto


+ 0 - 0
locate/tf_wheel_3Dcnn_api.h


+ 122 - 134
terminor/terminal_command_executor.cpp

@@ -295,129 +295,114 @@ void Terminor_Command_Executor::set_save_root_path(std::string root)
     m_save_root_path=root;
 }
 
-Error_manager Terminor_Command_Executor::scanning_measuring()
-{
+Error_manager Terminor_Command_Executor::scanning_measuring() {
     std::lock_guard<std::mutex> lock(ms_mutex_scan_measure);
-    LOG(INFO)<<">>>>>>>>>>>> Enter terminator ID:"<<m_terminor_parameter.id();
+    Error_manager code;
+    LOG(INFO) << ">>>>>>>>>>>> Enter terminator ID:" << m_terminor_parameter.id();
     //计时起点
-    auto t_start_point=std::chrono::system_clock::now();
+    auto t_start_point = std::chrono::system_clock::now();
 
     //准备目录
     time_t tt;
-    time( &tt );
-    tt = tt + 8*3600;  // transform the time zone
-    tm* t= gmtime( &tt );
-    char path[255]={0};
-    sprintf(path,"%s/%4d/%02d/%02d",m_save_root_path.c_str(),
+    time(&tt);
+    tt = tt + 8 * 3600;  // transform the time zone
+    tm *t = gmtime(&tt);
+    char path[255] = {0};
+    sprintf(path, "%s/%4d/%02d/%02d", m_save_root_path.c_str(),
             t->tm_year + 1900,
             t->tm_mon + 1,
             t->tm_mday);
     PathCreator path_creator;
     path_creator.CreateDatePath(path);
-    std::string project_path=path_creator.GetCurPath();
+    std::string project_path = path_creator.GetCurPath();
+
 
-    Error_manager code;
     //第一步,启动雷达扫描点云,切换当前状态为扫描中
     //根据配置筛选雷达
     pcl::PointCloud<pcl::PointXYZ> scan_cloud;
     std::mutex cloud_lock;
-    std::vector<Laser_task*> laser_task_vector;
-
-    std::vector<Laser_base*> tp_lasers;
-    for(int i=0;i<m_terminor_parameter.laser_parameter_size();++i)
-    {
-        int laser_id=m_terminor_parameter.laser_parameter(i).id();
-        int frame_count=m_terminor_parameter.laser_parameter(i).frame_count();
-        if(frame_count<=0)
-        {
-            LOG(WARNING)<<"terminal parameter laser["<<laser_id<<"] frame count is <0";
+    std::vector<Laser_task *> laser_task_vector;
+
+    std::vector<Laser_base *> tp_lasers;
+    for (int i = 0; i < m_terminor_parameter.laser_parameter_size(); ++i) {
+        int laser_id = m_terminor_parameter.laser_parameter(i).id();
+        int frame_count = m_terminor_parameter.laser_parameter(i).frame_count();
+        if (frame_count <= 0) {
+            LOG(WARNING) << "terminal parameter laser[" << laser_id << "] frame count is <0";
             continue;
         }
-        if(laser_id>=0&&laser_id<mp_laser_vector.size())
-        {
+        if (laser_id >= 0 && laser_id < mp_laser_vector.size()) {
             //判断该id的雷达是否已经添加进去, 放置配置中出现重复的雷达编号
-            bool tb_repeat=false;
-            for(int j=0;j<tp_lasers.size();++j)
-            {
-                if(tp_lasers[j]==mp_laser_vector[laser_id])
-                {
-                    tb_repeat=true;
+            bool tb_repeat = false;
+            for (int j = 0; j < tp_lasers.size(); ++j) {
+                if (tp_lasers[j] == mp_laser_vector[laser_id]) {
+                    tb_repeat = true;
                     break;
                 }
             }
-            if(tb_repeat==false)
-            {
+            if (tb_repeat == false) {
                 tp_lasers.push_back(mp_laser_vector[laser_id]);
                 //创建扫描任务,
-                Laser_task* laser_task=new Laser_task();
+                Laser_task *laser_task = new Laser_task();
                 //
-                laser_task->task_init(TASK_CREATED,&scan_cloud,&cloud_lock);
+                laser_task->task_init(TASK_CREATED, &scan_cloud, &cloud_lock);
                 laser_task->set_task_frame_maxnum(frame_count);
                 laser_task->set_save_path(project_path);
                 laser_task_vector.push_back(laser_task);
                 //发送任务单给雷达
-                code=tp_lasers[i]->execute_task(laser_task);
-                if(code!=SUCCESS)
-                {
+                code = tp_lasers[i]->execute_task(laser_task);
+                if (code != SUCCESS) {
                     return code;
                 }
             }
         }
     }
-    if(tp_lasers.size()==0)
-    {
-        return Error_manager(TERMINOR_NOT_CONTAINS_LASER,NORMAL,"terminal not contains laser");
+    if (tp_lasers.size() == 0) {
+        return Error_manager(TERMINOR_NOT_CONTAINS_LASER, NORMAL, "terminal not contains laser");
     }
-    m_terminor_statu=TERMINOR_SCANNING;
+    m_terminor_statu = TERMINOR_SCANNING;
 
     //等待雷达完成任务单
-    while(1)
-    {
+    while (1) {
         //判断是否强制退出
-        if(mb_force_quit==true)
-        {
-            char description[255]={0};
-            sprintf(description,"ternimal is force quit terminal id : %d",m_terminor_parameter.id());
-            return Error_manager(TERMINOR_FORCE_QUIT,NORMAL,description);
+        if (mb_force_quit == true) {
+            char description[255] = {0};
+            sprintf(description, "ternimal is force quit terminal id : %d", m_terminor_parameter.id());
+            return Error_manager(TERMINOR_FORCE_QUIT, NORMAL, description);
         }
         //判断雷达任务单是否全部完成
-        bool tb_laser_complete=true;
-        for(int i=0;i<laser_task_vector.size();++i)
-        {
-            tb_laser_complete &=(TASK_OVER==laser_task_vector[i]->get_statu());
+        bool tb_laser_complete = true;
+        for (int i = 0; i < laser_task_vector.size(); ++i) {
+            tb_laser_complete &= (TASK_OVER == laser_task_vector[i]->get_statu());
         }
-        if(tb_laser_complete)
-        {
+        if (tb_laser_complete) {
             break;
         }
         //计算扫描时间,若超时,并且没有点,则返回错误.
-        auto t_end_point=std::chrono::system_clock::now();
-        auto duration=std::chrono::duration_cast<std::chrono::milliseconds>(t_end_point - t_start_point);
-        double second=double(duration.count()) *
-            std::chrono::milliseconds::period::num / std::chrono::milliseconds::period::den;
-        if(second>m_timeout_second)
-        {
+        auto t_end_point = std::chrono::system_clock::now();
+        auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(t_end_point - t_start_point);
+        double second = double(duration.count()) *
+                        std::chrono::milliseconds::period::num / std::chrono::milliseconds::period::den;
+        if (second > m_timeout_second) {
             //扫描超时,点云中没有点,则返回错误
-            if(scan_cloud.size()==0)
-            {
-                return Error_manager(TERMINOR_LASER_TIMEOUT,MAJOR_ERROR,"laser scanning timeout");
+            if (scan_cloud.size() == 0) {
+                return Error_manager(TERMINOR_LASER_TIMEOUT, MAJOR_ERROR, "laser scanning timeout");
             }
 
 
         }
-        usleep(1000*100);
+        usleep(1000 * 100);
     }
     //检查雷达任务完成情况,是否是正常完成
-    LOG(INFO)<<" laser scanning over cloud size:"<<scan_cloud.size();
+    LOG(INFO) << " laser scanning over cloud size:" << scan_cloud.size();
     //释放扫描任务单
-    for(int i=0;i<laser_task_vector.size();++i)
-    {
-        if(laser_task_vector[i]!=0)
-        {
+    for (int i = 0; i < laser_task_vector.size(); ++i) {
+        if (laser_task_vector[i] != 0) {
             delete laser_task_vector[i];
-            laser_task_vector[i]=NULL;
+            laser_task_vector[i] = NULL;
         }
     }
+
     //第二步,根据区域筛选点云
     pcl::PointCloud<pcl::PointXYZ>::Ptr locate_cloud(new pcl::PointCloud<pcl::PointXYZ>);
     pcl::PassThrough<pcl::PointXYZ> passX;
@@ -425,121 +410,124 @@ Error_manager Terminor_Command_Executor::scanning_measuring()
     pcl::PassThrough<pcl::PointXYZ> passZ;
     passX.setInputCloud(scan_cloud.makeShared());
     passX.setFilterFieldName("x");
-    passX.setFilterLimits(m_terminor_parameter.area_3d().min_x(),m_terminor_parameter.area_3d().max_x());
+    passX.setFilterLimits(m_terminor_parameter.area_3d().min_x(), m_terminor_parameter.area_3d().max_x());
     passX.filter(*locate_cloud);
 
     passY.setInputCloud(locate_cloud);
     passY.setFilterFieldName("y");
-    passY.setFilterLimits(m_terminor_parameter.area_3d().min_y(),m_terminor_parameter.area_3d().max_y());
+    passY.setFilterLimits(m_terminor_parameter.area_3d().min_y(), m_terminor_parameter.area_3d().max_y());
     passY.filter(*locate_cloud);
 
     passY.setInputCloud(locate_cloud);
     passY.setFilterFieldName("z");
-    passY.setFilterLimits(m_terminor_parameter.area_3d().min_z(),m_terminor_parameter.area_3d().max_z());
+    passY.setFilterLimits(m_terminor_parameter.area_3d().min_z(), m_terminor_parameter.area_3d().max_z());
     passY.filter(*locate_cloud);
-    LOG(INFO)<<"筛选点云点数 : "<<locate_cloud->size();
+    LOG(INFO) << "筛选点云点数 : " << locate_cloud->size();
+
+
 
     //第三步,创建测量任务, 进入测量中
-    Locate_task* locate_task=new Locate_task();
+    Locate_task *locate_task = new Locate_task();
     locate_task->set_locate_cloud(locate_cloud);
     locate_task->set_save_path(project_path);
-    m_terminor_statu=TERMINOR_MEASURING;
-    code=mp_locater->execute_task(locate_task);
-    m_measure_information.locate_correct=false;
+    m_terminor_statu = TERMINOR_MEASURING;
+    code = mp_locater->execute_task(locate_task);
+    m_measure_information.locate_correct = false;
     //获取测量结果
-    Locate_information dj_locate_information=locate_task->get_locate_information();
+    Locate_information dj_locate_information = locate_task->get_locate_information();
     //释放locate task
-    if(locate_task!=NULL)
-    {
+    if (locate_task != NULL) {
         delete locate_task;
-        locate_task=NULL;
+        locate_task = NULL;
     }
-    if(code!=SUCCESS)
-    {
+    if (code != SUCCESS) {
         return code;
     }
 
+
     //进入万集雷达流程--------
-    Wj_lidar_Task* wj_task=new Wj_lidar_Task();
-    code=wj_task->init();
-    if(code!=SUCCESS)
-    {
+    Wj_lidar_Task *wj_task = new Wj_lidar_Task();
+    code = wj_task->init();
+    if (code != SUCCESS) {
         delete wj_task;
         return code;
     }
     wj_command t_wj_command;
-    t_wj_command.terminal_id=m_terminor_parameter.id();
-    t_wj_command.command_time=std::chrono::steady_clock::now();
-    t_wj_command.timeout_in_milliseconds=2000;
+    t_wj_command.terminal_id = m_terminor_parameter.id();
+    t_wj_command.command_time = std::chrono::steady_clock::now();
+    t_wj_command.timeout_in_milliseconds = 2000;
     wj_task->set_command(t_wj_command);
-    code=mp_wj_lidar->execute_task(wj_task);
-    if(code!=SUCCESS)
-    {
+    code = mp_wj_lidar->execute_task(wj_task);
+    if (code != SUCCESS) {
         delete wj_task;
         return code;
     }
     ///万集测量正确,对比两数据
     wj_measure_result wj_result;
-    code=wj_task->get_result(wj_result);
-    if(code!=SUCCESS)
-    {
+    code = wj_task->get_result(wj_result);
+    if (code != SUCCESS) {
         delete wj_task;
         return code;
     }
     Locate_information wj_locate_information;
-    wj_locate_information.locate_x=wj_result.x;
-    wj_locate_information.locate_y=wj_result.y;
-    wj_locate_information.locate_theta=wj_result.angle;
-    wj_locate_information.locate_wheel_base=wj_result.wheel_base;
-    wj_locate_information.locate_width=wj_result.width;
+    wj_locate_information.locate_x = wj_result.x;
+    wj_locate_information.locate_y = wj_result.y;
+    wj_locate_information.locate_theta = wj_result.angle;
+    wj_locate_information.locate_wheel_base = wj_result.wheel_base;
+    wj_locate_information.locate_width = wj_result.width;
     //对比两个数据
-    float offset_x=fabs(dj_locate_information.locate_x-wj_locate_information.locate_x);
-    float offset_y=fabs(dj_locate_information.locate_y-wj_locate_information.locate_y);
-    float offset_angle=fabs(dj_locate_information.locate_theta-wj_locate_information.locate_theta);
-    float offset_width=fabs(dj_locate_information.locate_width-wj_locate_information.locate_width);
-    float offset_wheel_base=fabs(dj_locate_information.locate_wheel_base-wj_locate_information.locate_wheel_base);
-    if(offset_x>100 ||offset_y>100 ||offset_angle>4 || offset_wheel_base>200 ||offset_width>200)
-    {
-	LOG(WARNING)<<"chekc failed. (offset x>100, y>100, angle>4, wheel_base>200, width>200): "<<offset_x<<" "<<offset_y<<" "<<offset_angle<<" "<<offset_wheel_base<<" "<<offset_width;
-        return Error_manager(TERMINOR_CHECK_RESULTS_ERROR,NORMAL,"check results failed ");
+    float offset_x = fabs(dj_locate_information.locate_x - wj_locate_information.locate_x);
+    float offset_y = fabs(dj_locate_information.locate_y - wj_locate_information.locate_y);
+    float offset_angle = fabs(dj_locate_information.locate_theta - wj_locate_information.locate_theta);
+    float offset_width = fabs(dj_locate_information.locate_width - wj_locate_information.locate_width);
+    float offset_wheel_base = fabs(
+            dj_locate_information.locate_wheel_base - wj_locate_information.locate_wheel_base);
+    if (offset_x > 100 || offset_y > 100 || offset_angle > 4 || offset_wheel_base > 200 || offset_width > 200) {
+        LOG(WARNING) << "chekc failed. (offset x>100, y>100, angle>4, wheel_base>200, width>200): " << offset_x
+                     << " " << offset_y << " " << offset_angle << " " << offset_wheel_base << " " << offset_width;
+        return Error_manager(TERMINOR_CHECK_RESULTS_ERROR, NORMAL, "check results failed ");
     }
     ///根据两个结果选择最优结果,中心点选择万集雷达,角度选择两值加权,轴距已以2750为基准作卡尔曼滤波
     ///车长以大疆雷达为准,车宽以万集雷达为准,高以大疆雷达为准
-    m_measure_information.locate_x=wj_locate_information.locate_x;
-    m_measure_information.locate_y=wj_locate_information.locate_y;
-    if(offset_angle<2)
-        m_measure_information.locate_theta=0.5*wj_locate_information.locate_theta+0.5*dj_locate_information.locate_theta;
+    m_measure_information.locate_x = wj_locate_information.locate_x;
+    m_measure_information.locate_y = wj_locate_information.locate_y;
+    if (offset_angle < 2)
+        m_measure_information.locate_theta =
+                0.5 * wj_locate_information.locate_theta + 0.5 * dj_locate_information.locate_theta;
     else
-        m_measure_information.locate_theta=0.1*wj_locate_information.locate_theta+0.9*dj_locate_information.locate_theta;
-
-    float dj_distance=fabs(dj_locate_information.locate_wheel_base-2750);
-    float wj_distance=fabs(wj_locate_information.locate_wheel_base-2750);
-    float weight_dj=wj_distance/(dj_distance+wj_distance);
-    float weight_wj=dj_distance/(dj_distance+wj_distance);
-    m_measure_information.locate_wheel_base=weight_dj*dj_locate_information.locate_wheel_base+
-        weight_wj*wj_locate_information.locate_wheel_base;
-    m_measure_information.locate_length=dj_locate_information.locate_length;
-    m_measure_information.locate_width=wj_locate_information.locate_width;
-    m_measure_information.locate_hight=dj_locate_information.locate_hight;
-    m_measure_information.locate_correct=true;
+        m_measure_information.locate_theta =
+                0.1 * wj_locate_information.locate_theta + 0.9 * dj_locate_information.locate_theta;
+
+    float dj_distance = fabs(dj_locate_information.locate_wheel_base - 2750);
+    float wj_distance = fabs(wj_locate_information.locate_wheel_base - 2750);
+    float weight_dj = wj_distance / (dj_distance + wj_distance);
+    float weight_wj = dj_distance / (dj_distance + wj_distance);
+    m_measure_information.locate_wheel_base = weight_dj * dj_locate_information.locate_wheel_base +
+                                              weight_wj * wj_locate_information.locate_wheel_base;
+    m_measure_information.locate_length = dj_locate_information.locate_length;
+    m_measure_information.locate_width = wj_locate_information.locate_width;
+    m_measure_information.locate_hight = dj_locate_information.locate_hight;
+    m_measure_information.locate_correct = true;
     ////如果测量正确,检验结果
-    if(mp_verify_tool!=NULL) {
+    if (mp_verify_tool != NULL) {
 
         cv::RotatedRect rotated_rect;
         rotated_rect.center = cv::Point2f(m_measure_information.locate_x, m_measure_information.locate_y);
         rotated_rect.angle = m_measure_information.locate_theta;
-        float ext_length=720;
-        float robot_width=2650.0;
-        float new_length=m_measure_information.locate_length+ext_length*2.0;
-        rotated_rect=create_rotate_rect(new_length,robot_width,m_measure_information.locate_theta,
-                                        m_measure_information.locate_x, m_measure_information.locate_y);
-        code = mp_verify_tool->verify(rotated_rect,m_measure_information.locate_hight, false);
+        float ext_length = 720;
+        float robot_width = 2650.0;
+        float new_length = m_measure_information.locate_length + ext_length * 2.0;
+        rotated_rect = create_rotate_rect(new_length, robot_width, m_measure_information.locate_theta,
+                                          m_measure_information.locate_x, m_measure_information.locate_y);
+        code = mp_verify_tool->verify(rotated_rect, m_measure_information.locate_hight, false);
         m_measure_information.locate_correct = (code == SUCCESS);
         delete wj_task;
         return code;
 
+    } else {
+        delete wj_task;
     }
-    delete wj_task;
+
     return code;
 }
 

+ 77 - 38
test/locate_sample.cpp

@@ -7,6 +7,7 @@
 #include <fcntl.h>
 #include "../locate/locate_task.h"
 #include "../locate/locater.h"
+#include <pcl/filters/passthrough.h>
 #include <glog/logging.h>
 #include <google/protobuf/io/coded_stream.h>
 #include <google/protobuf/io/zero_copy_stream_impl.h>
@@ -25,7 +26,7 @@ void init_glog()
 {
     FLAGS_max_log_size = 100;
     FLAGS_logbufsecs = 0;
-    google::InitGoogleLogging("LidarMeasurement");
+    google::InitGoogleLogging("LidarMeasurement_test");
     google::SetStderrLogging(google::INFO);
     google::InstallFailureSignalHandler();
     FLAGS_colorlogtostderr = true;        // Set log color
@@ -101,27 +102,28 @@ bool string2point(std::string str,pcl::PointXYZ& point)
     return true;
 }
 
-pcl::PointCloud<pcl::PointXYZ>::Ptr ReadTxtCloud(std::string file)
+void ReadTxtCloud(std::string file, pcl::PointCloud<pcl::PointXYZ> &cloud)
 {
+    cloud.clear();
     std::ifstream fin(file.c_str());
     const int line_length=64;
     char str[line_length]={0};
-    pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
+    // pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
     while(fin.getline(str,line_length))
     {
         pcl::PointXYZ point;
         if(string2point(str,point))
         {
-            cloud->push_back(point);
+            cloud.push_back(point);
         }
     }
-    return cloud;
+    // return *cloud;
 }
 
 int main(int argc,char* argv[])
 {
     init_glog();
-    std::string input_file="balck_suv";
+    std::string input_file="cloud";
     std::string out_path="./test";
     if(argc>=2)
     {
@@ -143,45 +145,82 @@ int main(int argc,char* argv[])
     {
         LOG(ERROR)<<code.to_string();
     }
-    Locate_task* task=new Locate_task();
+    
 
-    std::string cloud_path="/home/zx/data/samples/src_txt/";
+    std::string cloud_path="/home/zx/zzw/code/LidarMeasure/build/";
     cloud_path+=input_file;
     std::vector<std::string> files;
     list_dir(cloud_path.c_str(),files);
     int count=files.size();
-    int correct_size=0;
-    for(int i=0;i<files.size();++i) {
-
-        pcl::PointCloud<pcl::PointXYZ>::Ptr cloud;
-        std::string t_file=cloud_path+"/"+files[i];
-        cloud = ReadTxtCloud(t_file);
-        std::cout << "  input file: " << t_file << std::endl;
-        code = task->set_locate_cloud(cloud);
-        if (code != SUCCESS) {
-            LOG(ERROR) << code.to_string();
-            return 0;
-        }
-        task->set_save_path(out_path);
-        code = locater->execute_task(task, 5);
-        if (code == SUCCESS) {
-            LOG(INFO) << " LOCATE SUCCESS";
-            correct_size++;
-        }
-        else {
-            LOG(ERROR) << code.to_string();
-            //移动文件
-            usleep(300);
-            std::string src="./test/cnn3d.txt";
-            std::string dst="./error/";
-            dst+=files[i];
-            std::string name="mv "+src+" "+dst;
-            const char *des_name=name.c_str();
-
-            system(des_name); //调用系统命令
-            usleep(200);
+    int correct_size = 0;
+    while (1)
+    {
+        int count = 20;
+        while(count-->0){
+
+            for (int i = 0; i < files.size(); ++i)
+            {
+
+                pcl::PointCloud<pcl::PointXYZ> cloud;
+                std::string t_file = cloud_path + "/" + files[i];
+                ReadTxtCloud(t_file, cloud);
+                std::cout << "  input file: " << t_file << std::endl;
+
+                //第二步,根据区域筛选点云
+                pcl::PointCloud<pcl::PointXYZ>::Ptr locate_cloud(new pcl::PointCloud<pcl::PointXYZ>);
+                pcl::PassThrough<pcl::PointXYZ> passX;
+                pcl::PassThrough<pcl::PointXYZ> passY;
+                pcl::PassThrough<pcl::PointXYZ> passZ;
+                passX.setInputCloud(cloud.makeShared());
+                passX.setFilterFieldName("x");
+                passX.setFilterLimits(-100000, 100000);
+                passX.filter(*locate_cloud);
+
+                passY.setInputCloud(locate_cloud);
+                passY.setFilterFieldName("y");
+                passY.setFilterLimits(-100000, 100000);
+                passY.filter(*locate_cloud);
+
+                passY.setInputCloud(locate_cloud);
+                passY.setFilterFieldName("z");
+                passY.setFilterLimits(-100000, 100000);
+                passY.filter(*locate_cloud);
+                LOG(INFO) << "筛选点云点数 : " << locate_cloud->size();
+
+                Locate_task* task=new Locate_task();
+                code = task->set_locate_cloud(locate_cloud);
+                if (code != SUCCESS)
+                {
+                    LOG(ERROR) << code.to_string();
+                    return 0;
+                }
+                task->set_save_path(out_path);
+                code = locater->execute_task(task, 5);
+				Locate_information dj_locate_information = task->get_locate_information();
+                if (code == SUCCESS)
+                {
+                    LOG(INFO) << " LOCATE SUCCESS";
+                    correct_size++;
+                }
+                else
+                {
+                    LOG(ERROR) << code.to_string();
+                    //移动文件
+                    usleep(300);
+                    std::string src = "./test/cnn3d.txt";
+                    std::string dst = "./error/";
+                    dst += files[i];
+                    std::string name = "mv " + src + " " + dst;
+                    const char *des_name = name.c_str();
+
+                    system(des_name); //调用系统命令
+                    usleep(200);
+                }
+                delete task;
+            }
 
         }
+        getchar();
     }
     if(count>0)
     {