我可以得到的最小误差是15(基本值)左右,而我知道应该可以低于1。用于此的参数是当Kc = 1,tauI = 1,tauD = 1和tauC = 1时。通过使用迭代,窗口小部件以及反复试验来找到。我真的不知如何编码才能获得尽可能小的参数。似乎参数的任何变化都会导致此最小值的误差发生显着变化。任何帮助将不胜感激。
import sys
import control
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
# Pull data from CSV
file = 'profiledata.csv'
data = pd.read_csv(file,sep=',')
T_i = data.values
# Universal Variables
time_array = np.linspace(0,59,60)
perf = np.linspace(1,1,100)
average_perf = np.linspace(1,1,100)
Kc = 1
tI = 1
tD = 1
tC = 1
# Functions
for i in range(len(perf)):
s = control.tf([1,0],[0,1])
Gp = 1/(s**2 + s + 1)
Gd = (s+1)/(s**2+s+1)
Gc = Kc*(1+1/(tI*s) + tD*s/(tC*s + 1))
sys_D = Gd/(1+Gp*Gc)
_,T,_ = control.forced_response(sys_D, time_array, T_i[:,i])
# Compute output based on disturbance closed loop TF sys_D
_,Q,_ = control.forced_response(-Gc, time_array, T) # Compute input
perf[i] = sum(abs(T) + (0.2)*abs(Q))
# Calculate the average error from the parameters
average_perf = sum(perf)/100
print(average_perf)
预期结果是average_perf = 0时。读取的数据文件是100列60行的干扰曲线。无论如何,是否有要测试最佳参数,保留该参数,然后针对该参数针对最小误差进行完全优化的其他参数的测试?还是我只是看着这个完全错误。编码也是新手,所以我不确定如何有效地做到这一点。传递函数输入到for循环中。