📄 demo_movedlg.cpp
字号:
(CButton*)GetDlgItem(IDC_CHECK_X)->EnableWindow(TRUE);
(CButton*)GetDlgItem(IDC_CHECK_Y)->EnableWindow(TRUE);
(CButton*)GetDlgItem(IDC_CHECK_Z)->EnableWindow(TRUE);
(CButton*)GetDlgItem(IDC_CHECK_W)->EnableWindow(TRUE);
if(m_bEnableDemo_x)(CButton*)GetDlgItem(IDC_EDIT_COUNT_PULSE_X)->EnableWindow(TRUE);
if(m_bEnableDemo_y)(CButton*)GetDlgItem(IDC_EDIT_COUNT_PULSE_Y)->EnableWindow(TRUE);
if(m_bEnableDemo_z)(CButton*)GetDlgItem(IDC_EDIT_COUNT_PULSE_Z)->EnableWindow(TRUE);
if(m_bEnableDemo_w)(CButton*)GetDlgItem(IDC_EDIT_COUNT_PULSE_W)->EnableWindow(TRUE);
EnableCheckWnd(m_bEqualityVelocity);
}
else
{
(CButton*)GetDlgItem(IDC_BTN_SETTING)->EnableWindow(FALSE);
(CButton*)GetDlgItem(IDCANCEL)->EnableWindow(FALSE);
(CButton*)GetDlgItem(IDC_BUTTON_CLEAR)->EnableWindow(FALSE);
(CButton*)GetDlgItem(IDC_BTN_CONTINUE)->EnableWindow(FALSE);
(CButton*)GetDlgItem(IDOK)->EnableWindow(FALSE);
(CButton*)GetDlgItem(IDC_RADIO_UNCHANGE)->EnableWindow(FALSE);
(CButton*)GetDlgItem(IDC_RADIO_ALTERNATION)->EnableWindow(FALSE);
(CButton*)GetDlgItem(IDC_CHECK_X)->EnableWindow(FALSE);
(CButton*)GetDlgItem(IDC_CHECK_Y)->EnableWindow(FALSE);
(CButton*)GetDlgItem(IDC_CHECK_Z)->EnableWindow(FALSE);
(CButton*)GetDlgItem(IDC_CHECK_W)->EnableWindow(FALSE);
EnableCheckWnd(TRUE);
(CButton*)GetDlgItem(IDC_EDIT_COUNT_PULSE_X)->EnableWindow(FALSE);
(CButton*)GetDlgItem(IDC_EDIT_COUNT_PULSE_Y)->EnableWindow(FALSE);
(CButton*)GetDlgItem(IDC_EDIT_COUNT_PULSE_Z)->EnableWindow(FALSE);
(CButton*)GetDlgItem(IDC_EDIT_COUNT_PULSE_W)->EnableWindow(FALSE);
}
CDialog::OnTimer(nIDEvent);
}
void CDemo_moveDlg::OnCancel()
{
// TODO: Add extra cleanup here
KillTimer(1);
// adt850_end();
if(m_pToolTip) delete m_pToolTip;
sudden_stop(0,1);
sudden_stop(0,2);
sudden_stop(0,3);
sudden_stop(0,4);
CDialog::OnCancel();
}
void CDemo_moveDlg::OnBtnContinue()
{
// TODO: Add your control notification handler code here
if(!m_bEnableDemo_x&&!m_bEnableDemo_y&&!m_bEnableDemo_z&&!m_bEnableDemo_w)
{
MessageBox("请选择驱动轴!");
return;
}
UpdateData();
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);
//--------------------速度设置------------------------
if(m_bEqualityVelocity){ //匀速运动
set_startv(0,1,m_nDriveSpeed_x/m_nRatio_x);
set_startv(0,2,m_nDriveSpeed_y/m_nRatio_y);
set_startv(0,3,m_nDriveSpeed_z/m_nRatio_z);
set_startv(0,4,m_nDriveSpeed_w/m_nRatio_w);
set_speed(0,1,m_nDriveSpeed_x/m_nRatio_x);
set_speed(0,2,m_nDriveSpeed_y/m_nRatio_y);
set_speed(0,3,m_nDriveSpeed_z/m_nRatio_z);
set_speed(0,4,m_nDriveSpeed_w/m_nRatio_w);
}
else{ //加/减速运动
set_startv(0,1,m_nStartV_x/m_nRatio_x);
set_startv(0,2,m_nStartV_y/m_nRatio_y);
set_startv(0,3,m_nStartV_z/m_nRatio_z);
set_startv(0,4,m_nStartV_w/m_nRatio_w);
set_speed(0,1,m_nDriveSpeed_x/m_nRatio_x);
set_speed(0,2,m_nDriveSpeed_y/m_nRatio_y);
set_speed(0,3,m_nDriveSpeed_z/m_nRatio_z);
set_speed(0,4,m_nDriveSpeed_w/m_nRatio_w);
}
if(!m_bEqualityVelocity)SetAddSpeed();
if(m_bEnableDemo_x) continue_move(0,1,0);
if(m_bEnableDemo_y) continue_move(0,2,0);
if(m_bEnableDemo_z) continue_move(0,3,0);
if(m_bEnableDemo_w) continue_move(0,4,0);
}
void CDemo_moveDlg::CheckAxisStatus()
{
int state=-1;
if(m_bEnableDemo_x){
while(state!=0)
get_status(cardno,1,&state);
state=-1;
}
if(m_bEnableDemo_y){
while(state!=0)
get_status(cardno,2,&state);
state=-1;
}
if(m_bEnableDemo_z){
while(state!=0)
get_status(cardno,3,&state);
state=-1;
}
if(m_bEnableDemo_w){
while(state!=0)
get_status(cardno,4,&state);
state=-1;
}
}
void CDemo_moveDlg::SetAllAxisLogicPos()
{
if(m_bEnableDemo_x) set_command_pos(cardno,1,0);
if(m_bEnableDemo_y) set_command_pos(cardno,2,0);
if(m_bEnableDemo_z) set_command_pos(cardno,3,0);
if(m_bEnableDemo_w) set_command_pos(cardno,4,0);
}
void CDemo_moveDlg::Init850Card()
{
int count;
const int nCoefficient=8000000;
cardno=0;
count=adt850_initial();
if(count<1) {
MessageBox("未安装850卡!");
CDialog::OnCancel();
}
long nValue;
set_command_pos(cardno,1,0);
set_command_pos(cardno,2,0);
set_command_pos(cardno,3,0);
set_command_pos(cardno,4,0);
//------------------倍率=8000000/R-----------------------------------------
//函数set_range()中的最后一个参数 由R=8000000/倍率来确定.
//------------------设置倍率参数-------------------------------------------
nValue = nCoefficient/m_nRatio_x ;
set_range(cardno,1,nValue);
nValue = nCoefficient/m_nRatio_y ;
set_range(cardno,2,nValue);
nValue = nCoefficient/m_nRatio_z ;
set_range(cardno,3,nValue);
nValue = nCoefficient/m_nRatio_w ;
set_range(cardno,4,nValue);
//------------------设置起始速度-------------------------------------------
nValue=m_nStartV_x/m_nRatio_x;
set_startv(cardno,1,nValue);
nValue=m_nStartV_y/m_nRatio_y;
set_startv(cardno,2,nValue);
nValue=m_nStartV_z/m_nRatio_z;
set_startv(cardno,3,nValue);
nValue=m_nStartV_w/m_nRatio_w;
set_startv(cardno,4,nValue);
//------------------设置驱动速度-------------------------------------------
nValue=m_nDriveSpeed_x/m_nRatio_x;
set_speed(cardno,1,nValue);
nValue=m_nDriveSpeed_y/m_nRatio_y;
set_speed(cardno,2,nValue);
nValue=m_nDriveSpeed_z/m_nRatio_z;
set_speed(cardno,3,nValue);
nValue=m_nDriveSpeed_w/m_nRatio_w;
set_speed(cardno,4,nValue);
}
void CDemo_moveDlg::OnChangeEditCountPulseX()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
/*LPTSTR lpStr;
BYTE count;
long nValue;
count=GetDlgItemText(IDC_EDIT_COUNT_PULSE_X,lpStr,9);
nValue=::atol(lpStr);*/
}
void CDemo_moveDlg::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
/* CRect rc;
for(int i=0;i<4;i++){
rc.CopyRect(&arrInfo[i].rc);
rc.NormalizeRect();
if(rc.PtInRect(point)){
tool.SetToolRect(this,arrInfo[i].dwID,&arrInfo[i].rc);
tool.UpdateTipText("1 to 800000",this,arrInfo[i].dwID);
break;
}
}*/
CDialog::OnMouseMove(nFlags, point);
}
BOOL CDemo_moveDlg::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
if (NULL != m_pToolTip)
m_pToolTip->RelayEvent(pMsg);
return CDialog::PreTranslateMessage(pMsg);
}
void CDemo_moveDlg::OnButtonOnstop()
{
// TODO: Add your control notification handler code here
if(m_bEnableDemo_x) sudden_stop(cardno,1);
if(m_bEnableDemo_y) sudden_stop(cardno,2);
if(m_bEnableDemo_z) sudden_stop(cardno,3);
if(m_bEnableDemo_w) sudden_stop(cardno,4);
}
void CDemo_moveDlg::SetAddSpeed()
{ UpdateData();
long nValue;
if(!m_bEqualityVelocity){ //加/减速运动
BOOL bMode_Acc;
bMode_Acc=m_bEnableCurve_Move ? 1:0;
//---------------设为梯形/S形加减速.0为梯形,1为S形----------------------
set_ad_mode(cardno,1,bMode_Acc);
set_ad_mode(cardno,2,bMode_Acc);
set_ad_mode(cardno,3,bMode_Acc);
set_ad_mode(cardno,4,bMode_Acc);
//---------------对每轴设置,对称加减速/非对称加减速,0为对称,1为非对称----------------
bMode_Acc=m_bEnableSymmetry_Acc_x ? 1:0;
set_dec1_mode(cardno,1,bMode_Acc);
bMode_Acc=m_bEnableSymmetry_Acc_y ? 1:0;
set_dec1_mode(cardno,2,bMode_Acc);
bMode_Acc=m_bEnableSymmetry_Acc_z ? 1:0;
set_dec1_mode(cardno,3,bMode_Acc);
bMode_Acc=m_bEnableSymmetry_Acc_w ? 1:0;
set_dec1_mode(cardno,4,bMode_Acc);
//-----------------------采用自动减速方式-------------------------------------------------
for(int j=1;j<5;j++)
set_dec2_mode(cardno,j,0);
//-----------------------设置每轴的加速度-----------------------------------------------
//------------加速度的实际值为nValue=m_nVelocityAcc_x*125*m_nRatio_x--------------------
set_acc(cardno,1,m_nVelocityAcc_x);
//------------加速度的实际值为nValue=m_nVelocityAcc_y*125*m_nRatio_y--------------------
set_acc(cardno,2,m_nVelocityAcc_y);
//------------加速度的实际值为nValue=m_nVelocityAcc_z*125*m_nRatio_z--------------------
set_acc(cardno,3,m_nVelocityAcc_z);
//------------加速度的实际值为nValue=m_nVelocityAcc_w*125*m_nRatio_w--------------------
set_acc(cardno,4,m_nVelocityAcc_w);
//-----------------------设置每轴的减速度-----------------------------------------------
//------------减速度的实际值为nValue=m_nVelocityDec_x*125*m_nRatio_x--------------------
set_dec(cardno,1,m_nVelocityDec_x);
//------------减速度的实际值为nValue=m_nVelocityDec_y*125*m_nRatio_y--------------------
set_dec(cardno,2,m_nVelocityDec_y);
//------------减速度的实际值为nValue=m_nVelocityDec_z*125*m_nRatio_z--------------------
set_dec(cardno,3,m_nVelocityDec_z);
//------------减速度的实际值为nValue=m_nVelocityDec_w*125*m_nRatio_w--------------------
set_dec(cardno,4,m_nVelocityDec_w);
//-----------------------如果是S形加速运动,设置速度增加率.-----------------------------
if(m_bEnableCurve_Move){
if(m_fAccTime_x==0||m_fAccTime_y==0||m_fAccTime_z==0||m_fAccTime_w==0)return;
int nAccValue;
nValue=long(m_nVelocityAcc_x/m_fAccTime_x);
nAccValue=62500000 * m_nRatio_x/nValue;
set_acac(cardno,1,nAccValue);
nValue=long(m_nVelocityAcc_y/m_fAccTime_y);
nAccValue=62500000 * m_nRatio_y/nValue;
set_acac(cardno,2,nAccValue);
nValue=long(m_nVelocityAcc_z/m_fAccTime_z);
nAccValue=62500000 * m_nRatio_z/nValue;
set_acac(cardno,3,nAccValue);
nValue=long(m_nVelocityAcc_w/m_fAccTime_w);
nAccValue=62500000 * m_nRatio_w/nValue;
set_acac(cardno,4,nAccValue);
}
}
}
void CDemo_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_moveDlg::CheckNum(long &num, long min, long max)
{
//数值范围
if(num<min)num=min;
if(num>max)num=max;
}
void CDemo_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);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -