|
@@ -2,6 +2,7 @@
|
|
|
#include <glog/logging.h>
|
|
|
#include <chrono>
|
|
|
#include <pcl/filters/passthrough.h>
|
|
|
+#include "../tool/pathcreator.h"
|
|
|
|
|
|
//////以下两个函数用于测试,读取指定点云
|
|
|
bool string2point(std::string str,pcl::PointXYZ& point)
|
|
@@ -176,26 +177,107 @@ void Terminor_Command_Executor::thread_command_working(Terminor_Command_Executor
|
|
|
return ;
|
|
|
}
|
|
|
//执行指令,阻塞直到指令执行完成或者异常结束
|
|
|
- Error_manager code=terminor->working();
|
|
|
+ Error_manager code=terminor->scanning_measuring();
|
|
|
+ if(code!=SUCCESS)
|
|
|
+ {
|
|
|
+ LOG(ERROR)<<"Command execute failed : "<<code.to_string();
|
|
|
+ }
|
|
|
+ //根据结果执行上传任务
|
|
|
+ code=terminor->post_measure_information();
|
|
|
//更新终端状态为Ready状态
|
|
|
terminor->m_terminor_statu=TERMINOR_READY;
|
|
|
+ if(code!=SUCCESS)
|
|
|
+ {
|
|
|
+ LOG(ERROR)<<"Command execute failed : "<<code.to_string();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ LOG(INFO)<<"Command execute complete!!!";
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+/*
|
|
|
+ * 执行上传plc任务
|
|
|
+ */
|
|
|
+Error_manager Terminor_Command_Executor::post_measure_information()
|
|
|
+{
|
|
|
+ //计时起点
|
|
|
+ auto t_start_point=std::chrono::system_clock::now();
|
|
|
+ Error_manager code;
|
|
|
+ //执行plc上传任务
|
|
|
+ m_terminor_statu=TERMINOR_POSTING;
|
|
|
+ Plc_Task* plc_task=new Plc_Task();
|
|
|
+
|
|
|
+ measure_result measure_information;
|
|
|
+ measure_information.x=m_measure_information.locate_x;
|
|
|
+ measure_information.y=m_measure_information.locate_y;
|
|
|
+ measure_information.angle=m_measure_information.locate_theta;
|
|
|
+ measure_information.length=m_measure_information.locate_length;
|
|
|
+ measure_information.width=m_measure_information.locate_width;
|
|
|
+ measure_information.height=m_measure_information.locate_hight;
|
|
|
+ measure_information.wheel_base=m_measure_information.locate_wheel_base;
|
|
|
+ measure_information.terminal_id=m_terminor_parameter.id();
|
|
|
+ measure_information.correctness=m_measure_information.locate_correct;
|
|
|
+
|
|
|
+ plc_task->set_result(measure_information);
|
|
|
+ code=mp_plc->execute_task(plc_task);
|
|
|
+ while(code!=SUCCESS)
|
|
|
+ {
|
|
|
+ //判断是否强制退出
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ //对于上传不成功,作失败处理,重新传输
|
|
|
+ code=mp_plc->execute_task(plc_task);
|
|
|
+ ///不成功,检测本次流程是否超时
|
|
|
+ if(code!=SUCCESS)
|
|
|
+ {
|
|
|
+ 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)
|
|
|
+ {
|
|
|
+ //扫描超时处理
|
|
|
+ return Error_manager(TERMINOR_POST_PLC_TIMEOUT,NORMAL,"post plc timeout");
|
|
|
+ }
|
|
|
+ usleep(1000*100);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ return code;
|
|
|
}
|
|
|
-Error_manager Terminor_Command_Executor::working()
|
|
|
+
|
|
|
+Error_manager Terminor_Command_Executor::scanning_measuring()
|
|
|
{
|
|
|
//计时起点
|
|
|
auto t_start_point=std::chrono::system_clock::now();
|
|
|
Error_manager code;
|
|
|
//第一步,启动雷达扫描点云,切换当前状态为扫描中
|
|
|
pcl::PointCloud<pcl::PointXYZ>::Ptr scan_cloud(new pcl::PointCloud<pcl::PointXYZ>);
|
|
|
+ std::mutex cloud_lock;
|
|
|
std::vector<Task_Base*> laser_task_vector;
|
|
|
+ PathCreator path_creator;
|
|
|
+ path_creator.CreateDatePath("/home/zx/data/scans");
|
|
|
+ std::string project_path;
|
|
|
+ path_creator.GetCurPath(project_path);
|
|
|
for(int i=0;i<mp_laser_vector.size();++i)
|
|
|
{
|
|
|
Laser_task* laser_task=new Laser_task();
|
|
|
//
|
|
|
- laser_task->task_init(TASK_CREATED,scan_cloud);
|
|
|
+ laser_task->task_init(TASK_CREATED,scan_cloud,&cloud_lock);
|
|
|
laser_task->set_task_points_number(1000);
|
|
|
+ laser_task->set_save_path(project_path);
|
|
|
laser_task_vector.push_back(laser_task);
|
|
|
//发送任务单给雷达
|
|
|
+ code=mp_laser_vector[i]->execute_task(laser_task);
|
|
|
+ if(code!=SUCCESS)
|
|
|
+ {
|
|
|
+ return code;
|
|
|
+ }
|
|
|
}
|
|
|
m_terminor_statu=TERMINOR_SCANNING;
|
|
|
//等待雷达完成任务单
|
|
@@ -231,11 +313,12 @@ Error_manager Terminor_Command_Executor::working()
|
|
|
return Error_manager(TERMINOR_LASER_TIMEOUT,NORMAL,"laser scanning timeout");
|
|
|
}
|
|
|
|
|
|
+
|
|
|
}
|
|
|
usleep(1000*100);
|
|
|
}
|
|
|
//检查雷达任务完成情况,是否是正常完成
|
|
|
-
|
|
|
+ LOG(INFO)<<" laser scanning over cloud size:"<<scan_cloud->size();
|
|
|
//释放扫描任务单
|
|
|
for(int i=0;i<laser_task_vector.size();++i)
|
|
|
{
|
|
@@ -264,11 +347,12 @@ Error_manager Terminor_Command_Executor::working()
|
|
|
passY.setFilterFieldName("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();
|
|
|
|
|
|
//第三步,创建测量任务, 进入测量中
|
|
|
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);
|
|
|
if(code!=SUCCESS)
|
|
@@ -276,56 +360,15 @@ Error_manager Terminor_Command_Executor::working()
|
|
|
//对于失败情况作分别处理
|
|
|
}
|
|
|
//获取测量结果
|
|
|
- Locate_information locate_information=locate_task->get_locate_information();
|
|
|
+ m_measure_information=locate_task->get_locate_information();
|
|
|
//释放locate task
|
|
|
if(locate_task!=NULL)
|
|
|
{
|
|
|
delete locate_task;
|
|
|
locate_task=NULL;
|
|
|
}
|
|
|
- //第四步,测量完成,上传数据
|
|
|
- m_terminor_statu=TERMINOR_POSTING;
|
|
|
- measure_result measure_information;
|
|
|
- measure_information.x=locate_information.locate_x;
|
|
|
- measure_information.y=locate_information.locate_y;
|
|
|
- measure_information.angle=locate_information.locate_theta;
|
|
|
- measure_information.length=locate_information.locate_length;
|
|
|
- measure_information.width=locate_information.locate_width;
|
|
|
- measure_information.height=locate_information.locate_hight;
|
|
|
- measure_information.wheel_base=locate_information.locate_wheel_base;
|
|
|
- measure_information.terminal_id=m_terminor_parameter.id();
|
|
|
- measure_information.correctness=locate_information.locate_correct;
|
|
|
|
|
|
- //执行plc上传任务
|
|
|
- Plc_Task* plc_task=new Plc_Task();
|
|
|
- plc_task->set_result(measure_information);
|
|
|
- code=mp_plc->execute_task(plc_task);
|
|
|
- while(code!=SUCCESS)
|
|
|
- {
|
|
|
- //判断是否强制退出
|
|
|
- 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);
|
|
|
- }
|
|
|
- //对于上传不成功,作失败处理,重新传输
|
|
|
- code=mp_plc->execute_task(plc_task);
|
|
|
- ///不成功,检测本次流程是否超时
|
|
|
- if(code!=SUCCESS)
|
|
|
- {
|
|
|
- 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)
|
|
|
- {
|
|
|
- //扫描超时处理
|
|
|
|
|
|
- }
|
|
|
- usleep(1000*100);
|
|
|
- }
|
|
|
|
|
|
- }
|
|
|
return code;
|
|
|
}
|