📄 beihangdlg.cpp
字号:
arrButton.Add(IDCANCEL);
arrButton.Add(IDC_SSTAB_SCAN);
return true;
}
BEGIN_EVENTSINK_MAP(CBeihangDlg, CDialog)
//{{AFX_EVENTSINK_MAP(CBeihangDlg)
// ON_EVENT(CBeihangDlg, IDC_SSTAB_SCAN, -605 /* MouseDown */, OnMsDwSstab, VTS_I2 VTS_I2 VTS_I4 VTS_I4)
//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()
/***************************************************************************/
/*函数名称:OnMsDwSstab */
/*函数功能:确定“Jog控制及Z轴连续运动”和“2轴扫查序列”选项切换 */
/*参数说明:Button——确定哪个鼠标键动作。 */
/* X——鼠标在屏幕上单击位置的X坐标。 */
/* Y——鼠标在屏幕上单击位置的Y坐标。 */
/*开发人员:陈利民 */
/*开发日期:2006-01-20 */
/***************************************************************************/
/*void CBeihangDlg::OnMsDwSstab(short Button, short Shift, long X, long Y)
{
// TODO: Add your control notification handler code here
if (X>0 && X<=160 && Y>0 && Y<20)
{
VisSwitch(0, true);
}
else if (X>160 && X<324 && Y>0 && Y<20)
{
VisSwitch(1,TRUE);
}
}
*/
/***************************************************************************/
/*函数名称:VisSwitch */
/*函数功能:确定“Jog控制及Z轴连续运动”和“2轴扫查序列”的控件可见 */
/*参数说明:nTab——哪个选项卡被选中。 */
/* nTab0——选中“Jog控制及Z轴连续运动”。 */
/* nTab1——2轴扫查序列。 */
/* status——未分配功能 */
/*开发人员:陈利民 */
/*开发日期:2006-01-20 */
/***************************************************************************/
bool CBeihangDlg::VisSwitch(int nTab, bool status)
{
int nIndex, nCtls;
if (nTab==0)
{
CWnd * pWnd;
for (nIndex=0; nIndex<33; nIndex++)
{
nCtls=arrButton[nIndex];
pWnd=GetDlgItem(nCtls);
if(pWnd!=NULL)
pWnd->ShowWindow(1);
}
for (nIndex=33; nIndex<62; nIndex++)
{
nCtls=arrButton[nIndex];
pWnd=GetDlgItem(nCtls);
if(pWnd!=NULL)
pWnd->ShowWindow(0);
}
}
else if(nTab==1)
{
CWnd * pWnd;
for (nIndex=0; nIndex<33; nIndex++)
{
nCtls=arrButton[nIndex];
pWnd=GetDlgItem(nCtls);
if(pWnd!=NULL)
pWnd->ShowWindow(0);
}
for (nIndex=33; nIndex<62; nIndex++)
{
nCtls=arrButton[nIndex];
pWnd=GetDlgItem(nCtls);
if(pWnd!=NULL)
pWnd->ShowWindow(1);
if(nIndex==51||nIndex==54)
pWnd->EnableWindow(0);
}
}
else
{
return false;
}
return true;
}
void CBeihangDlg::OnButtonRGoto()
{
// TODO: Add your control notification handler code here
// TODO: Add your control notification handler code here
bBreak=0;
runinfocnt=0;
short rtn;
int period=200;
int ISR_Sta=0;
unsigned short lmtvolt=255;
unsigned int sense=0xF;
int total_axes=2;
int Pulse_mode=2;
int cur_axis=2;
bool axis_sta=true;
rtn=DLL_Full_Initial(period, ISR_Sta, lmtvolt, sense, total_axes, Pulse_mode);
GT_Axis(2);
/*根据复选框的选项判断是否使能驱动器 */
int m_nSpeedl=m_ctlCM_R_SPEED.GetCurSel();
double m_dblAxisSpeed=arrSpeed[m_nSpeedl] * 60;
axis_sta=true;
rtn=DLL_Axis_OnOff(2, axis_sta);
UpdateData(TRUE);
if(m_dblRObjPos+m_dblRCurPos>=-360&&m_dblRObjPos+m_dblRCurPos<=360)
{ curaxis=2;
curspeed=m_dblAxisSpeed;
rtn=DLL_R_Run(m_dblAxisSpeed,360,0,10,5000,200);
if(zerosit==-1)
{
m_dblRObjPos=-m_dblRCurPos;
}
rtn=params.axisRrun(m_dblAxisSpeed,m_dblRObjPos);
m_dblRCurPos+=m_dblRObjPos;
UpdateData(0);
pv->draw();
}
else
{
CWnd* pwnd=this->GetDlgItem(IDC_EDIT_R_OBJPOS);
pwnd->SetWindowText("0");
}
}
void CBeihangDlg::OnButtonRPause()
{
// TODO: Add your control notification handler code here
unsigned short Curren_Axis=2,Status;
short rtn=GT_GetSts(&Status);
if(!(Status&1))
{if(!DLL_SngAxis_eStop(Curren_Axis))
{AfxMessageBox("R轴停车失败");
}
else
{
GetSystemTime(&t2);
ltime=(t2.wDay-t1.wDay)*3600*24+(t2.wHour-t1.wHour)*3600+\
(t2.wMinute-t1.wMinute)*60+t2.wSecond-t1.wSecond\
+(t2.wMilliseconds-t1.wMilliseconds)/1000.0;
m_dblRCurPos-=m_dblRObjPos;
m_dblRCurPos+=((int)(curspeed*ltime*10))/10.;
// m_dblRCurPos+=params.atlrpos();
m_dblRObjPos=0;
curspeed=0;
UpdateData(0);
}
}
}
void CBeihangDlg::OnBtnZGoto()
{ bBreak=0;
runinfocnt=0;
// TODO: Add your control notification handler code here
short rtn;
int period=200;
int ISR_Sta=0;
unsigned short lmtvolt=255;
unsigned int sense=0xF;
int total_axes=2;
int Pulse_mode=2;
int cur_axis=1;
bool axis_sta=true;
rtn=DLL_Full_Initial(period, ISR_Sta, lmtvolt, sense, total_axes, Pulse_mode);
int m_nSpeedNo=m_ctlCM_Z_SPEED.GetCurSel();
double m_dblAxisSpeed=arrSpeed[m_nSpeedNo] * 20;
double m_dblTimeAlfa=m_nSpeedNo*0.3;
axis_sta=true;
rtn=DLL_Axis_OnOff(cur_axis, axis_sta);
UpdateData(TRUE);
curspeed=m_dblAxisSpeed;
curaxis=1;
rtn=DLL_Z_Run(m_dblAxisSpeed,10,0,/*m_ZObjPos*50/56.2*/1,5000,200);
if(zerosit==-1)
{
m_ZObjPos=-m_dblZCurPos;
m_dblAxisSpeed=-m_dblAxisSpeed;
}
// rtn=GT_CaptProb();
rtn=params.axisZrun(m_dblAxisSpeed,m_ZObjPos);
etime=abs(m_ZObjPos/m_dblAxisSpeed)+3;
m_dblZCurPos+=m_ZObjPos;
UpdateData(0);
// long stime,ctime;
// time(&stime);
// ctime=stime;
// while(ctime<=stime+etime)
// time(&ctime);
// int c=runinfocnt;
//GT_Axis(1);
//GT_GetAtlPos(&stime);
pv->draw();
}
void CBeihangDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
/**************************************************************************/
/*以下为Z轴连续运动控制代码——1号定时器 */
/**************************************************************************/
if (nIDEvent==1)
{
UpdateData(TRUE);//变量初始化
short rtn;
int period=200;
int ISR_Sta=0;
unsigned short lmtvolt=255;
unsigned int sense=0xF;
int total_axes=2;
int Pulse_mode=2;
int cur_axis=1;
bool axis_sta=true;
static int time_start;
double m_dblTimeAlfa=(m_dblZSpeedCon/15)+1 ;
double m_nTime=fabs(m_dblZEnd)/m_dblZSpeedCon;
int time_temp=time(<ime);
if (m_dblZSpeedCon>50 || m_dblZSpeedCon<0)
{
KillTimer(1);
MessageBox("速度超限");
goto End;
}
if (m_dblStart<=0)
{
KillTimer(1);
goto End;
}
if (m_nZConTimes==0)//本次操作的首次运动
{
m_dblZEndCon=m_dblZEnd;
rtn=DLL_Full_Initial(period, ISR_Sta, lmtvolt, sense, total_axes, Pulse_mode);
axis_sta=true;
rtn=DLL_Axis_OnOff(1, axis_sta);
time_start=time(<ime);
curspeed=m_dblZSpeedCon;
curaxis=1;
rtn=DLL_Z_Run(m_dblZSpeedCon,10,0,1,5000,200);
rtn=params.axisZrun(m_dblZSpeedCon,m_dblZEndCon);
m_dblZCurPos+=m_dblZEndCon;
UpdateData(0);
m_nZConTimes++;
}
if ((double)(time_temp-time_start)<(m_nTime+m_dblTimeAlfa))
{
goto End;//运动未完成,跳出本次执行
}
else//本次运动完成,执行后面操作
{
if (m_nZConTimes>=(int)m_dblStart*2)//全部运动完成,结束运行,关闭定时器
{
flag=1;
m_nZConTimes=0;
KillTimer(1);
static char pinfo[]="运动成功完成,Z轴扫描运动";
runinfo[runinfocnt++]=pinfo;
pv->draw();
goto End;
}
//运动没有全部完成,继续下次运动操作
m_dblZEndCon=-1 * m_dblZEndCon;
rtn=DLL_Full_Initial(period, ISR_Sta, lmtvolt, sense, total_axes, Pulse_mode);
axis_sta=true;
rtn=DLL_Axis_OnOff(1, axis_sta);
curaxis=1;
curspeed=m_dblZSpeedCon;
rtn=DLL_Z_Run(m_dblZSpeedCon,10,0,1,5000,200);
rtn=params.axisZrun(m_dblZSpeedCon,m_dblZEndCon);
m_dblZCurPos+=m_dblZEndCon;
UpdateData(0);
time_start=time(<ime);
m_nZConTimes++;
}
End:
int test=1;
}
/**************************************************************************/
/*以下为两轴连续运动控制代码——2号定时器 */
/**************************************************************************/
if (nIDEvent==2)
{ BOOL bFirstR=1;
UpdateData(TRUE);
m_dblConRStart=m_dblRCurPos;
m_dblConZStart=m_dblZCurPos;
UpdateData(0);
short rtn;
int period=200;
int ISR_Sta=0;
unsigned short lmtvolt=255;
unsigned int sense=0xF;
int total_axes=2;
int Pulse_mode=2;
int cur_axis=1;
bool axis_sta=true;
double m_dblZStepScan=m_dblConZStep;
double m_dblConRDis=m_dblConRDistance;
double m_dblTimeAlfa=(m_dblConZSpeed/15);
double m_nTime=fabs(m_dblConZStart)/m_dblConZSpeed;
static int time_start=time( <ime );
int time_temp;
double m_dblZEndCon=m_dblConRDistance;
double m_dblNextRPos=nArrAxisR.GetAt(m_nTwoConTimes+1);
double m_dblNextZPos=nArrAxisZ.GetAt(m_nTwoConTimes+1);
GT_Axis(2);
unsigned short status;
GT_GetSts(&status);
/*if ((status & 0x5)==1 && m_nTwoConTimes>0)
{
MessageBox("2轴限位报警!","2轴扫查",MB_OK);
KillTimer(2);
goto End2;
}*/
//if (!status&0x6)
//MessageBox("2轴反向限位报警!","2轴扫查",MB_OK);*/
/*判断最大速度是否超限*/
if (m_dblConRSpeed>60 || m_dblConRSpeed<0)
{
KillTimer(2);
MessageBox("R速度超限");
goto End2;
}
if (m_dblConZSpeed>16 || m_dblConZSpeed<0)
{
KillTimer(2);
MessageBox("Z速度超限");
goto End2;
}
if (m_nTwoConTimes==1)
{
cur_axis=1;
}
/*R轴单轴运动到位*/
if (RFinFlag==0)
{
if (RRunFlag==0)
{
time_start=time( <ime );
rtn=DLL_Full_Initial(period, ISR_Sta, lmtvolt, sense, total_axes, Pulse_mode);
axis_sta=true;
rtn=DLL_Axis_OnOff(2, axis_sta);
curaxis=2;
curspeed=m_dblConRSpeed;
curspeedr=m_dblConRSpeed;
rtn=DLL_R_Run(m_dblConRSpeed,360,0,10,5000,200);
rtn=params.axisRrun(m_dblConRSpeed,m_dblNextRPos*(1+360/120.0));
RRunFlag=1;
goto End2;
}
if (RRunFlag==1)
{
m_dblTimeAlfa=(m_dblConRSpeed/15);
m_nTime=fabs(m_dblConRDistance)/m_dblConRSpeed;
time_temp=time( <ime );
//+m_dblTimeAlfa
if ((double)(time_temp-time_start)<m_nTime+1)
{
goto End2;//运动未完成,跳出本次执行
}
else
{
RFinFlag=1;
RRunFlag=0;
ZFinFlag=0;
ZRunFlag=0;
m_dblRCurPos+=m_dblNextRPos;
UpdateData(0);
}
}
}
/*Z轴单轴运动到位*/
if (ZFinFlag==0)
{
if (ZRunFlag==0)
{
time_start=time( <ime );
rtn=DLL_Full_Initial(period, ISR_Sta, lmtvolt, sense, total_axes, Pulse_mode);
axis_sta=true;
rtn=DLL_Axis_OnOff(1, axis_sta);
curspeed=m_dblConZSpeed;
curaxis=1;
rtn=DLL_Z_Run(m_dblConZSpeed,10,0,1,5000,200);
rtn=params.axisZrun(m_dblConZSpeed,m_dblNextZPos);
ZRunFlag=1;
}
if (ZRunFlag==1)
{
time_temp=time( <ime );
//+m_dblTimeAlfa
if (m_nTwoConTimes==0)
{
m_nTime=fabs(m_dblConZStart)/m_dblConZSpeed;
}else{
m_nTime=fabs(m_dblConZStep)/m_dblConZSpeed;
}
if ((double)(time_temp-time_start)<(m_nTime+1))
{
goto End2;//运动未完成,跳出本次执行
}
else
{
ZFinFlag=1;
ZRunFlag=0;
RFinFlag=0;
RRunFlag=0;
m_dblConZStart+=m_dblConZStep;
m_dblZCurPos=m_dblConZStart;
UpdateData(0);
}
}
}
m_nTwoConTimes++;
if (m_nTwoConTimes>=m_nTwoNo-1)
{
KillTimer(2);
m_nTwoConTimes=0;
static char f[]="运动成功完Z轴、R轴协同扫描运动";
runinfo[runinfocnt++]=f;
pv->draw();
}
End2:
tasknum=0;
}
/**************************************************************************/
/*以下中断事件监测代码代码——3号定时器 */
/**************************************************************************/
/*if (nIDEvent==3)
{
GT_Axis(1);
unsigned short status;
GT_GetSts(&status);
if(status&0x20)
{
MessageBox("5","Test",MB_OK);
}
}*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -