|
@@ -53,7 +53,6 @@ Terminor_Command_Executor::Terminor_Command_Executor(Terminal::Terminor_paramete
|
|
|
:m_terminor_statu(TERMINOR_READY), mp_command_thread(0),m_timeout_second(15),mb_force_quit(false)
|
|
|
{
|
|
|
m_terminor_parameter=parameter;
|
|
|
- mp_wj_lidar=NULL;
|
|
|
}
|
|
|
|
|
|
Error_manager Terminor_Command_Executor::force_stop_command()
|
|
@@ -91,8 +90,7 @@ TerminorStatu Terminor_Command_Executor::get_terminor_statu()
|
|
|
return m_terminor_statu;
|
|
|
}
|
|
|
|
|
|
-Error_manager Terminor_Command_Executor::execute_command(std::vector<Laser_base*> lasers,Fence_controller* wj_lidar,
|
|
|
- Plc_Communicator* plc,Locater* locater,Verify_result* verify_tool,float timeout)
|
|
|
+Error_manager Terminor_Command_Executor::execute_command(std::vector<Laser_base*> lasers,float timeout)
|
|
|
{
|
|
|
Error_manager code;
|
|
|
//第一步检查输入参数合法性
|
|
@@ -105,25 +103,6 @@ Error_manager Terminor_Command_Executor::execute_command(std::vector<Laser_base*
|
|
|
return Error_manager(TERMINOR_INPUT_LASER_NULL,NORMAL,description);
|
|
|
}
|
|
|
}
|
|
|
- if(plc==0)
|
|
|
- {
|
|
|
- char description[255]={0};
|
|
|
- sprintf(description,"terminor input plc* is null terminor id:%d",m_terminor_parameter.id());
|
|
|
- return Error_manager(TERMINOR_INPUT_PLC_NULL,NORMAL,description);
|
|
|
- }
|
|
|
- if(wj_lidar==NULL)
|
|
|
- {
|
|
|
- char description[255]={0};
|
|
|
- sprintf(description,"terminor input wj_lidar* is null terminor id:%d",m_terminor_parameter.id());
|
|
|
- return Error_manager(TERMINOR_INPUT_LOCATER_NULL,NORMAL,description);
|
|
|
- }
|
|
|
- if(locater==0)
|
|
|
- {
|
|
|
- char description[255]={0};
|
|
|
- sprintf(description,"terminor input locater* is null terminor id:%d",m_terminor_parameter.id());
|
|
|
- return Error_manager(TERMINOR_INPUT_LOCATER_NULL,NORMAL,description);
|
|
|
- }
|
|
|
- mp_verify_tool=verify_tool;
|
|
|
|
|
|
//第二步,雷达,plc以及定位模块是否能正常接收指令;
|
|
|
for(int i=0;i<lasers.size();++i)
|
|
@@ -135,20 +114,7 @@ Error_manager Terminor_Command_Executor::execute_command(std::vector<Laser_base*
|
|
|
return code;
|
|
|
}
|
|
|
}
|
|
|
- //检查plc状态
|
|
|
- code=plc->get_error();
|
|
|
- if(code!=SUCCESS)
|
|
|
- {
|
|
|
- LOG(ERROR)<<"terminor check plc error : "<<code.to_string()<<" terminor id:"<<m_terminor_parameter.id();
|
|
|
- return code;
|
|
|
- }
|
|
|
- //检查测量模块状态
|
|
|
- code=locater->get_error();
|
|
|
- if(code!=SUCCESS)
|
|
|
- {
|
|
|
- LOG(ERROR)<<"terminor check locater error : "<<code.to_string()<<" terminor id:"<<m_terminor_parameter.id();
|
|
|
- return code;
|
|
|
- }
|
|
|
+
|
|
|
// 检查当前终端指令执行器的状态是否空闲;如果空闲,进入测量流程,设置忙碌状态
|
|
|
std::lock_guard<std::mutex> t_lock(m_mutex_lock);
|
|
|
if(get_terminor_statu()!=TERMINOR_READY)
|
|
@@ -169,9 +135,7 @@ Error_manager Terminor_Command_Executor::execute_command(std::vector<Laser_base*
|
|
|
}
|
|
|
//第二步接受指令,保存输入参数,更新指令状态为TERMINOR_BUSY,启动内部工作线程.返回SUCCESS
|
|
|
mp_laser_vector=lasers;
|
|
|
- mp_plc=plc;
|
|
|
- mp_wj_lidar=wj_lidar;
|
|
|
- mp_locater=locater;
|
|
|
+
|
|
|
m_terminor_statu=TERMINOR_BUSY;
|
|
|
m_timeout_second=timeout;
|
|
|
mp_command_thread=new std::thread(thread_command_working,this);
|
|
@@ -219,8 +183,6 @@ void Terminor_Command_Executor::thread_command_working(Terminor_Command_Executor
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
- //根据结果执行上传任务
|
|
|
- code=terminor->post_measure_information();
|
|
|
//更新终端状态为Ready状态
|
|
|
terminor->m_terminor_statu=TERMINOR_READY;
|
|
|
|
|
@@ -232,62 +194,6 @@ void Terminor_Command_Executor::thread_command_working(Terminor_Command_Executor
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-/*
|
|
|
- * 执行上传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;
|
|
|
- //plc终端编号从1开始,因此,上传给plc的终端编号必须+1
|
|
|
- measure_information.terminal_id=m_terminor_parameter.id()+1;
|
|
|
- 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;
|
|
|
-}
|
|
|
-
|
|
|
void Terminor_Command_Executor::set_save_root_path(std::string root)
|
|
|
{
|
|
|
m_save_root_path=root;
|
|
@@ -349,7 +255,7 @@ Error_manager Terminor_Command_Executor::scanning_measuring()
|
|
|
//
|
|
|
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->set_task_save_path(project_path);
|
|
|
laser_task_vector.push_back(laser_task);
|
|
|
//发送任务单给雷达
|
|
|
code=tp_lasers[i]->execute_task(laser_task);
|
|
@@ -434,98 +340,6 @@ Error_manager Terminor_Command_Executor::scanning_measuring()
|
|
|
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);
|
|
|
- m_measure_information.locate_correct=false;
|
|
|
- //获取测量结果
|
|
|
- Locate_information dj_locate_information=locate_task->get_locate_information();
|
|
|
- //释放locate task
|
|
|
- if(locate_task!=NULL)
|
|
|
- {
|
|
|
- delete locate_task;
|
|
|
- locate_task=NULL;
|
|
|
- }
|
|
|
- if(code!=SUCCESS)
|
|
|
- {
|
|
|
- return code;
|
|
|
- }
|
|
|
-
|
|
|
- //进入万集雷达流程--------
|
|
|
- Wj_lidar_Task* wj_task=new Wj_lidar_Task();
|
|
|
- code=wj_task->init();
|
|
|
- if(code!=SUCCESS)
|
|
|
- {
|
|
|
- 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;
|
|
|
- wj_task->set_command(t_wj_command);
|
|
|
- code=mp_wj_lidar->execute_task(wj_task);
|
|
|
- if(code!=SUCCESS)
|
|
|
- {
|
|
|
- return code;
|
|
|
- }
|
|
|
- ///万集测量正确,对比两数据
|
|
|
- wj_measure_result wj_result;
|
|
|
- code=wj_task->get_result(wj_result);
|
|
|
- if(code!=SUCCESS)
|
|
|
- {
|
|
|
- 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;
|
|
|
- //对比两个数据
|
|
|
- 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_width-wj_locate_information.locate_width);
|
|
|
- if(offset_x>100 ||offset_y>100 ||offset_angle>2 || offset_wheel_base>200 ||offset_width>100)
|
|
|
- {
|
|
|
- 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;
|
|
|
- m_measure_information.locate_theta=0.5*(wj_locate_information.locate_theta+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) {
|
|
|
-
|
|
|
- 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);
|
|
|
- m_measure_information.locate_correct = (code == SUCCESS);
|
|
|
- return code;
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
return code;
|
|
|
}
|
|
|
|