?? customparamdlg.cpp
字號:
// CustomParamDlg.cpp : implementation file
//
#include "stdafx.h"
#include "watertank.h"
#include "CustomParamDlg.h"
#include "ExternData.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define DllImport __declspec(dllimport)
extern DllImport ExternData Dll_ExternData;
/////////////////////////////////////////////////////////////////////////////
// CCustomParamDlg dialog
CCustomParamDlg::CCustomParamDlg(CWnd* pParent /*=NULL*/)
: CDialog(CCustomParamDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CCustomParamDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
m_nLoop = 2;
m_dKp[0] = 0.0;
m_dKi[0] = 0.0;
m_dKd[0] = 0.0;
m_dKp[1] = 0.0;
m_dKi[1] = 0.0;
m_dKd[1] = 0.0;
m_bChangeMode = TRUE;
}
void CCustomParamDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CCustomParamDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CCustomParamDlg, CDialog)
//{{AFX_MSG_MAP(CCustomParamDlg)
ON_BN_CLICKED(IDC_BUTTON_SAVECUSTOMPARAM, OnButtonSavecustomparam)
ON_BN_CLICKED(IDC_BUTTON_LOADCUSTOMPARAM, OnButtonLoadcustomparam)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCustomParamDlg message handlers
BOOL CCustomParamDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
if(m_bChangeMode == FALSE)
{
GetDlgItem(IDC_BUTTON_LOADCUSTOMPARAM)->EnableWindow(FALSE);
GetDlgItem(IDC_BUTTON_SAVECUSTOMPARAM)->EnableWindow(FALSE);
GetDlgItem(IDOK)->EnableWindow(FALSE);
}
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CCustomParamDlg::OnButtonSavecustomparam()
{
CFileDialog dlg(FALSE, NULL, Dll_ExternData.m_pchCustomFileName);
dlg.m_ofn.lpstrInitialDir = Dll_ExternData.m_pchCustomParamDir;
dlg.m_ofn.lpstrDefExt = "cus";
dlg.m_ofn.lpstrFilter = "Custom-Control Param File(*.cus)\0*.cus";
if(dlg.DoModal() == IDOK)
{
CString str = dlg.GetPathName();
int index = str.ReverseFind('\\');
CString str2 = str.Left(index);
strcpy(Dll_ExternData.m_pchCustomParamDir, str2);
str2 = str.Right(str.GetLength() - index - 1);
strcpy(Dll_ExternData.m_pchCustomFileName, str2);
FILE *file;
if( (file = fopen(str, "wt")) == NULL)
{
MessageBox("Can't open file " + str);
return;
}
fputs("Custom parameters\n", file);
str2.Format("loopnumber = %d\n", m_nLoop);
fputs(str2,file);
for(int loop = 0; loop < m_nLoop; loop ++)
{
str2.Format("loop %d: Kp\tKi\tKd\n", loop+1);
fputs(str2, file);
str2.Format("%14.10Lf\t%14.10Lf\t%14.10Lf\n", m_dKp[loop], m_dKi[loop], m_dKd[loop]);
fputs(str2, file);
}
fclose(file);
}
}
void CCustomParamDlg::OnButtonLoadcustomparam()
{
CFileDialog dlg(TRUE, NULL, Dll_ExternData.m_pchCustomFileName);
dlg.m_ofn.lpstrInitialDir = Dll_ExternData.m_pchCustomParamDir;
dlg.m_ofn.lpstrDefExt = "cus";
dlg.m_ofn.lpstrFilter = "Custom-Control Param File(*.cus)\0*.cus";
if(dlg.DoModal() == IDOK)
{
CString str = dlg.GetPathName();
int index = str.ReverseFind('\\');
CString str2 = str.Left(index);
strcpy(Dll_ExternData.m_pchCustomParamDir, str2);
str2 = str.Right(str.GetLength() - index - 1);
strcpy(Dll_ExternData.m_pchCustomFileName, str2);
FILE *file;
if( (file = fopen(str, "rt")) == NULL)
{
MessageBox("Can't open file " + str);
return;
}
char buff[256];
fgets(buff, 256, file);
if(strcmp(buff,"Custom parameters\n") != 0)
{
MessageBox("Invalidate Custom parameter file!");
return;
}
int nloop = 0;
fscanf(file, "loopnumber = %d\n", &nloop);
if(nloop <= 0)
{
MessageBox("Invalidate Custom parameter file, loop number!");
return;
}
m_nLoop = nloop;
double kp,ki,kd;
for(int loop = 0; loop < m_nLoop; loop++)
{
fgets(buff, 256, file);
str2.Format("loop %d: Kp\tKi\tKd\n", loop+1);
if(strcmp(buff,str2) != 0)
{
MessageBox("Invalidate Custom parameter file, PID parameter!");
return;
}
kp = ki = kd = 0.0;
fscanf(file, "%Lf\t%Lf\t%Lf\n", &kp, &ki, &kd);
m_dKp[loop] = kp;
m_dKi[loop] = ki;
m_dKd[loop] = kd;
}
fclose(file);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -