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

📄 pid.cpp

📁 变增益PID算法的c++实现
💻 CPP
📖 第 1 页 / 共 3 页
字号:
SetDlgItemText(IDC_EDIT_KP,string); 

dt=theApp.m_pid_para.ki[theApp.channel]; 
dt=dt/100; 
string.Format(">3.2f",dt); 
SetDlgItemText(IDC_EDIT_KI,string); 

string.Format(">4d",theApp.m_pid_para.kd[theApp.channel]); 
SetDlgItemText(IDC_EDIT_KD,string); 

string.Format(">5d",theApp.m_pid_para.bias[theApp.channel]); 
SetDlgItemText(IDC_EDIT_KP4,string); 


dt=theApp.m_pid_para.accel[theApp.channel]; 
dt=dt/10; 
string.Format(">3.1f",dt);//加速速率 放大10倍 
SetDlgItemText(IDC_EDIT_KP6,string); 


dt=theApp.m_pid_para.integral[theApp.channel]; 
dt=dt/10; 
string.Format(">3.1f",dt);//放大10倍 
SetDlgItemText(IDC_EDIT_KP7,string); 


dt=temp_value[theApp.channel]; 
dt=dt/10; 
string.Format(">3.1f",dt); 
SetDlgItemText(IDC_EDITPV,string); 


dt=setpt[theApp.channel]; 
dt=dt/10; 
string.Format(">3.1f",dt); 
SetDlgItemText(IDC_EDITSV,string); 



dt=theApp.accel_value[0]; 
dt=dt/10; 
string.Format(">3.1f",dt); 
SetDlgItemText(IDC_EDIT_ACCEL,string); 

} 

void CFUZZYDlg::OnTimer(UINT nIDEvent) 
{ 
// TODO: Add your message handler code here and/or call default 

CDialog::OnTimer(nIDEvent); 
} 

void CFUZZYDlg::OnEnChangeEditKp() 
{ 
// 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 
double dx; 
char Buf[32]; 
short j; 
GetDlgItemText(IDC_EDIT_KP,Buf,20); 
dx=atof(Buf); 
j=dx*1000; 
theApp.m_pid_para.kp[theApp.channel]=j; 
} 

void CFUZZYDlg::OnEnChangeEditKi() 
{ 
// 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 
double dx; 
char Buf[32]; 
short j; 
GetDlgItemText(IDC_EDIT_KI,Buf,20); 
dx=atof(Buf); 
j=dx*100; 
theApp.m_pid_para.ki[theApp.channel]=j; 
} 

void CFUZZYDlg::OnEnChangeEditKd() 
{ 
// 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 
char Buf[32]; 
short j; 
GetDlgItemText(IDC_EDIT_KD,Buf,20); 
theApp.m_pid_para.kd[theApp.channel]=atoi(Buf); 
} 

void CFUZZYDlg::OnEnChangeEditKp4() 
{ 
// 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 
double dx; 
char Buf[32]; 
short j; 
GetDlgItemText(IDC_EDIT_KP4,Buf,20); 
theApp.m_pid_para.bias[theApp.channel]=atoi(Buf);; 

} 

void CFUZZYDlg::OnBnClickedButton1() 
{ 
// TODO: Add your control notification handler code here 
theApp.PidRun(theApp.channel); 
OnFlashData(); 
OnUpdatePara(); 
} 

void CFUZZYDlg::OnEnChangeEditKp5() 
{ 
// 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 
char Buf[32]; 
int j; 
GetDlgItemText(IDC_EDIT_KP5,Buf,20); 
j=atoi(Buf); 
if(j>31) j=31; 
theApp.channel=j; 
} 

void CFUZZYDlg::OnBnClickedButton2() 
{ 
// TODO: Add your control notification handler code here 
theApp.SavePidPara(); 
theApp.LoadPidPara(); 
} 

void CFUZZYDlg::OnFlashData() 
{ 
CString string; 
double dt; 


string.Format(">3d",m_fuzzy.crisp_inputs[0]); 
SetDlgItemText(IDC_EDIT1,string); 

string.Format(">3d",m_fuzzy.crisp_inputs[1]); 
SetDlgItemText(IDC_EDIT2,string); 

//===========e隶属度=========================================== 
dt=m_fuzzy.fuzzy_inputs[0][0]; 
dt=dt/1000; 
string.Format(">3.1f",dt); 
SetDlgItemText(IDC_EDITA1,string); 

dt=m_fuzzy.fuzzy_inputs[0][1]; 
dt=dt/1000; 
string.Format(">3.1f",dt); 
SetDlgItemText(IDC_EDITA2,string); 

dt=m_fuzzy.fuzzy_inputs[0][2]; 
dt=dt/1000; 
string.Format(">3.1f",dt); 
SetDlgItemText(IDC_EDITA3,string); 

dt=m_fuzzy.fuzzy_inputs[0][3]; 
dt=dt/1000; 
string.Format(">3.1f",dt); 
SetDlgItemText(IDC_EDITA4,string); 

dt=m_fuzzy.fuzzy_inputs[0][4]; 
dt=dt/1000; 
string.Format(">3.1f",dt); 
SetDlgItemText(IDC_EDITA5,string); 

dt=m_fuzzy.fuzzy_inputs[0][5]; 
dt=dt/1000; 
string.Format(">3.1f",dt); 
SetDlgItemText(IDC_EDITA6,string); 

dt=m_fuzzy.fuzzy_inputs[0][6]; 
dt=dt/1000; 
string.Format(">3.1f",dt); 
SetDlgItemText(IDC_EDITA7,string); 


//=========== ec 隶属度=========================================== 
dt=m_fuzzy.fuzzy_inputs[1][0]; 
dt=dt/1000; 
string.Format(">3.1f",dt); 
SetDlgItemText(IDC_EDITDA1,string); 

dt=m_fuzzy.fuzzy_inputs[1][1]; 
dt=dt/1000; 
string.Format(">3.1f",dt); 
SetDlgItemText(IDC_EDITDA2,string); 

dt=m_fuzzy.fuzzy_inputs[1][2]; 
dt=dt/1000; 
string.Format(">3.1f",dt); 
SetDlgItemText(IDC_EDITDA3,string); 


dt=m_fuzzy.fuzzy_inputs[1][3]; 
dt=dt/1000; 
string.Format(">3.1f",dt); 
SetDlgItemText(IDC_EDITDA4,string); 


dt=m_fuzzy.fuzzy_inputs[1][4]; 
dt=dt/1000; 
string.Format(">3.1f",dt); 
SetDlgItemText(IDC_EDITDA5,string); 

dt=m_fuzzy.fuzzy_inputs[1][5]; 
dt=dt/1000; 
string.Format(">3.1f",dt); 
SetDlgItemText(IDC_EDITDA6,string); 

dt=m_fuzzy.fuzzy_inputs[1][6]; 
dt=dt/1000; 
string.Format(">3.1f",dt); 
SetDlgItemText(IDC_EDITDA7,string); 


//=====ΔP============================= 
string.Format(">5d",m_fuzzy.crisp_outputs[0]); 
SetDlgItemText(IDC_EDIT3,string); 

dt=m_fuzzy.fuzzy_outputs_image[0][0]; 
dt=dt/1000; 
string.Format(">3.1f",dt); 
SetDlgItemText(IDC_EDITDM1,string); 

dt=m_fuzzy.fuzzy_outputs_image[0][1]; 
dt=dt/1000; 
string.Format(">3.1f",dt); 
SetDlgItemText(IDC_EDITDM2,string); 

dt=m_fuzzy.fuzzy_outputs_image[0][2]; 
dt=dt/1000; 
string.Format(">3.1f",dt); 
SetDlgItemText(IDC_EDITDM3,string); 


dt=m_fuzzy.fuzzy_outputs_image[0][3]; 
dt=dt/1000; 
string.Format(">3.1f",dt); 
SetDlgItemText(IDC_EDITDM4,string); 


dt=m_fuzzy.fuzzy_outputs_image[0][4]; 
dt=dt/1000; 
string.Format(">3.1f",dt); 
SetDlgItemText(IDC_EDITDM5,string); 


dt=m_fuzzy.fuzzy_outputs_image[0][5]; 
dt=dt/1000; 
string.Format(">3.1f",dt); 
SetDlgItemText(IDC_EDITDM6,string); 


dt=m_fuzzy.fuzzy_outputs_image[0][6]; 
dt=dt/1000; 
string.Format(">3.1f",dt); 
SetDlgItemText(IDC_EDITDM7,string); 


//=====ΔI============================= 
string.Format(">5d",m_fuzzy.crisp_outputs[1]); 
SetDlgItemText(IDC_EDIT4,string); 

dt=m_fuzzy.fuzzy_outputs_image[1][0]; 
dt=dt/1000; 
string.Format(">3.1f",dt); 
SetDlgItemText(IDC_EDITDM8,string); 

dt=m_fuzzy.fuzzy_outputs_image[1][1]; 
dt=dt/1000; 
string.Format(">3.1f",dt); 
SetDlgItemText(IDC_EDITDM9,string); 

dt=m_fuzzy.fuzzy_outputs_image[1][2]; 
dt=dt/1000; 
string.Format(">3.1f",dt); 
SetDlgItemText(IDC_EDITDM10,string); 


dt=m_fuzzy.fuzzy_outputs_image[1][3]; 
dt=dt/1000; 
string.Format(">3.1f",dt); 
SetDlgItemText(IDC_EDITDM11,string); 


dt=m_fuzzy.fuzzy_outputs_image[1][4]; 
dt=dt/1000; 
string.Format(">3.1f",dt); 
SetDlgItemText(IDC_EDITDM12,string); 


dt=m_fuzzy.fuzzy_outputs_image[1][5]; 
dt=dt/1000; 
string.Format(">3.1f",dt); 
SetDlgItemText(IDC_EDITDM13,string); 


dt=m_fuzzy.fuzzy_outputs_image[1][6]; 
dt=dt/1000; 
string.Format(">3.1f",dt); 
SetDlgItemText(IDC_EDITDM14,string); 


//=====ΔD============================= 
string.Format(">5d",m_fuzzy.crisp_outputs[2]); 
SetDlgItemText(IDC_EDIT5,string); 

dt=m_fuzzy.fuzzy_outputs_image[2][0]; 
dt=dt/1000; 
string.Format(">3.1f",dt); 
SetDlgItemText(IDC_EDITDM15,string); 

dt=m_fuzzy.fuzzy_outputs_image[2][1]; 
dt=dt/1000; 
string.Format(">3.1f",dt); 
SetDlgItemText(IDC_EDITDM16,string); 

dt=m_fuzzy.fuzzy_outputs_image[2][2]; 
dt=dt/1000; 
string.Format(">3.1f",dt); 
SetDlgItemText(IDC_EDITDM17,string); 


dt=m_fuzzy.fuzzy_outputs_image[2][3]; 
dt=dt/1000; 
string.Format(">3.1f",dt); 
SetDlgItemText(IDC_EDITDM18,string); 


dt=m_fuzzy.fuzzy_outputs_image[2][4]; 
dt=dt/1000; 
string.Format(">3.1f",dt); 
SetDlgItemText(IDC_EDITDM19,string); 


dt=m_fuzzy.fuzzy_outputs_image[2][5]; 
dt=dt/1000; 
string.Format(">3.1f",dt); 
SetDlgItemText(IDC_EDITDM20,string); 

dt=m_fuzzy.fuzzy_outputs_image[2][6]; 
dt=dt/1000; 
string.Format(">3.1f",dt); 
SetDlgItemText(IDC_EDITDM21,string); 

//=== P=1+ΔP============================= 
dt=m_fuzzy.crisp_scale[0]; 
dt=dt/1000; 
string.Format(">3.3f",dt); 
SetDlgItemText(IDC_EDITP,string); 

//=== I=1+ΔI============================= 
dt=m_fuzzy.crisp_scale[1]; 
dt=dt/1000; 
string.Format(">3.3f",dt); 
SetDlgItemText(IDC_EDITI,string); 

//=== D=1+ΔD============================= 
dt=m_fuzzy.crisp_scale[2]; 
dt=dt/1000; 
string.Format(">3.3f",dt); 
SetDlgItemText(IDC_EDITD,string); 

//======================================== 
string.Format(">5d",theApp.m_pid[theApp.channel].this_Output); 
SetDlgItemText(IDC_EDIT_SUM,string); 


//======================================== 
string.Format(">7d",theApp.m_pid[theApp.channel].test_kd); 
SetDlgItemText(IDC_EDIT6,string); 


} 

void CFUZZYDlg::OnEnChangeEditpv() 
{//PV 
// 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 
char Buf[32]; 
double dx; 
GetDlgItemText(IDC_EDITPV,Buf,20); 
dx=atof(Buf); 
dx=dx*10; 
temp_value[theApp.channel]=dx; 
} 

void CFUZZYDlg::OnEnChangeEditsv() 
{//SV 
// 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 
char Buf[32]; 
double dx; 
GetDlgItemText(IDC_EDITSV,Buf,20); 
dx=atof(Buf); 
dx=dx*10; 
setpt[theApp.channel]=dx; 
} 


void CFUZZYDlg::OnEnChangeEditKp6() 
{//ACCEL 
// 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 
char Buf[32]; 
double dx; 
short j; 
GetDlgItemText(IDC_EDIT_KP6,Buf,20);//加速速率 放大10倍 
dx=atof(Buf); 
theApp.m_pid_para.accel[theApp.channel]=dx*10; 
} 

void CFUZZYDlg::OnEnChangeEditKp7() 
{// 开始调节 
// 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 
char Buf[32]; 
short j; 
double dx; 
GetDlgItemText(IDC_EDIT_KP7,Buf,20); 
dx=atof(Buf); 
theApp.m_pid_para.integral[theApp.channel]=dx*10;// 放大10倍 

} 
 

⌨️ 快捷键说明

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