⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 linedlg.cpp

📁 三轴车床的控制系统
💻 CPP
字号:
// LineDlg.cpp : implementation file
//

#include "stdafx.h"
#include "CSU.h"
#include "LineDlg.h"

#include "DotDlg.h"
#include "GT400SV.h"
#include "CSUDlg.h"

#include <math.h>

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CLineDlg dialog


CLineDlg::CLineDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CLineDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CLineDlg)
	m_step = 0.0;
	m_synacc = 0.0;
	m_synvel = 0.0;
	m_xendpos = 0.0;
	m_yendpos = 0.0;
	m_zscope = 0.0;
	m_zspeed = 0.0;
	m_linen = 0;
	m_ymove = 0.0;
	m_motoroff = 0;
	m_motoron = 0;
	m_ymspeed = 0.0;
	m_wettime = 0;
	//}}AFX_DATA_INIT
}


void CLineDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CLineDlg)
	DDX_Text(pDX, IDC_EDIT_step, m_step);
	DDX_Text(pDX, IDC_EDIT_SynAcc, m_synacc);
	DDX_Text(pDX, IDC_EDIT_SynVel, m_synvel);
	DDX_Text(pDX, IDC_EDIT_xendpos, m_xendpos);
	DDX_Text(pDX, IDC_EDIT_yendpos, m_yendpos);
	DDX_Text(pDX, IDC_EDIT_Zscope, m_zscope);
	DDX_Text(pDX, IDC_EDIT_Zspeed, m_zspeed);
	DDX_Text(pDX, IDC_EDIT_LineN, m_linen);
	DDX_Text(pDX, IDC_EDIT_Ymove, m_ymove);
	DDX_Text(pDX, IDC_EDIT_motoroff, m_motoroff);
	DDX_Text(pDX, IDC_EDIT_motoron, m_motoron);
	DDX_Text(pDX, IDC_EDIT_ymspeed, m_ymspeed);
	DDX_Text(pDX, IDC_EDIT_wettime, m_wettime);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CLineDlg, CDialog)
	//{{AFX_MSG_MAP(CLineDlg)
	ON_BN_CLICKED(IDC_Linerun_BUTTON, OnLinerunBUTTON)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CLineDlg message handlers

void CLineDlg::OnLinerunBUTTON() 
{
	   	UpdateData(TRUE);
	    unsigned short sts;
		double cnt1[5]={2000,0,0,0,0};
        double cnt2[5]={0,2000,0,0,0};
		GT_MapAxis(1,cnt1); 
        GT_MapAxis(2,cnt2);
		GT_SetSynAcc(0.00000004*m_synacc); 
        GT_SetSynVel(0.0002*m_synvel);

		GT_Axis(3);
		long actl_pos;
		GT_GetAtlPos(&actl_pos);
        GT_ZeroPos();                               //把当前位置置为零位

		ZTmotion(m_zscope, m_zspeed);               //Z轴先向上移动一段距离

		int n=(int)(sqrt(m_xendpos*m_xendpos+m_yendpos*m_yendpos)/m_step);
        double xendpos=m_step*(m_xendpos/sqrt(m_xendpos*m_xendpos+m_yendpos*m_yendpos));           //x方向上的进给量
		double yendpos=m_step*(m_yendpos/sqrt(m_xendpos*m_xendpos+m_yendpos*m_yendpos));           //y方向上的进给量
		
		Nflag=1;
	for(int j=0;j<m_linen;j++)
	{
        double ymove=m_ymove*j;
		for(int i=0;i<=n;i++)
		{
		if(Nflag==-1)    //反向走
        GT_LnXY((n-i)*xendpos,ymove);
		else
		GT_LnXY(i*xendpos,ymove);  		
	    GT_GetCrdSts(&sts);

//		GT_ExOpt(0x1);                 //滴胶
//		Sleep(m_motoron);             //电机转动时间
//		GT_ExOpt(0x2);
//		Sleep(m_motoroff);


		while((sts&0x01)!=0x01)
		{	
	  	GT_GetCrdSts(&sts);       
        }                           //XY平面定位

		GT_Axis(3);
		GT_ClrSts();
		ZTmotion(0, m_zspeed);     //Z轴移动到滴胶位置
		Sleep(m_wettime);         //润湿时间
		GT_ExOpt(0x1);                 //滴胶
		Sleep(m_motoron);             //电机转动时间
		GT_ExOpt(0x2);
		Sleep(m_motoroff);
        ZTmotion(m_zscope, m_zspeed);  //滴完胶后Z轴上移                    
		
		}


        Nflag=-Nflag;

	}
        ZTmotion(0, m_zspeed);  //Z轴回原位
        MessageBox("运动完成","",MB_OK);    
	
}

void CLineDlg::ZTmotion(double Pos, double speed)
{
   long d1=(long)(Pos*Pmm);//位置
   double d2=speed*Vmms;//速度
    if(d2>=16384||d2<=0)
	{
		MessageBox("速度超出范围","error",MB_OK);
	}
	if(d1>=1073741823||d2<=-1073741824)
	{
		MessageBox("增量值超出范围","error",MB_OK);
	}


  GT_PrflT();
  GT_SetAcc(0.4);
  GT_SetVel(d2);
  GT_SetPos(d1);
  GT_Update();
  unsigned short sts;
  GT_GetSts(&sts);
   
 DWORD oldtime = GetTickCount();

  while((sts&0x01)!=0x01)
	 {
/*	  	Sleep( 5 );
        DWORD nowtime = GetTickCount();
		DWORD s = nowtime - oldtime;
	    if(Pos==0&&s>=(DWORD)m_motoron )
		GT_ExOpt(0x1);
		if(Pos==0&&s>=(DWORD)m_motoroff)
		GT_ExOpt(0x2); */
	    GT_GetSts(&sts);
	 }
   GT_ClrSts();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -