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

📄 demo_inp_movedlg.cpp

📁 850运动控制卡的详细开发资料
💻 CPP
📖 第 1 页 / 共 3 页
字号:
				
					if(m_bIsTwoAxisInp)
					{
						if(m_bChkDemo_x)
						{
							(CButton*)GetDlgItem(IDC_CHECK_DEMO_X)->EnableWindow(TRUE);
						}
						if(m_bChkDemo_z)
						{
							(CButton*)GetDlgItem(IDC_CHECK_DEMO_Z)->EnableWindow(TRUE);
						}
					}
					
				
					


			        if(m_bChkDemo_x)(CButton*)GetDlgItem(IDC_EDIT_PULSE_COUNT_X)->EnableWindow(TRUE);
	                if(m_bChkDemo_y)(CButton*)GetDlgItem(IDC_EDIT_PULSE_COUNT_Y)->EnableWindow(TRUE);
	                if(m_bChkDemo_z)(CButton*)GetDlgItem(IDC_EDIT_PULSE_COUNT_Z)->EnableWindow(TRUE);
	                if(m_bChkDemo_w)(CButton*)GetDlgItem(IDC_EDIT_PULSE_COUNT_W)->EnableWindow(TRUE);
	                EnableCheckWnd(m_bDisableEquality_V);
				}
		
		
	
		

	CDialog::OnTimer(nIDEvent);
}





void CDemo_Inp_MoveDlg::ShowInfo()
{//获取逻辑位置和速度
	long pos_x=0,pos_y=0,pos_z=0,pos_w=0;
	long nCurrentSpeed_x=0,nCurrentSpeed_y=0,nCurrentSpeed_z=0,nCurrentSpeed_w=0;
  



		             get_command_pos(cardno,1,&pos_x);
					
		             get_command_pos(cardno,2,&pos_y);
				
		             get_command_pos(cardno,3,&pos_z);
							
		             get_command_pos(cardno,4,&pos_w);
					
		
    if(m_bIsInpLine){
	   if(m_bIsTwoAxisInp){
		    if(m_bChkDemo_x){ 
		
			get_speed(cardno,1,&nCurrentSpeed_x);
		
			
			}
		    if(m_bChkDemo_z){
			
			get_speed(cardno,3,&nCurrentSpeed_z);
			
			}
	   }
      if(m_bIsThreeAxisInp){
			get_speed(cardno,1,&nCurrentSpeed_x);
             nCurrentSpeed_z=0;		
	  }
	   if(m_bIsFourAxisInp){  		   
		get_speed(cardno,1,&nCurrentSpeed_x);
		 nCurrentSpeed_z=0;
	   }
	}
	else{
		if(m_bIsTwoAxisInp){
		        if(m_bChkDemo_x){ 		
			         get_speed(cardno,1,&nCurrentSpeed_x);
				}
		         if(m_bChkDemo_z){
					 get_speed(cardno,3,&nCurrentSpeed_z);		
				 }
		}
		else{}
	}

    SetDlgItemInt(IDC_EDIT_LOGIC_POS_X,pos_x);
	SetDlgItemInt(IDC_EDIT_LOGIC_POS_Y,pos_y);
	SetDlgItemInt(IDC_EDIT_LOGIC_POS_Z,pos_z);
	SetDlgItemInt(IDC_EDIT_LOGIC_POS_W,pos_w);

	SetDlgItemInt(IDC_EDIT_VELOCITY_X,nCurrentSpeed_x*m_nRatio_x);
	SetDlgItemInt(IDC_EDIT_VELOCITY_Y,nCurrentSpeed_y*m_nRatio_y);
	SetDlgItemInt(IDC_EDIT_VELOCITY_Z,nCurrentSpeed_z*m_nRatio_z);
	SetDlgItemInt(IDC_EDIT_VELOCITY_W,nCurrentSpeed_w*m_nRatio_w);



}

