sc 1 year ago
parent
commit
c0b3dd9e75
  1. 11
      UserClass/PID.cs
  2. 16
      ViewModel/MainWindowViewModel.cs

11
UserClass/PID.cs

@ -19,6 +19,7 @@ namespace DyeingComputer.UserClass
private static double e1 = 0; // Error one iteration old
private static double e2 = 0; // Error two iterations old
#region 构造函数
/// <summary>
/// PID构造器
/// </summary>
@ -38,6 +39,16 @@ namespace DyeingComputer.UserClass
this.OutputLowerLimit = OutputLowerLimit;
}
public PID()
{
this.Kp = 0.5;
this.Ki = 0.1;
this.Kd = 0.2;
this.N = 1;
this.OutputUpperLimit = 65530;
this.OutputLowerLimit = 0;
}
#endregion
/// <summary>
/// PID迭代器,在每个采样周期调用此函数以获取当前控制器输出。
/// 设定点和过程值应使用相同的单位。

16
ViewModel/MainWindowViewModel.cs

@ -52,23 +52,21 @@ namespace DyeingComputer.ViewModel
private readonly string DBAddress = Environment.CurrentDirectory + "\\DataBase\\800COMPUTER.db"; //数据库路径
private PID PID = null;
private IniFile.IniFiles Configini = new IniFile.IniFiles(Convert.ToString(System.AppDomain.CurrentDomain.BaseDirectory) + "DyeingComputer.ini");
PID pid = new PID();
public MainWindowViewModel()
{
SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径
SQLiteHelpers.Open(); //打开数据库
double ST01 = Convert.ToDouble( SQLiteHelpers.ExecuteScalar("select value from system where ParameterID = 'ST01'", null)); //读取
double ST02 = Convert.ToDouble( SQLiteHelpers.ExecuteScalar("select value from system where ParameterID = 'ST02'", null));
double ST03 = Convert.ToDouble( SQLiteHelpers.ExecuteScalar("select value from system where ParameterID = 'ST03'", null));
double ST04 = Convert.ToDouble(SQLiteHelpers.ExecuteScalar("select value from system where ParameterID = 'ST04'", null));
double ST05 = Convert.ToDouble(SQLiteHelpers.ExecuteScalar("select value from system where ParameterID = 'ST05'", null));
double ST06 = Convert.ToDouble(SQLiteHelpers.ExecuteScalar("select value from system where ParameterID = 'ST06'", null));
pid.Kp = Convert.ToDouble( SQLiteHelpers.ExecuteScalar("select value from system where ParameterID = 'ST01'", null)); //读取
pid.Ki = Convert.ToDouble( SQLiteHelpers.ExecuteScalar("select value from system where ParameterID = 'ST02'", null));
pid.Kd = Convert.ToDouble( SQLiteHelpers.ExecuteScalar("select value from system where ParameterID = 'ST03'", null));
pid.N = Convert.ToDouble(SQLiteHelpers.ExecuteScalar("select value from system where ParameterID = 'ST04'", null));
pid.OutputUpperLimit = Convert.ToDouble(SQLiteHelpers.ExecuteScalar("select value from system where ParameterID = 'ST05'", null));
pid.OutputLowerLimit = Convert.ToDouble(SQLiteHelpers.ExecuteScalar("select value from system where ParameterID = 'ST06'", null));
SQLiteHelpers.Close();
WorkNumder = "----------";
PID pid=new PID(ST01,ST02,ST03,ST04,ST05,ST06);
CountDown(); //启动循环任务
SQL_data(); //读数据库
UPort(); //启动串口

Loading…
Cancel
Save