You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

223 lines
9.2 KiB
C++

#include "StdAfx.h"
#include "Laser.h"
#include "Propertie.h"
#include "PropertieMgr.h"
#include "AuthorityMgr.h"
#include "MsgBox.h"
#include "Motor.h"
#include "ExceptionMsg.h"
#include "WorkCmdContainer.h"
#include "WorkCmdMoveMotor.h"
CLaser *gLaser = new CLaser;
CLaser::CLaser(void)
{
m_OpenDelay = 0;//开关后延时 ms
m_BaseThickness = 0;//用来调试焦距的基准产品厚度mm
m_WorkThickness = 0;//当前加工的产品厚度mm
m_MaxThickness = 1;//最大产品厚度mm
m_MinThickness = 1;//最小产品厚度mm
}
CLaser::~CLaser(void)
{
}
CMFCPropertyGridProperty *CLaser::CreatGridProperty()
{
CString PropertyName;//属性名称
CString Description;//描述
CString Path = _T("Laser");//存储路径
CString Name;
//-------------------------------------------------------------------------------//
PropertyName = _T("激光");
CMFCPropertyGridProperty* pGroup = new CMFCPropertyGridProperty(PropertyName);
//-------------------------------------------------------------------------------//
if(gAuthorityMgr->CheckAuthority(_FACTORY))
{
{
//添加属性变量映射
Name = _T("m_OpenDelay");//变量名字
CPropertie *pPropertie = new CPropertie;
pPropertie->SetpVal((void*)&m_OpenDelay);
pPropertie->SetType(_PROP_TYPE_INT);
pPropertie->SetpModule(this);
pPropertie->SetPath(Path);
pPropertie->SetName(Name);
pPropertie->WriteRead(true);//读取保存的属性
//添加属性显示
PropertyName = _T("开关后延时");
Description = _T("激光打开后的延时时间,等待能量上升(ms)");
CMFCPropertyGridProperty* p1 = new CMFCPropertyGridProperty(PropertyName,(_variant_t)m_OpenDelay, Description);
pGroup->AddSubItem(p1);
gDevicePropertieMgr.Insert(p1, pPropertie);
}
{
//添加属性变量映射
Name = _T("m_CutSpeedIncrement");//变量名字
CPropertie *pPropertie = new CPropertie;
pPropertie->SetpVal((void*)&m_CutSpeedIncrement);
pPropertie->SetType(_PROP_TYPE_INT);
pPropertie->SetpModule(this);
pPropertie->SetPath(Path);
pPropertie->SetName(Name);
pPropertie->WriteRead(true);//读取保存的属性
//添加属性显示
PropertyName = _T("切速增量");
Description = _T("激光切割时,相对主机的速度增量.");
CMFCPropertyGridProperty* p1 = new CMFCPropertyGridProperty(PropertyName, (_variant_t)m_CutSpeedIncrement, Description);
pGroup->AddSubItem(p1);
gDevicePropertieMgr.Insert(p1, pPropertie);
}
{
//添加属性变量映射
Name = _T("m_LaserCoord_x");//变量名字
CPropertie *pPropertie = new CPropertie;
pPropertie->SetpVal((void*)&m_LaserCoord.x);
pPropertie->SetType(_PROP_TYPE_DOUBLE);
pPropertie->SetpModule(this);
pPropertie->SetPath(Path);
pPropertie->SetName(Name);
pPropertie->WriteRead(true);//读取保存的属性
//添加属性显示
PropertyName = _T("激光坐标X");
Description = _T("激光中心相对原点的坐标X");
CMFCPropertyGridProperty* p1 = new CMFCPropertyGridProperty(PropertyName,(_variant_t)m_LaserCoord.x, Description);
pGroup->AddSubItem(p1);
gDevicePropertieMgr.Insert(p1, pPropertie);
}
{
//添加属性变量映射
Name = _T("m_LaserCoord_y");//变量名字
CPropertie *pPropertie = new CPropertie;
pPropertie->SetpVal((void*)&m_LaserCoord.y);
pPropertie->SetType(_PROP_TYPE_DOUBLE);
pPropertie->SetpModule(this);
pPropertie->SetPath(Path);
pPropertie->SetName(Name);
pPropertie->WriteRead(true);//读取保存的属性
//添加属性显示
PropertyName = _T("激光坐标Y");
Description = _T("激光中心相对原点的坐标Y");
CMFCPropertyGridProperty* p1 = new CMFCPropertyGridProperty(PropertyName,(_variant_t)m_LaserCoord.y, Description);
pGroup->AddSubItem(p1);
gDevicePropertieMgr.Insert(p1, pPropertie);
}
{
//添加属性变量映射
Name = _T("m_BaseThickness");//变量名字
CPropertie *pPropertie = new CPropertie;
pPropertie->SetpVal((void*)&m_BaseThickness);
pPropertie->SetType(_PROP_TYPE_DOUBLE);
pPropertie->SetpModule(this);
pPropertie->SetPath(Path);
pPropertie->SetName(Name);
pPropertie->WriteRead(true);//读取保存的属性
//添加属性显示
PropertyName = _T("基准产品厚度");
Description = _T("用来调试焦距的基准产品厚度,用于自动变焦mm");
CMFCPropertyGridProperty* p1 = new CMFCPropertyGridProperty(PropertyName,(_variant_t)m_BaseThickness, Description);
pGroup->AddSubItem(p1);
gDevicePropertieMgr.Insert(p1, pPropertie);
}
{
//添加属性变量映射
Name = _T("m_WorkThickness");//变量名字
CPropertie *pPropertie = new CPropertie;
pPropertie->SetpVal((void*)&m_WorkThickness);
pPropertie->SetType(_PROP_TYPE_DOUBLE);
pPropertie->SetpModule(this);
pPropertie->SetPath(Path);
pPropertie->SetName(Name);
pPropertie->WriteRead(true);//读取保存的属性
//添加属性显示
PropertyName = _T("当前产品厚度");
Description = _T("当前加工的产品厚度mm");
CMFCPropertyGridProperty* p1 = new CMFCPropertyGridProperty(PropertyName,(_variant_t)m_WorkThickness, Description);
pGroup->AddSubItem(p1);
gDevicePropertieMgr.Insert(p1, pPropertie);
}
{
//添加属性变量映射
Name = _T("m_MaxThickness");//变量名字
CPropertie *pPropertie = new CPropertie;
pPropertie->SetpVal((void*)&m_MaxThickness);
pPropertie->SetType(_PROP_TYPE_DOUBLE);
pPropertie->SetpModule(this);
pPropertie->SetPath(Path);
pPropertie->SetName(Name);
pPropertie->WriteRead(true);//读取保存的属性
//添加属性显示
PropertyName = _T("最大产品厚度");
Description = _T("最大的产品厚度mm");
CMFCPropertyGridProperty* p1 = new CMFCPropertyGridProperty(PropertyName,(_variant_t)m_MaxThickness, Description);
pGroup->AddSubItem(p1);
gDevicePropertieMgr.Insert(p1, pPropertie);
}
{
//添加属性变量映射
Name = _T("m_MinThickness");//变量名字
CPropertie *pPropertie = new CPropertie;
pPropertie->SetpVal((void*)&m_MinThickness);
pPropertie->SetType(_PROP_TYPE_DOUBLE);
pPropertie->SetpModule(this);
pPropertie->SetPath(Path);
pPropertie->SetName(Name);
pPropertie->WriteRead(true);//读取保存的属性
//添加属性显示
PropertyName = _T("最小产品厚度");
Description = _T("最小的产品厚度mm");
CMFCPropertyGridProperty* p1 = new CMFCPropertyGridProperty(PropertyName,(_variant_t)m_MinThickness, Description);
pGroup->AddSubItem(p1);
gDevicePropertieMgr.Insert(p1, pPropertie);
}
}
//-------------------------------------------------------------------------------//
return pGroup;
}
//工作文件另存为
void CLaser::WriteWorkFileExt(vector<CLab> &LabVec)
{
LabVec.push_back(CLab(LAB_NULL,m_WorkThickness));//产品厚度
}
void CLaser::ReadWorkFile(CLabVecRang &LabVecRang)
{
int idx = LabVecRang.GetStart()+1;
m_WorkThickness = LabVecRang.GetDouble(idx++);
}
//添加调整焦距指令
void CLaser::AddAdjustFocalCmd()
{
CMotor &Motor = *(CMotor::GetMotor(MOTOR_Z));
double TargetCoord = m_WorkThickness-m_BaseThickness;//目标焦距位置
//和当前焦距位置不相等才需要调整
if(!IsTwoDbEqual(Motor.GetCoord(),TargetCoord))
{
CWorkCmdContainer &CmdContainer = CWorkCmdContainer::GetInstance();
CWorkCmdMoveMotor *pCmd = new CWorkCmdMoveMotor(Motor,TargetCoord);
pCmd->SetMoveFlg(false);//移动到坐标
CmdContainer.AddCmd(pCmd);
}
}
//获取当前焦距的调整量
double CLaser::GetFocalAdjustVal()
{
double AdjustVal = 0;
if(m_WorkThickness>=m_MinThickness && m_WorkThickness<=m_MaxThickness)
{
AdjustVal = m_BaseThickness - m_WorkThickness;
}
return AdjustVal;
}
//开光前响应
void CLaser::OnOpen()
{
Sleep(GetOpenDelay());
}
//关光后响应
void CLaser::OnClose()
{
}