// Motion_test.cpp : implementation file
//

#include "stdafx.h"
#include "Demo.h"
#include "Motion_test.h"
#include "ValExt.h"
#include "WinConSDK.h"

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


int Star_A;
bool Auto_Get;
WORD m_nTimer;
int My_Count;

/////////////////////////////////////////////////////////////////////////////
// Motion_test dialog


Motion_test::Motion_test(CWnd* pParent /*=NULL*/)
	: CDialog(Motion_test::IDD, pParent)
{
	//{{AFX_DATA_INIT(Motion_test)
	m_XAcc = 0;
	m_XE = 0;
	m_XP = 0;
	m_XSpeed = 0;
	m_YAcc = 0;
	m_YE = 0;
	m_YP = 0;
	m_YSpeed = 0;
	m_Msg = _T("");
	//}}AFX_DATA_INIT
}


void Motion_test::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(Motion_test)
	DDX_Control(pDX, IDC_Auto, m_CAuto);
	DDX_Text(pDX, IDC_XAcc, m_XAcc);
	DDX_Text(pDX, IDC_XE, m_XE);
	DDX_Text(pDX, IDC_XP, m_XP);
	DDX_Text(pDX, IDC_XSpeed, m_XSpeed);
	DDX_Text(pDX, IDC_YAcc, m_YAcc);
	DDX_Text(pDX, IDC_YE, m_YE);
	DDX_Text(pDX, IDC_YP, m_YP);
	DDX_Text(pDX, IDC_YSpeed, m_YSpeed);
	DDX_Text(pDX, IDC_Msg, m_Msg);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(Motion_test, CDialog)
	//{{AFX_MSG_MAP(Motion_test)
	ON_WM_TIMER()
	ON_BN_CLICKED(IDC_Auto, OnAuto)
	ON_BN_CLICKED(IDC_Manual_Get, OnManualGet)
	ON_BN_CLICKED(IDC_Servo_On_All, OnServoOnAll)
	ON_BN_CLICKED(IDC_Servo_Off_All, OnServoOffAll)
	ON_BN_CLICKED(IDC_HOME_SETX, OnHomeSetx)
	ON_BN_CLICKED(IDC_HOME_SETY, OnHomeSety)
	ON_BN_CLICKED(IDC_Axis1_1, OnAxis11)
	ON_BN_CLICKED(IDC_Axis1_2, OnAxis12)
	ON_BN_CLICKED(IDC_Axis1_0, OnAxis1_0)
	ON_BN_CLICKED(IDC_Axis1_4, OnAxis1_4)
	ON_BN_CLICKED(IDC_Stop_A, OnStopA)
	ON_BN_CLICKED(IDC_STOP, OnStop)
	ON_BN_CLICKED(IDC_Clear_Error, OnClearError)
	ON_BN_CLICKED(IDC_Axis2_0, OnAxis2_0)
	ON_BN_CLICKED(IDC_Axis2_1, OnAxis2_1)
	ON_BN_CLICKED(IDC_Axis2_2, OnAxis2_2)
	ON_BN_CLICKED(IDC_Axis2_3, OnAxis2_3)
	ON_BN_CLICKED(IDC_Axis2_5, OnAxis2_5)
	ON_BN_CLICKED(IDC_Axis2_6, OnAxis2_6)
	ON_BN_CLICKED(IDC_RECTAN, OnRectan)
	ON_BN_CLICKED(IDC_GEAR, OnGear)
	ON_BN_CLICKED(IDC_C_Move, OnCMove)
	ON_BN_CLICKED(IDC_Get_Error, OnGetError)
	ON_BN_CLICKED(IDC_HOME_SETXH, OnHomeSetxh)
	ON_BN_CLICKED(IDC_HOME_SETYH, OnHomeSetyh)
	ON_BN_CLICKED(IDC_HOME_SETXZ, OnHomeSetxz)
	ON_BN_CLICKED(IDC_HOME_SETYZ, OnHomeSetyz)
	ON_BN_CLICKED(IDC_HOME_AutoX, OnHOMEAutoX)
	ON_BN_CLICKED(IDC_HOME_AutoY, OnHOMEAutoY)
	ON_BN_CLICKED(IDC_C_Move2, OnCMove2)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()


