数据不移动,在原点收集

master
bestlqiang 5 years ago
parent 1c878cdb72
commit 8a5442f4c5

@ -133,6 +133,9 @@ inline bool IsDbEqual(double a,double b)
class Dbxy class Dbxy
{ {
friend bool operator==(const Dbxy &lhs, const Dbxy &rhs); friend bool operator==(const Dbxy &lhs, const Dbxy &rhs);
friend bool operator!=(const Dbxy &lhs, const Dbxy &rhs);
friend Dbxy operator+(const Dbxy &lhs, const Dbxy &rhs);
friend Dbxy operator-(const Dbxy &lhs, const Dbxy &rhs);
public: public:
Dbxy(double _x,double _y):x(_x),y(_y){}; Dbxy(double _x,double _y):x(_x),y(_y){};
Dbxy() Dbxy()
@ -154,7 +157,18 @@ inline bool operator==(const Dbxy &lhs, const Dbxy &rhs)
{ {
return (IsDbEqual(lhs.x,rhs.x) && IsDbEqual(lhs.y,rhs.y)); return (IsDbEqual(lhs.x,rhs.x) && IsDbEqual(lhs.y,rhs.y));
} }
inline bool operator!=(const Dbxy &lhs, const Dbxy &rhs)
{
return ((!IsDbEqual(lhs.x, rhs.x)) || (!IsDbEqual(lhs.y, rhs.y)));
}
inline Dbxy operator+(const Dbxy &lhs, const Dbxy &rhs)
{
return Dbxy((lhs.x+ rhs.x),(lhs.y+ rhs.y));
}
inline Dbxy operator-(const Dbxy &lhs, const Dbxy &rhs)
{
return Dbxy((lhs.x - rhs.x), (lhs.y - rhs.y));
}
//抓取点的类型 //抓取点的类型
class CCatchPoint :public Dbxy class CCatchPoint :public Dbxy
{ {

@ -240,8 +240,8 @@ void CMarkArea::CollectWorkData(bool bNeedSel,CProduct &Product)
{ {
Dbxy AllOffset2; Dbxy AllOffset2;
AllOffset2 = gCommonFlowMgr->GetAdjustOffsetAll(); AllOffset2 = gCommonFlowMgr->GetAdjustOffsetAll();
Offset.x = AllOffset2.x - m_RealBasePt.x; Offset.x = AllOffset2.x;//-m_RealBasePt.x;
Offset.y = AllOffset2.y - m_RealBasePt.y; Offset.y = AllOffset2.y;// -m_RealBasePt.y;
} }
if(bNeedSel) if(bNeedSel)
@ -286,6 +286,11 @@ void CMarkArea::CollectWorkData(bool bNeedSel,CProduct &Product)
SpecialWorkDataVec.clear(); SpecialWorkDataVec.clear();
return; return;
} }
Product.TheoryDataToRealData(WorkDataVec, m_BasePt,Offset);
Product.TheoryDataToRealData(SpecialWorkDataVec, m_BasePt,Offset);
return;
//根据抓取两个mark 来计算拉伸数据 //根据抓取两个mark 来计算拉伸数据
if(gCommonFlowMgr->IsbStretchDataToRealSize()) if(gCommonFlowMgr->IsbStretchDataToRealSize())
{ {

@ -83,8 +83,8 @@ void CProduct::ResetRealMarkPt()
m_RealMarkPt1.y = 0; m_RealMarkPt1.y = 0;
m_RealMarkPt2.x = 0; m_RealMarkPt2.x = 0;
m_RealMarkPt2.y = 0; m_RealMarkPt2.y = 0;
m_RealMarkPt3.x = 0; //m_RealMarkPt3.x = 0;
m_RealMarkPt3.y = 0; //m_RealMarkPt3.y = 0;
//偏移和旋转都要重设 //偏移和旋转都要重设
m_Offset.x = 0;//理论数据映射为平台坐标的偏移X m_Offset.x = 0;//理论数据映射为平台坐标的偏移X
m_Offset.y = 0;//理论数据映射为平台坐标的偏移Y m_Offset.y = 0;//理论数据映射为平台坐标的偏移Y
@ -140,6 +140,9 @@ void CProduct::SetRealMarkPt(Dbxy pt)
if(!IsSetRealMarkPt1() || !IsSetRealMarkPt2()) if(!IsSetRealMarkPt1() || !IsSetRealMarkPt2())
return; return;
CalAffinePars();
return;
//计算偏移旋转 //计算偏移旋转
CalTheoryToRealPar(); CalTheoryToRealPar();
@ -157,20 +160,98 @@ void CProduct::SetRealMarkPt(Dbxy pt)
CalTheoryToRealPar(); CalTheoryToRealPar();
} }
} }
#include<opencv2/opencv.hpp>
using namespace cv;
void CProduct::CalAffinePars()
{
CString logstr;
o_TheoryMarkPt1 = m_TheoryMarkPt1 - m_BasePt;
logstr.Format("TheoryMarkPt1 Coord(%f,%f)", o_TheoryMarkPt1.x, o_TheoryMarkPt1.y);
gLogMgr->WriteDebugLog(logstr);
o_TheoryMarkPt2 = m_TheoryMarkPt2 - m_BasePt;
logstr.Format("TheoryMarkPt2 Coord(%f,%f)", o_TheoryMarkPt2.x, o_TheoryMarkPt2.y);
gLogMgr->WriteDebugLog(logstr);
o_TheoryMarkPt3 = m_TheoryMarkPt3 - m_BasePt;
logstr.Format("TheoryMarkPt3 Coord(%f,%f)", o_TheoryMarkPt3.x, o_TheoryMarkPt3.y);
gLogMgr->WriteDebugLog(logstr);
o_RealMarkPt1 = m_RealMarkPt1 - m_BasePt;
logstr.Format("RealMarkPt1 Coord(%f,%f)", o_RealMarkPt1.x, o_RealMarkPt1.y);
gLogMgr->WriteDebugLog(logstr);
o_RealMarkPt2 = m_RealMarkPt2 - m_BasePt;
logstr.Format("RealMarkPt2 Coord(%f,%f)", o_RealMarkPt2.x, o_RealMarkPt2.y);
gLogMgr->WriteDebugLog(logstr);
o_RealMarkPt3 = m_RealMarkPt3 - m_BasePt;
logstr.Format("RealMarkPt3 Coord(%f,%f)", o_RealMarkPt3.x, o_RealMarkPt3.y);
gLogMgr->WriteDebugLog(logstr);
double TheoryDis = CalDistance(o_TheoryMarkPt1, o_TheoryMarkPt2);
logstr.Format("[Mark1&2理论间距]: [%f]", TheoryDis);
gLogMgr->WriteDebugLog(logstr);
double RealDis = CalDistance(o_RealMarkPt1, o_RealMarkPt2);
logstr.Format("[Mark1&2真实间距]: [%f]", RealDis);
gLogMgr->WriteDebugLog(logstr);
double DisDiff = abs(TheoryDis - RealDis);
logstr.Format(_T("[Mark 间距误差] = [%f]"), DisDiff);
gLogMgr->WriteDebugLog(logstr);
if (DisDiff > abs(gProductMgr->GetMaxMarkDisDiff()))
{
gTrackWorkFlow1.RadAlamOnOff(true);//报警提示
ResetRealMarkPt();
CString LogStr("Mark 间距误差超出范围,定位可能误判!");
AfxMessageBox(logstr);
gTrackWorkFlow1.RadAlamOnOff(false);//报警提示
CExceptionMsg Msg;
Msg.SetMsg(CString(""));
throw Msg;//抛出异常
/* CExceptionMsg Msg;
Msg.SetMsg(LogStr);
throw Msg;*/
}
Point2f ThroryCoords[3];
Point2f RealCoords[3];
Mat warp_mat(2, 3, CV_32FC1);
ThroryCoords[1] = Point2f(o_TheoryMarkPt1.x, o_TheoryMarkPt1.y);
ThroryCoords[2] = Point2f(o_TheoryMarkPt2.x, o_TheoryMarkPt2.y);
ThroryCoords[0] = Point2f(o_TheoryMarkPt3.x, o_TheoryMarkPt3.y);
RealCoords[1] = Point2f(o_RealMarkPt1.x, o_RealMarkPt1.y);
RealCoords[2] = Point2f(o_RealMarkPt2.x, o_RealMarkPt2.y);
RealCoords[0] = Point2f(o_RealMarkPt3.x, o_RealMarkPt3.y);
//得放射变换参数矩阵
warp_mat = getAffineTransform(ThroryCoords, RealCoords);
warp_mat.convertTo(warp_mat, CV_32FC1);//不转化时,默认CV_64FC1 后续计算会错误
//取出6个变换参数
m_p00 = warp_mat.at<float>(0, 0);
m_p01 = warp_mat.at<float>(0, 1);
m_p02 = warp_mat.at<float>(0, 2);
m_p10 = warp_mat.at<float>(1, 0);
m_p11 = warp_mat.at<float>(1, 1);
m_p12 = warp_mat.at<float>(1, 2);
}
//计算真实数据的偏移和旋转值 //计算真实数据的偏移和旋转值
void CProduct::CalTheoryToRealPar() void CProduct::CalTheoryToRealPar()
{ {
gLogMgr->WriteDebugLog("func : CalTheoryToRealPar"); gLogMgr->WriteDebugLog("func : CalTheoryToRealPar");
if (gLogMgr->IsDebuging())//调试时,理论点用作实际点.
{
m_RealMarkPt1 = m_TheoryMarkPt1;
m_RealMarkPt2 = m_TheoryMarkPt2;
m_Offset.x = 0;
m_Offset.y = 0;
m_RotateAng = 0;
return;
}
//以第一个点的来计算相对的偏移 //以第一个点的来计算相对的偏移
m_Offset.x = m_RealMarkPt1.x - m_TheoryMarkPt1.x; m_Offset.x = m_RealMarkPt1.x - m_TheoryMarkPt1.x;
m_Offset.y = m_RealMarkPt1.y - m_TheoryMarkPt1.y; m_Offset.y = m_RealMarkPt1.y - m_TheoryMarkPt1.y;
@ -263,36 +344,49 @@ void CProduct::CalRealStretchPar()
//理论数据转换为实际数据 //理论数据转换为实际数据
void CProduct::TheoryDataToRealData(vector<Dbxy> &vec,Dbxy &Offset) void CProduct::TheoryDataToRealData(vector<Dbxy> &vec,Dbxy &Offset)
{ {
#ifdef Create_MarkData_file
CStdioFile sf;
if (!sf.Open("MarkData.txt", CFile::modeCreate | CFile::modeReadWrite | CFile::modeNoTruncate))
sf.m_hFile = NULL;
CString str;
vector<Dbxy>::iterator iter = vec.begin(); vector<Dbxy>::iterator iter = vec.begin();
vector<Dbxy>::iterator iter_end = vec.end(); vector<Dbxy>::iterator iter_end = vec.end();
for (; iter != iter_end; iter++) for(;iter!=iter_end;iter++)
{ {
(*iter) = TheoryPtToRealPt((*iter)); (*iter) = TheoryPtToRealPt((*iter));
(*iter).x += Offset.x; (*iter).x += Offset.x;
(*iter).y += Offset.y; (*iter).y += Offset.y;
if (sf.m_hFile != NULL)
{
str.Format("MarkAreaCenter: X=%f;Y=%f \n", (*iter).x, (*iter).y);
sf.SeekToEnd();
sf.WriteString(str);
}
} }
sf.Close(); }
#else
//理论数据转换为实际数据
void CProduct::TheoryDataToRealData(vector<Dbxy> &vec, Dbxy &BaseOffset, Dbxy CutAdjust)
{
vector<Dbxy>::iterator iter = vec.begin(); vector<Dbxy>::iterator iter = vec.begin();
vector<Dbxy>::iterator iter_end = vec.end(); vector<Dbxy>::iterator iter_end = vec.end();
for(;iter!=iter_end;iter++) for (;iter != iter_end;iter++)
{ {
(*iter) = TheoryPtToRealPt((*iter)); //(*iter) = TheoryPtToRealPt((*iter));
(*iter).x += Offset.x; //(*iter) = (*iter) - m_BasePt;
(*iter).y += Offset.y; auto x = (*iter).x;
auto y = (*iter).y;
double retx = m_p00*x + m_p01*y + m_p02+ CutAdjust.x;
double rety = m_p10*x + m_p11*y + m_p12+ CutAdjust.y;
(*iter).x = retx;
(*iter).y = rety;
auto temp = BaseOffset - m_BasePt;
(*iter) = (*iter) - temp;
/*(*iter).x += CutAdjust.x;
(*iter).y += CutAdjust.y;*/
} }
#endif }
void CProduct::ResetAffinePars()
{
m_p00 = 1;
m_p01 = 0;
m_p02 = 0;
m_p10 = 0;
m_p11 = 1;
m_p12 = 0;
} }
//获取实际产品的尺寸比例 //获取实际产品的尺寸比例
Dbxy CProduct::CalRealProductScale() Dbxy CProduct::CalRealProductScale()
@ -434,4 +528,16 @@ void CProduct::TheoryDataToRealData(vector<vector<Dbxy>> &vec,Dbxy &Offset)
} }
} }
//理论数据转换为实际数据
void CProduct::TheoryDataToRealData(vector<vector<Dbxy>> &vec, Dbxy &BaseOffset, Dbxy CutAdjust)
{
gLogMgr->WriteDebugLog("CProduct::TheoryDataToRealData");
vector<vector<Dbxy>>::iterator iter = vec.begin();
vector<vector<Dbxy>>::iterator iter_end = vec.end();
for (;iter != iter_end;iter++)
{
TheoryDataToRealData(*iter, BaseOffset,CutAdjust);
}
}
#endif #endif

@ -28,9 +28,14 @@ public:
void SetTheoryMark3Pt(Dbxy pt){m_TheoryMarkPt3 = pt;}; void SetTheoryMark3Pt(Dbxy pt){m_TheoryMarkPt3 = pt;};
void SetRealMark3Pt(Dbxy pt){m_RealMarkPt3 = pt;}; void SetRealMark3Pt(Dbxy pt){m_RealMarkPt3 = pt;};
Dbxy TheoryPtToRealPt(Dbxy TheoryMarkPt); Dbxy TheoryPtToRealPt(Dbxy TheoryMarkPt);
void TheoryDataToRealData(vector<vector<Dbxy>> &vec,Dbxy &Offset);
void StretchDataToRealSize(vector<vector<Dbxy>> &vec); void StretchDataToRealSize(vector<vector<Dbxy>> &vec);
void TheoryDataToRealData(vector<Dbxy> &vec,Dbxy &Offset);
void TheoryDataToRealData(vector<vector<Dbxy>> &vec, Dbxy &Offset);
void TheoryDataToRealData(vector<Dbxy> &vec, Dbxy &Offset);
void TheoryDataToRealData(vector<Dbxy>& vec, Dbxy & BaseOffset, Dbxy CutAdjust);
void ResetAffinePars();//重置仿射变换参数
void TheoryDataToRealData(vector<vector<Dbxy>>& vec, Dbxy & BaseOffset, Dbxy CutAdjust);
void TheoryDataToRealData(vector<vector<Dbxy>> &SrcVec,vector<vector<Dbxy>> &DecVec,Dbxy &Offset); void TheoryDataToRealData(vector<vector<Dbxy>> &SrcVec,vector<vector<Dbxy>> &DecVec,Dbxy &Offset);
void TheoryDataToRealData(vector<Dbxy> &SrcVec,vector<Dbxy> &DecVec,Dbxy &Offset); void TheoryDataToRealData(vector<Dbxy> &SrcVec,vector<Dbxy> &DecVec,Dbxy &Offset);
bool IsSetRealMarkPt1(); bool IsSetRealMarkPt1();
@ -42,12 +47,13 @@ public:
void SetbNewAddProduct(bool bNew) { m_bNewAddProduct = bNew; };//设置是否是改造新增的产品 void SetbNewAddProduct(bool bNew) { m_bNewAddProduct = bNew; };//设置是否是改造新增的产品
bool IsbNewAddProduct() { return m_bNewAddProduct; };//查询是否是改造新增的产品 bool IsbNewAddProduct() { return m_bNewAddProduct; };//查询是否是改造新增的产品
private: private:
void CalAffinePars();
void CalTheoryToRealPar(); void CalTheoryToRealPar();
Dbxy CalRealProductScale(); Dbxy CalRealProductScale();
void StretchPt(Dbxy &Pt,SObjOperatePar &Par); void StretchPt(Dbxy &Pt,SObjOperatePar &Par);
void CalRealStretchPar(); void CalRealStretchPar();
double CalRealProductScaleExt(Dbxy TheoryMarkPt1,Dbxy TheoryMarkPt2,Dbxy RealMarkPt1,Dbxy RealMarkPt2); double CalRealProductScaleExt(Dbxy TheoryMarkPt1,Dbxy TheoryMarkPt2,Dbxy RealMarkPt1,Dbxy RealMarkPt2);
public: private:
Dbxy m_BasePt;//工件的基准坐标点 Dbxy m_BasePt;//工件的基准坐标点
bool m_bUsed;//是否使用 bool m_bUsed;//是否使用
bool m_bLastOne;//是否为最后一个 bool m_bLastOne;//是否为最后一个
@ -62,6 +68,23 @@ public:
Dbxy m_RealMarkPt1;//真实坐标(相对于激光中心点) mm Dbxy m_RealMarkPt1;//真实坐标(相对于激光中心点) mm
Dbxy m_RealMarkPt2; Dbxy m_RealMarkPt2;
Dbxy m_RealMarkPt3; Dbxy m_RealMarkPt3;
public:
Dbxy o_TheoryMarkPt1;//理论坐标(不移动时) mm
Dbxy o_TheoryMarkPt2;
Dbxy o_TheoryMarkPt3;
//ccd 抓取的实际值------------------------------------
Dbxy o_RealMarkPt1;//真实坐标(不移动时) mm
Dbxy o_RealMarkPt2;
Dbxy o_RealMarkPt3;
//仿射参数------------------------------------
float m_p00=1;
float m_p01=0;
float m_p02=0;
float m_p10=0;
float m_p11=1;
float m_p12=0;
public: public:
//实际偏移旋转结果--------------------------------- //实际偏移旋转结果---------------------------------
Dbxy m_Offset;//理论数据映射为平台坐标的偏移 Dbxy m_Offset;//理论数据映射为平台坐标的偏移

@ -817,8 +817,8 @@ void CTrackWorkFlow::MarkProcess()
//设置当前的工作步骤 //设置当前的工作步骤
SetCurTrackWorkStep(_ETrack_Step_Marking); SetCurTrackWorkStep(_ETrack_Step_Marking);
//数据移动回默认的位置 //数据移动回默认的位置
gProgramCutMgr->MoveObjData(Dbxy(0, 0)); //gProgramCutMgr->MoveObjData(Dbxy(0, 0));
gMarkAreaMgr->MoveAllAreaToTargetPt(Dbxy(0, 0)); //gMarkAreaMgr->MoveAllAreaToTargetPt(Dbxy(0, 0));
//gCurLockTrackType = _ETrackType_NULL;//解锁 //gCurLockTrackType = _ETrackType_NULL;//解锁
@ -839,6 +839,8 @@ bool CTrackWorkFlow::MarkProcessExt()
//gProgram_SZ_XL->SetCurMarkingTrack(m_TrackType); //gProgram_SZ_XL->SetCurMarkingTrack(m_TrackType);
CProduct &Product = gServer->m_RcvProduct; CProduct &Product = gServer->m_RcvProduct;
/*
Dbxy BasePt = Product.GetProductBasePt(); Dbxy BasePt = Product.GetProductBasePt();
//=======移动obj============== //=======移动obj==============
gProgramCutMgr->MoveObjData(BasePt); gProgramCutMgr->MoveObjData(BasePt);
@ -847,6 +849,7 @@ bool CTrackWorkFlow::MarkProcessExt()
gObjComponentMgr->CalAllObjCenterPt(); gObjComponentMgr->CalAllObjCenterPt();
Dbxy AllObjCenterPt = gObjComponentMgr->GetAllObjCenterPt(); Dbxy AllObjCenterPt = gObjComponentMgr->GetAllObjCenterPt();
gMarkAreaMgr->MoveAllAreaToTargetPt(AllObjCenterPt); gMarkAreaMgr->MoveAllAreaToTargetPt(AllObjCenterPt);
*/
bool Ret; bool Ret;
//启动切割 //启动切割

@ -57,7 +57,8 @@ bool CWorkCmdMarkArea::Excute()
m_MarkArea.SetSelState(true);//选择当前加工的area m_MarkArea.SetSelState(true);//选择当前加工的area
//设置markarea 内的obj 为已加工状态 //设置markarea 内的obj 为已加工状态
gObjComponentMgr->SetMarkedStateRect(m_MarkArea.GetRect(),m_bSelMark); // gObjComponentMgr->SetMarkedStateRect(m_MarkArea.GetRect(), m_bSelMark);
gObjComponentMgr->SetMarkedStateRect(m_MarkArea.GetRect(),true);
//可能会引起报错? //可能会引起报错?
//m_pView->MoveViewCenter(); //m_pView->MoveViewCenter();
//m_pView->RefreshView(); //m_pView->RefreshView();

Binary file not shown.
Loading…
Cancel
Save