void CDemo_Inp_MoveDlg::OnBtnInpContinue() 
{//连续插补
   
	if(!m_bChkDemo_x&&!m_bChkDemo_z&&m_bIsTwoAxisInp)
	{
		MessageBox("请选择插补轴!");
		return;
	}
	
	int s1,s2;
	int no,ch;

	//范围设定更新
	set_range(0,1,8000000/m_nRatio_x);
	set_range(0,2,8000000/m_nRatio_y);
	set_range(0,3,8000000/m_nRatio_z);
	set_range(0,4,8000000/m_nRatio_w);
    //三轴插补和四轴插补时Z轴的倍率设置成与X轴一样
	if(!m_bIsTwoAxisInp)set_range(0,3,8000000/m_nRatio_x);

	SetSpeed();
	m_bIsContinueInp=true;

	if(m_bChkDemo_x)
	{
		no=1;
		ch=1;
	}
	if(m_bIsTwoAxisInp&&m_bChkDemo_z)
	{
		no=2;
		ch=3;
	}
   if(m_bDisableEquality_V)
   {
	   SetAddSpeed();
   }
    inp_dec_disable(cardno,no);
//------------第一段----------------------

  DemoInpMove();
	while(true)
	{   
	    DoEvent();
		get_stopdata(cardno,ch,&s1);
		if(s1!=0)goto err;
        
		get_inp_status2(0,no,&s2);
		if(s2!=0)break;
	}
//------------第二段----------------------
    DemoInpMove();

	while(true)
	{   
		DoEvent();
		get_stopdata(0,ch,&s1);
		if(s1!=0)goto err;
	   
		get_inp_status2(cardno,no,&s2);
		if(s2!=0)break;
	}
//------------第三段----------------------

   DemoInpMove();

	while(true)
	{   
		DoEvent();
		get_stopdata(cardno,ch,&s1);
		if(s1!=0)goto err;

		get_inp_status2(cardno,no,&s2);
		if(s2!=0)break;
	}

//------------第四段----------------------
	    DemoInpMove();

	while(true)
	{   
		DoEvent();
		get_stopdata(cardno,ch,&s1);
		if(s1!=0)goto err;

		get_inp_status2(cardno,no,&s2);
		if(s2!=0)break;
	}

//--------最后一段----------------------
	if(m_bDisableEquality_V)inp_dec_enable(0,no);
  

  DemoInpMove();
	while(true)
	{   
		DoEvent();
		get_stopdata(cardno,ch,&s1);
		if(s1!=0)goto err;
	    
		get_inp_status(cardno,no,&s2);
		if(s2==0)break;
	}

	return;
err:
	MessageBox("error");
    return;
	
	
	

}
	 


void CDemo_Inp_MoveDlg::DemoInpMove()
{  
	
		if(m_bIsInpLine){	//直线插补
			if(m_bIsTwoAxisInp){
				if(m_bChkDemo_x)	inp_move2(cardno,1,m_nPulseCount_x,m_nPulseCount_y);
				if(m_bChkDemo_z)	inp_move2(cardno,2,m_nPulseCount_z,m_nPulseCount_w);
			}
		     if(m_bIsThreeAxisInp)	{

				if(m_bChkDemo_x) inp_move3(cardno,m_nPulseCount_x,m_nPulseCount_y,m_nPulseCount_z);
			}
			 if(m_bIsFourAxisInp){
                  if(m_bChkDemo_x)   inp_move4(cardno,m_nPulseCount_x,m_nPulseCount_y,m_nPulseCount_z,m_nPulseCount_w);

			 }
		}
		else{	//圆弧插补

			if(m_bIsTwoAxisInp){
				if(m_bChkDemo_x)	inp_cw_arc(cardno,1,m_nPulseCount_x,m_nPulseCount_y,0,10000);	//圆心(0,10000) 半径R=10000
				if(m_bChkDemo_z)	inp_ccw_arc(cardno,2,m_nPulseCount_z,m_nPulseCount_w,10000,0);//圆心(10000,0) 半径R=10000
			}
			else{		//目前演示程序,不支持圆弧的三轴插补
			}

		}
}

void CDemo_Inp_MoveDlg::ClearAllAxisPos()
{  //各轴位置清零
  set_command_pos(cardno,1,0);
  set_command_pos(cardno,2,0);
  set_command_pos(cardno,3,0);
  set_command_pos(cardno,4,0);
}

void CDemo_Inp_MoveDlg::OnBtnInpStop() 
{
	// TODO: Add your control notification handler code here
	//插补停止
		UpdateData();



	sudden_stop(cardno,1);
	sudden_stop(cardno,2);
	sudden_stop(cardno,3);
	sudden_stop(cardno,4);

	m_bIsContinueInp=FALSE;	
	KillTimer(2);
}



void CDemo_Inp_MoveDlg::SetAddSpeed()
{   UpdateData();
	long nValue;

	if(m_bDisableEquality_V){//加/减速运动
				BOOL bMode_Acc;
				bMode_Acc=m_bEnable_S_Move ? 1:0;
//---------------设为梯形/S形加减速.0为梯形,1为S形----------------------
                
				set_ad_mode(cardno,1,bMode_Acc);
			
				set_ad_mode(cardno,3,bMode_Acc);
			

//---------------对每轴设置,对称加减速/非对称加减速,0为对称,1为非对称----------------
				
				bMode_Acc=m_bEnableSymmetry_Acc_x ? 1:0;
				set_dec1_mode(cardno,1,bMode_Acc);

				bMode_Acc=m_bEnableSymmetry_Acc_z ? 1:0;
				set_dec1_mode(cardno,3,bMode_Acc);
				
				
		

//-----------------------采用手动减速方式-------------------------------------------------
				if(m_bIsInpLine){		
					if(	m_bIsContinueInp){    //连续插补加减速时采用手动减速,设定减速点
					long nDecpos;	
						set_dec2_mode(cardno,1,1);
					
	                //   nDecpos=m_nPulseCount_x-long((m_nDriveSpeed_x+m_nStartV_x)*m_fAccTime_x/2);
					nDecpos=1500-long((m_nDriveSpeed_x+m_nStartV_x)*m_fAccTime_x/2);
			           set_dec_pos(cardno,1,nDecpos);
					   if(m_bChkDemo_z&&m_bIsTwoAxisInp){
				      set_dec2_mode(cardno,3,1);
				    //  nDecpos=m_nPulseCount_z-long((m_nDriveSpeed_z+m_nStartV_z)*m_fAccTime_z/2);
					  nDecpos=1500-long((m_nDriveSpeed_z+m_nStartV_z)*m_fAccTime_z/2);
					  set_dec_pos(cardno,3,nDecpos);
					   }	
					}
					else{
						set_dec2_mode(cardno,1,0);
						if(m_bChkDemo_z&&m_bIsTwoAxisInp)set_dec2_mode(cardno,3,0);
					}
     
							
				}
				else{	
						//圆弧加减速插补时,手动设定减速点,不能采用自动减速

						long nPulse_Count=long((10000/1.414)*8);
						long nDecPos;

						set_dec2_mode(cardno,1,1);

						nDecPos=nPulse_Count-long((m_nDriveSpeed_x+m_nStartV_x)*m_fAccTime_x/2);
						set_dec_pos(cardno,1,nDecPos);
                        if(m_bChkDemo_z&&m_bIsTwoAxisInp){
						set_dec_pos(cardno,3,nDecPos);
						nDecPos=nPulse_Count-long((m_nDriveSpeed_z+m_nStartV_z)*m_fAccTime_z/2);
						set_dec_pos(cardno,3,nDecPos);
						}

					
					}

//-----------------------设置每轴的加速度-----------------------------------------------
//------------加速度的实际值为nValue=m_nVelocityAcc_x*125*m_nRatio_x--------------------
				set_acc(cardno,1,m_nVelocityAcc_x);

//------------加速度的实际值为nValue=m_nVelocityAcc_z*125*m_nRatio_z--------------------
				set_acc(cardno,3,m_nVelocityAcc_z);

//-----------------------设置每轴的减速度-----------------------------------------------
//------------减速度的实际值为nValue=m_nVelocityDec_x*125*m_nRatio_x--------------------
				set_dec(cardno,1,m_nVelocityDec_x);
				

//------------减速度的实际值为nValue=m_nVelocityDec_z*125*m_nRatio_z--------------------
				set_dec(cardno,3,m_nVelocityDec_z);

//-----------------------如果是S形加速运动,设置加速度增加率.-----------------------------
//-----------------------这里只演示完全S曲线加减速运动----------------------------------
				if(m_bEnable_S_Move && m_bIsInpLine){	//圆弧插补只能采用直线加减速,不能使用S曲线加减速
			
					int nAccValue;
					if(m_bChkDemo_x)
					{
					if(m_fAccTime_x==0)return;
					nValue=long(m_nVelocityAcc_x/m_fAccTime_x);
					nAccValue=62500000 * m_nRatio_x/nValue;
					set_acac(cardno,1,nAccValue);
					}

					if(m_bChkDemo_z&&m_bIsTwoAxisInp)
					{
					if(m_fAccTime_z==0)return;
					nValue=long(m_nVelocityAcc_z/m_fAccTime_z);
					nAccValue=62500000 * m_nRatio_z/nValue;
					set_acac(cardno,3,nAccValue);
					}
				}


			}


}

void CDemo_Inp_MoveDlg::CalAccTime()
{
        m_fAccTime_w=float(m_nDriveSpeed_w-m_nStartV_w)/float(m_nVelocityAcc_w);

		m_fAccTime_x=float(m_nDriveSpeed_x-m_nStartV_x)/float(m_nVelocityAcc_x);

		m_fAccTime_y=float(m_nDriveSpeed_y-m_nStartV_y)/float(m_nVelocityAcc_y);

		m_fAccTime_z=float(m_nDriveSpeed_z-m_nStartV_z)/float(m_nVelocityAcc_z);
}

void CDemo_Inp_MoveDlg::OnButtonClear() 
{
	// TODO: Add your control notification handler code here
	
		set_command_pos(cardno,1,0);
		set_command_pos(cardno,2,0);
		set_command_pos(cardno,3,0);
		set_command_pos(cardno,4,0);
	
	
}

void CDemo_Inp_MoveDlg::CheckNum(long &num, long min, long max)
{
  //数值范围
	if(num<min)num=min;
     if(num>max)num=max;
}

void CDemo_Inp_MoveDlg::SetSpeed()
{
UpdateData();
	if( !m_bDisableEquality_V)
		{  //匀速插补 
	 if(m_bIsTwoAxisInp){
		 if(m_bChkDemo_x){
			 set_startv(cardno,1,m_nDriveSpeed_x/m_nRatio_x);
	         set_speed(cardno,1,m_nDriveSpeed_x/m_nRatio_x);
         }
		 if(m_bChkDemo_z){
		
			 set_startv(cardno,3,m_nDriveSpeed_z/m_nRatio_z);
	         set_speed(cardno,3,m_nDriveSpeed_z/m_nRatio_z);
			 
		
		 }
     }
	
	 else{
		if(m_bChkDemo_x){
			 set_startv(cardno,1,m_nDriveSpeed_x/m_nRatio_x);
	         set_speed(cardno,1,m_nDriveSpeed_x/m_nRatio_x);
             

			 set_startv(cardno,3,m_nDriveSpeed_x/m_nRatio_x);
	         set_speed(cardno,3,m_nDriveSpeed_x/m_nRatio_x);
		}
	}



	}

	else		{
		if(m_bIsTwoAxisInp){
		 if(m_bChkDemo_x){
	    	set_startv(cardno,1,m_nStartV_x/m_nRatio_x);
		    set_speed(cardno,1,m_nDriveSpeed_x/m_nRatio_x);
		 }
		  if(m_bChkDemo_z){
	    	set_startv(cardno,3,m_nStartV_z/m_nRatio_z);
		    set_speed(cardno,3,m_nDriveSpeed_z/m_nRatio_z);
		  }
		}
		else{
           set_startv(cardno,1,m_nStartV_x/m_nRatio_x);
	       set_startv(cardno,3,m_nStartV_z/m_nRatio_z);

	       set_speed(cardno,1,m_nDriveSpeed_x/m_nRatio_x); 
		   set_speed(cardno,3,m_nDriveSpeed_z/m_nRatio_z);
	
		}
    }
}

⌨️ 快捷键说明

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