BOOL Motion_test::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	Auto_Get=false;
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void Motion_test::Show_Msg(int AA)
{
	m_Msg.Format(_T("%d"),AA);
	UpdateData(FALSE);
}

void Motion_test::Show_Msg(CString AA)
{
	m_Msg=AA;
	UpdateData(FALSE);
}

/////////////////////////////////////////////////////////////////////////////
// Motion_test message handlers

void Motion_test::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	//int i;
	if (nIDEvent==1)
	{
	m_XP=i8092MF_GET_LP(cardNo, AXIS_X);
	m_XE=i8092MF_GET_EP(cardNo, AXIS_X);
	m_XSpeed=i8092MF_GET_CV(cardNo, AXIS_X);
    //m_XSpeed=i8092MF_GET_ERROR_CODE(cardNo, AXIS_X);
	m_XAcc=i8092MF_GET_CA(cardNo, AXIS_X);
	//m_XAcc=i8092MF_GET_RR4(cardNo);
	


    //m_XE=i8092MF_GET_ERROR_CODE(cardNo, AXIS_X);
	//m_XP=My_Count;

	//m_YP=i8092MF_GET_LP(cardNo, AXIS_Y);
	//m_YE=i8092MF_GET_ERROR_CODE(cardNo, AXIS_Y);
	//m_YP=My_Count;
	//My_Count++;


 	m_YP=i8092MF_GET_LP(cardNo, AXIS_Y);
	m_YE=i8092MF_GET_EP(cardNo, AXIS_Y);
	m_YSpeed=i8092MF_GET_CV(cardNo, AXIS_Y);
	//m_YSpeed=i8092MF_GET_ERROR_CODE(cardNo, AXIS_Y);
	m_YAcc=i8092MF_GET_CA(cardNo, AXIS_Y);
	//m_YAcc=i8092MF_GET_RR5(cardNo);
	
	//m_YE=i8092MF_GET_ERROR_CODE(cardNo, AXIS_Y);
	//m_YP=My_Count;
	//My_Count++;
	//OnManualGet();
	//Show_Msg(i8092MF_GET_RR2(cardNo,AXIS_X));
	UpdateData(false);
    }
	CDialog::OnTimer(nIDEvent);
}

void Motion_test::OnAuto() 
{
	// TODO: Add your control notification handler code here
	Auto_Get= ! Auto_Get;
	if (Auto_Get)
    {
		My_Count=0;
		SetTimer(1, 50, 0);
		m_CAuto.SetWindowText(_T("Auto Update Off"));
	}
	else
	{
		KillTimer(1);  
		//KillTimer(2);
		m_CAuto.SetWindowText(_T("Auto Update On"));
	}
}

void Motion_test::OnManualGet() 
{
	// TODO: Add your control notification handler code here
	m_XP=i8092MF_GET_LP(cardNo, AXIS_X);
	m_XSpeed=i8092MF_GET_CV(cardNo, AXIS_X);
	m_XAcc=i8092MF_GET_CA(cardNo, AXIS_X);
	m_XE=i8092MF_GET_EP(cardNo, AXIS_X);

	m_YP=i8092MF_GET_LP(cardNo, AXIS_Y);
	m_YSpeed=i8092MF_GET_CV(cardNo, AXIS_Y);
	m_YAcc=i8092MF_GET_CA(cardNo, AXIS_Y);
	m_YE=i8092MF_GET_EP(cardNo, AXIS_Y);
	UpdateData(false);
}

void Motion_test::OnServoOnAll() 
{
	// TODO: Add your control notification handler code here
	i8092MF_SERVO_ON(cardNo, 0x3);
}

void Motion_test::OnServoOffAll() 
{
	// TODO: Add your control notification handler code here
	i8092MF_SERVO_OFF(cardNo, 0x3);
}

void Motion_test::OnHOMEAutoX() 
{
	// TODO: Add your control notification handler code here
	BYTE m_Axis=AXIS_X;
	i8092MF_SET_MAX_V(cardNo, m_Axis, 32000); 
	i8092MF_SET_A(cardNo, m_Axis,50000);   //set Acc =50000 PPS/S
	i8092MF_SET_SV(cardNo, m_Axis, 1000);
	BYTE RR=i8092MF_AUTO_HOME(cardNo, m_Axis, 2, 2, 0, 1, 50000,20000,2000,6000);
	Sleep(100);
	if (RR==0)
	{
		i8092MF_SET_LP(cardNo,m_Axis,0);
		i8092MF_SET_EP(cardNo,m_Axis,0);
	}	
	else
	{
		CString MSGG;
        MSGG= "Please Check AUTO_HOME ERROR:=" + CString(RR);
		Show_Msg(MSGG);
	}
}

void Motion_test::OnHOMEAutoY() 
{
	// TODO: Add your control notification handler code here
	BYTE m_Axis=AXIS_Y;
	i8092MF_SET_MAX_V(cardNo, m_Axis, 32000); 
	i8092MF_SET_A(cardNo, m_Axis,50000);   //set Acc =50000 PPS/S
	i8092MF_SET_SV(cardNo, m_Axis, 1000);
	BYTE RR=i8092MF_AUTO_HOME(cardNo, m_Axis, 2, 0, 1, 1, 50000,20000,2000,6000);
	Sleep(100);
	if (RR==0)
	{
		i8092MF_SET_LP(cardNo,m_Axis,0);
		i8092MF_SET_EP(cardNo,m_Axis,0);
	}
	else
	{
		CString MSGG;
        MSGG= "Please Check AUTO_HOME ERROR:=" + CString(RR);
		Show_Msg(MSGG);
	}
}


void Motion_test::OnHomeSetx() 
{
	// TODO: Add your control notification handler code here
	BYTE m_Axis=AXIS_X;
	i8092MF_SET_MAX_V(cardNo, m_Axis, 16000); 
	i8092MF_SET_A(cardNo, m_Axis,50000);   //set Acc =50000 PPS/S
	i8092MF_SET_SV(cardNo, m_Axis, 1000);
	BYTE RR=i8092MF_SEARCH_NHOME(cardNo, m_Axis, 1, 2000,5000);
	Sleep(100);
	if (RR==0)
	{
		i8092MF_SET_LP(cardNo,m_Axis,0);
		i8092MF_SET_EP(cardNo,m_Axis,0);
	}
	else
	{
		CString MSGG;
        MSGG= "Please Check SEARCH_NHOME ERROR:=" + CString(RR);
		Show_Msg(MSGG);
	}
}

void Motion_test::OnHomeSety() 
{
	// TODO: Add your control notification handler code here
	BYTE m_Axis=AXIS_Y;
	i8092MF_SET_MAX_V(cardNo, m_Axis, 16000); 
	i8092MF_SET_A(cardNo, m_Axis,50000);   //set Acc =50000 PPS/S
	i8092MF_SET_SV(cardNo, m_Axis, 1000);
	BYTE RR=i8092MF_SEARCH_NHOME(cardNo, m_Axis, 1, 2000,5000);
	Sleep(100);
	if (RR==0)
	{
		i8092MF_SET_LP(cardNo,m_Axis,0);
		i8092MF_SET_EP(cardNo,m_Axis,0);
	}
	else
	{
		CString MSGG;
        MSGG= "Please Check SEARCH_NHOME ERROR:=" + CString(RR);
		Show_Msg(MSGG);
	}
}
void Motion_test::OnHomeSetxh() 
{
	// TODO: Add your control notification handler code here
	BYTE m_Axis=AXIS_X;
	i8092MF_SET_MAX_V(cardNo, m_Axis, 16000); 
	i8092MF_SET_A(cardNo, m_Axis,50000);   //set Acc =50000 PPS/S
	i8092MF_SET_SV(cardNo, m_Axis, 1000);
	BYTE RR=i8092MF_SEARCH_HOME(cardNo, m_Axis, 1, 2000,5000);
	Sleep(100);
	if (RR==0)
	{
		i8092MF_SET_LP(cardNo,m_Axis,0);
		i8092MF_SET_EP(cardNo,m_Axis,0);
	}
	else
	{
		CString MSGG;
        MSGG= "Please Check SEARCH_HOME ERROR:=" + CString(RR);
		Show_Msg(MSGG);
	}
}

void Motion_test::OnHomeSetyh() 
{
	// TODO: Add your control notification handler code here
	BYTE m_Axis=AXIS_Y;
	i8092MF_SET_MAX_V(cardNo, m_Axis, 16000); 
	i8092MF_SET_A(cardNo, m_Axis,50000);   //set Acc =50000 PPS/S
	i8092MF_SET_SV(cardNo, m_Axis, 1000);
	BYTE RR=i8092MF_SEARCH_HOME(cardNo, m_Axis, 1, 2000,5000);
	Sleep(100);
	if (RR==0)
	{
		i8092MF_SET_LP(cardNo,m_Axis,0);
		i8092MF_SET_EP(cardNo,m_Axis,0);
	}
	else
	{
		CString MSGG;
        MSGG= "Please Check SEARCH_HOME ERROR:=" + CString(RR);
		Show_Msg(MSGG);
	}
}

void Motion_test::OnHomeSetxz() 
{
	// TODO: Add your control notification handler code here
	BYTE m_Axis=AXIS_X;
	i8092MF_SET_MAX_V(cardNo, m_Axis, 16000); 
	i8092MF_SET_A(cardNo, m_Axis,50000);   //set Acc =50000 PPS/S
	i8092MF_SET_SV(cardNo, m_Axis, 1000);
	BYTE RR=i8092MF_SEARCH_ZPHASE(cardNo, m_Axis, 1, 1000);
	Sleep(100);
	if (RR==0)
	{
		i8092MF_SET_LP(cardNo,m_Axis,0);
		i8092MF_SET_EP(cardNo,m_Axis,0);
	}
	else
	{
		CString MSGG;
        MSGG= "Please Check SEARCH_ZPHASE ERROR:=" + CString(RR);
		Show_Msg(MSGG);
	}
}

void Motion_test::OnHomeSetyz() 
{
	// TODO: Add your control notification handler code here
	BYTE m_Axis=AXIS_Y;
	i8092MF_SET_MAX_V(cardNo, m_Axis, 16000); 
	i8092MF_SET_A(cardNo, m_Axis,50000);   //set Acc =50000 PPS/S
	i8092MF_SET_SV(cardNo, m_Axis, 1000);
	BYTE RR=i8092MF_SEARCH_ZPHASE(cardNo, m_Axis, 1, 1000);
	Sleep(100);
	if (RR==0)
	{
		i8092MF_SET_LP(cardNo,m_Axis,0);
		i8092MF_SET_EP(cardNo,m_Axis,0);
	}
	else
	{
		CString MSGG;
        MSGG= "Please Check SEARCH_ZPHASE ERROR:=" + CString(RR);
		Show_Msg(MSGG);
	}
}


void Motion_test::OnAxis1_0() 
{
	// TODO: Add your control notification handler code here
	BYTE axis=AXIS_XY;  //for AXIS_X it can be to AXIS_XYZU
	i8092MF_SET_MAX_V(cardNo, axis, 20000); 
	i8092MF_NORMAL_SPEED(cardNo, axis, 0);		//set axis as Symmetrical T curve mode
	i8092MF_SET_V(cardNo, axis, 20000);			//set v=20000 PPS
	i8092MF_SET_A(cardNo, axis, 100000);		//set acc=100000 PPS/S
	i8092MF_SET_SV(cardNo, axis, 10);			//set start speed=1000 PPS
	i8092MF_SET_AO(cardNo, axis, 0);			//set offset pulse (at SV speed)= 0 PS
    i8092MF_FIXED_MOVE(cardNo, axis, 10000);	//run the fixed 10000 Pulse move.
	while (i8092MF_STOP_WAIT(cardNo, axis) == NO)
	{
		DoEvents();
		Sleep(1);
		//wait for axis to stop
	}
	Sleep(10);
	i8092MF_FIXED_MOVE(cardNo, axis, -10000);	//run the fixed -10000 Pulse move.	
	while (i8092MF_STOP_WAIT(cardNo, axis) == NO)
	{
		DoEvents();
		Sleep(1);
		//wait for axis to stop
	}

}


void Motion_test::OnAxis11() 
{
	// TODO: Add your control notification handler code here
	BYTE axis=AXIS_XY;  //for AXIS_X it can be to AXIS_XYZU
	i8092MF_SET_MAX_V(cardNo, axis, 20000); 
	i8092MF_NORMAL_SPEED(cardNo, axis, 0);		//set axis as Symmetrical T curve mode
	i8092MF_SET_V(cardNo, axis, 20000);			//set v=20000 PPS
	i8092MF_SET_A(cardNo, axis, 100000);		//set acc=100000 PPS/S
	i8092MF_SET_SV(cardNo, axis, 10);			//set start speed=1000 PPS
	i8092MF_SET_AO(cardNo, axis, 0);			//set offset pulse (at SV speed)= 0 PS
    i8092MF_FIXED_MOVE(cardNo, axis, -10000);	//run the fixed 10000 Pulse move.
	/*/
    BYTE axis=AXIS_XY; //for AXIS_X it can be to AXIS_XYZU
	i8092MF_SET_MAX_V(cardNo, axis, 20000); 
    i8092MF_NORMAL_SPEED(cardNo, axis, 1);		//set axis as Symmetrical S curve mode
	i8092MF_SET_V(cardNo, axis, 20000);			//set v=20000 PPS 
	i8092MF_SET_K(cardNo, axis, 50000);			//set K=500000 PPS/s^2
	i8092MF_SET_SV(cardNo, axis, 200);			//set start speed SV=200 PPS
	i8092MF_SET_AO(cardNo, axis, 9);			//set offset pulse(at SV speed)= 9 PS
    i8092MF_FIXED_MOVE(cardNo, axis, -10000);	//run the fixed -10000 Pulse move.
	/*/
}

void Motion_test::OnAxis12() 
{
	// TODO: Add your control notification handler code here
	BYTE axis=AXIS_XY; //for AXIS_X it can be to AXIS_XYZU
	i8092MF_SET_MAX_V(cardNo, axis, 20000); 
	i8092MF_NORMAL_SPEED(cardNo, axis, 2);		//set axis as Non-Symmetrical T curve mode
	i8092MF_SET_V(cardNo, axis, 20000);			//set v=20000 PPS
	i8092MF_SET_A(cardNo, axis, 100000);		//set acc A=100000 PPS/s
	i8092MF_SET_D(cardNo, axis, 100000);			//set dec D=100000 PPS/s
	i8092MF_SET_SV(cardNo, axis, 200);			//set start speed SV=200 PPS
	i8092MF_SET_AO(cardNo, axis, 9);			//set offset pulse(at SV speed)= 9 PS
    i8092MF_FIXED_MOVE(cardNo, axis, 10000);	//run the fixed 10000 Pulse move.
}



void Motion_test::OnAxis1_4() 
{
	// TODO: Add your control notification handler code here
	i8092MF_CONTINUE_MOVE(cardNo, AXIS_XY, 10000);
	//let AXIS X CONTINUE MOVE at 10000 pps speed
}

void Motion_test::OnStopA() 
{
	// TODO: Add your control notification handler code here
	i8092MF_STOP_SLOWLY(cardNo,AXIS_XY);
	//the ERROR will active please call the i8092MF_CLEAR_ERROR function to clear
}

void Motion_test::OnStop() 
{
	// TODO: Add your control notification handler code here
	i8092MF_STOP_SUDDENLY(cardNo,AXIS_XY);
	//the ERROR will active please call the i8092MF_CLEAR_ERROR function to clear

}

void Motion_test::OnClearError() 
{
	// TODO: Add your control notification handler code here
	i8092MF_CLEAR_ERROR(cardNo);
}

void Motion_test::OnAxis2_0() 
{
	// TODO: Add your control notification handler code here
	BYTE axis=AXIS_XY;  //for AXIS_XY it can be to AXIS_XYZU
	i8092MF_SET_MAX_V(cardNo, axis, 20000); 
	i8092MF_VECTOR_SPEED(cardNo, 0);					
	i8092MF_SET_VV(cardNo, 20000);			//set the vector speed as 20000 PPS.
	i8092MF_LINE_2D(cardNo, 10000, 10000);	//run the 2 axis interpolation.
}

void Motion_test::OnAxis2_1() 
{
	// TODO: Add your control notification handler code here
	BYTE axis=AXIS_XY;  //for AXIS_XY it can be to AXIS_XYZU
	i8092MF_SET_MAX_V(cardNo, axis, 32000); 
	i8092MF_VECTOR_SPEED(cardNo, 1);      
	//set 2 axis as Symmetrical T curve mode (VSVˇBVVˇBVAˇBVAO)
	i8092MF_SET_VSV(cardNo, 500);			//set the vector start speed as 500 PPS.
	i8092MF_SET_VV(cardNo, 20000);			//set the vector speed as 20000 PPS.
	i8092MF_SET_VA(cardNo, 100000);			//set the vector acc. 10000 PPS/s.
	i8092MF_SET_VAO(cardNo, 20);			//set the vector offset pulse(at VSV speed)= 20 PS
	i8092MF_LINE_2D(cardNo, -10000, -10000);	//the 2 axis interpolation.
}

void Motion_test::OnAxis2_2() 
{
	// TODO: Add your control notification handler code here
	BYTE axis=AXIS_XY;  //for AXIS_XY it can be to AXIS_XYZU
	i8092MF_SET_MAX_V(cardNo, axis, 32000); 
	//i8092MF_AXIS_ASSIGN(cardNo, AXIS_X, AXIS_Y, 0); 
	//set the axis1 as X axis2 as Y for interpolation axis.
	i8092MF_VECTOR_SPEED(cardNo, 2);      
	//set 2 axis as Symmetrical S curve mode (VSVˇBVVˇBVAˇBVKˇBVAO)
	i8092MF_SET_VSV(cardNo, 2000);			//set the vector start speed as 2000 PPS.
	i8092MF_SET_VV(cardNo, 20000);			//set the vector speed as 20000 PPS.
	i8092MF_SET_VK(cardNo, 500000);			//set K=50000 PPS/s^2 
	i8092MF_SET_VAO(cardNo, 20);			//set the vector offset pulse(at VSV speed)= 20 PS
	i8092MF_LINE_2D(cardNo, 10000, 10000);	//the 2 axis interpolation.
}

void Motion_test::OnAxis2_3() 
{
	// TODO: Add your control notification handler code here
	BYTE axis=AXIS_XY;  //for AXIS_XY it can be to AXIS_XYZU
	i8092MF_SET_MAX_V(cardNo, axis, 32000); 
	//i8092MF_AXIS_ASSIGN(cardNo, AXIS_X, AXIS_Y, 0); 
	//set the axis1 as X axis2 as Y for interpolation axis.
	i8092MF_VECTOR_SPEED(cardNo, 3);      
	//set 2 axis as Non-Symmetrical T curve mode (VSVˇBVVˇBVAˇBVDˇBVAO)
	i8092MF_SET_VSV(cardNo, 100);			//set the vector start speed as 100 PPS.
	i8092MF_SET_VV(cardNo, 20000);			//set the vector speed as 20000 PPS.
	i8092MF_SET_VA(cardNo, 100000);			//set the vector acc as 100000 PPS/s.
	i8092MF_SET_VD(cardNo, 10000);			//set the vector dec as 50000 PPS/s.
	i8092MF_SET_VAO(cardNo, 20);			//set the vector offset pulse(at VSV speed)= 20 PS
	i8092MF_LINE_2D(cardNo, -10000, -10000);	//the 2 axis interpolation.
}



void Motion_test::OnAxis2_5() 
{

	// TODO: Add your control notification handler code here
	long fp1=20000;
	long fp2=20000;
	long c1=20000;
	long c2=0;
	int sv=100;
	int v=30000;
	int a=50000; 
	i8092MF_SET_MAX_V(cardNo, AXIS_XY,80000);
	//i8092MF_AXIS_ASSIGN(cardNo, AXIS_X, AXIS_Y, 0); 
	//set the axis1 as X axis2 as Y for interpolation axis.
	i8092MF_VECTOR_SPEED(cardNo, 5);		
	//set 2 axis as circular symmetrical T curve mode (VSVˇBVVˇBVAˇBVAO)
	i8092MF_SET_VSV(cardNo, sv);				//set the vector start speed as sv PPS.
	i8092MF_SET_VV(cardNo, v);					//set the vector speed as v PPS.
	i8092MF_SET_VA(cardNo, a);					//set the vector acc as a PPS/s. 
	i8092MF_SET_VAO(cardNo, 0);					//set the vector offset pulse(at VSV speed)= 0 PS
	i8092MF_ARC_CW(cardNo, c1,c2, fp1, fp2);	//the 2 axis ARC_CW interpolation.

}

void Motion_test::OnAxis2_6() 
{

	// TODO: Add your control notification handler code here
	 long c1=3000;
	 long c2=0;
	 int sv=100;
	 int v=8000;
	 int a=12500;
	 int d=12000;
	 i8092MF_SET_MAX_V(cardNo,AXIS_XY,32000);
	 i8092MF_VECTOR_SPEED(cardNo, 6);		
	 //set 2 axis as circular symmetrical T curve mode (VSVˇBVVˇBVAˇBVAO)
	 i8092MF_SET_VSV(cardNo, sv);		//set the vector start speed as sv PPS.
	 i8092MF_SET_VV(cardNo, v);			//set the vector speed as v PPS.
	 i8092MF_SET_VA(cardNo, a);			//set the vector acc as a PPS/s.
	 i8092MF_SET_VD(cardNo, d);			//set the vector dec as d PPS/s.
	 i8092MF_SET_VAO(cardNo, 0);		//set the vector offset pulse(at VSV speed)= 0 PS
	 i8092MF_CIRCLE_CW(cardNo, c1, c2); //the 2 axis CIRCLE_CW interpolation.

}

void Motion_test::OnRectan() 
{
	// TODO: Add your control notification handler code here
	int sv=1000;		//set the vector start speed as sv=1000 PPS.
	int v=30000;		//set the vector speed as v=30000 PPS.
	int a=150000;		//set the vector acc as a=15000 PPS/s.
	int d=150000;		//set the vector dec as d=15000 PPS/s.
	i8092MF_SET_MAX_V(cardNo, 0Xf,160000); //set max speed for all axis= 160000 PPSˇC
	i8092MF_RECTANGLE(cardNo, 1, 0, 0, 40000, 20000, 5000, sv, v, a, d);
}

void Motion_test::OnGear() 
{
	// TODO: Add your control notification handler code here
	int sv=300;		//PPSˇC
	int v=15000;	//PPSˇC
	int a=500000;	//PPS/sˇC 
	int loop1;
	int loop2;
	float ratio=0.72f;
	i8092MF_SET_MAX_V(cardNo, AXIS_XY,160000L);
	i8092MF_RATIO_INITIAL(cardNo, sv, v, a, ratio); 
	for (loop2 = 0; loop2 < 5; loop2++)
	{
		for (loop1 = 0; loop1 < 5; loop1++)
		{
			i8092MF_RATIO_2D(cardNo, 0, 3600, 0);
			i8092MF_RATIO_2D(cardNo, 0, 3600, 1);
		}
		i8092MF_RATIO_2D(cardNo, 0, 7200, 0);
		i8092MF_RATIO_2D(cardNo, 0, 3600, 1);
	}
	i8092MF_RATIO_2D(cardNo, 1, 7200, 1); 

}



void Motion_test::OnCMove() 
{

	// TODO: Add your control notification handler code here
	int sv=100;			//set the vector start speed as sv=100 PPS.
	int v=50000;		//set the vector speed as v=50000 PPS.
	int a=100000;		//set the vector acc as a=100000 PPS/s.
	int d=100000;		//set the vector dec as a=100000 PPS/s.
	i8092MF_SET_MAX_V(cardNo, AXIS_XY,80000);
	//set max speed for all axis= 80000 PPS.
	BYTE nType[10]=	{     1,     2,     1,     2,     1,7,0,0,0,0};
	long cp1[10]=   {     0, 10000,     0,     0,     0,0,0,0,0,0};
	long cp2[10]=   {     0,     0,     0,-10000,     0,0,0,0,0,0};
	long fp1[10]=   { 10000, 10000,  1000, 10000,-31000,0,0,0,0,0};
	long fp2[10]=   { 10000, 10000,     0,-10000,-10000,0,0,0,0,0};
    i8092MF_CONTINUE_INTP(cardNo , 1, sv, v, a, d, nType,cp1, cp2, fp1, fp2);

}


void Motion_test::OnGetError() 
{
	// TODO: Add your control notification handler code here
	WORD KK=0;
	KK=i8092MF_GET_ERROR(cardNo);
	CString MSGG;
	if (KK == YES)
	{
	char buffer[20];
	KK=i8092MF_GET_ERROR_CODE(cardNo, AXIS_X);
    _itoa( KK, buffer, 10 );
	if (KK==0)
		MSGG="Xerr: Soft_Stop ";
	else
		MSGG="Xerr:" + CString(buffer) + "  ";
	KK=i8092MF_GET_ERROR_CODE(cardNo, AXIS_Y);
	_itoa( KK, buffer, 10 );
	if (KK==0)
		MSGG=MSGG + "Yerr: Soft_Stop ";
	else
		MSGG=MSGG + "Yerr:" + CString(buffer) + "  ";
	}
	else
		MSGG="No Error";
    Show_Msg(MSGG);
}







void Motion_test::OnCMove2() 
{
	// TODO: Add your control notification handler code here
	unsigned short sv=300; //set the vector start speed PPSˇC
	unsigned short v=18000; //set the vector speed PPSˇC
	unsigned long a=500000; //set the vector ACC PPS/sˇC
	i8092MF_SET_MAX_V(cardNo, AXIS_XY,32000L);
	i8092MF_MIX_2D_INITIAL(cardNo, 1, sv, v, a);
	i8092MF_MIX_2D_CONTINUE(cardNo, 0, 1, 0,     0, 50000, 0);		//1 segment
    i8092MF_MIX_2D_CONTINUE(cardNo, 0, 2, 0,-20000,     0,-40000);	//2 segment
	i8092MF_MIX_2D_CONTINUE(cardNo, 0, 3, 0,-10000,     0,-20000);	//3 segment
	i8092MF_MIX_2D_CONTINUE(cardNo, 0, 3, 0, 10000,     0, 20000);	//4 segment
	i8092MF_MIX_2D_CONTINUE(cardNo, 0, 1, 0,     0,-50000,     0);	//5 segment
	i8092MF_MIX_2D_CONTINUE(cardNo, 0, 4, 0, 10000,     0,     0);	//6 segment
	i8092MF_MIX_2D_CONTINUE(cardNo, 0, 5, 0,-10000,     0,     0);	//7 segment
	i8092MF_MIX_2D_CONTINUE(cardNo, 1, 2, 0, 20000,     0, 40000);	
	//8 segment and end the Interpolation 
	//RUN XˇBY Continuous Mix Interpolation 2DˇC
}
