モデル化する方程式を作成してから、統合制御システムをプロットしようとしています (特にクルーズ コントロールに関して)。ただし、実行するたびに2つのエラーが発生します。
ValueError: 必要な配列に対してオブジェクトが深すぎます odepack.error: 関数呼び出しの結果が浮動小数点数の適切な配列ではありません。
私はこれらの質問を読みました:
- scipy curve_fit エラー: 関数呼び出しの結果が浮動小数点数の適切な配列ではありません
- scipy odeint を使用してこの微分方程式を解くには?
- オブジェクトが目的の配列に対して深すぎる - scipy.integrate.odeint
それらは役立つはずですが、それらを私の問題に適用する方法がわかりません。私はPythonにかなり慣れていないので、明らかなことを見逃したり、非常にばかげたことをしたりした場合は、ご容赦ください。プロットに問題はないので、実際にこれを機能させる方法を理解したら、準備ができたと思います。
import numpy as np
import scipy.integrate as integrate
##Parameters
kp=.5 #proportional gain
ki=.1 #integral gain
vr=30 #desired velocity in m/s
Tm=190 #Max Torque in Nm
wm=420 #engine speed
B=0.4 #Beta
an=12 #at gear 4
p=1.3 #air density
Cd=0.32 #Drag coefficient
Cr=.01 #Coefficient of rolling friction
A=2.4 #frontal area
##Variables
m=18000 #weight
v=20 #starting velocity
time=np.linspace(0,10,50) #time
theta=np.radians(4) #Theta
def vderivs(state,t):
v = state
vel=[]
ti=0
while ti < t:
v1 = an*controller(ti,vr,v)*torque(v)
v2 = m*Cr*np.sign(v)
v3 = 0.5*p*Cd*A*v**2
v4 = m*np.sin(theta)
if t < 10:
vtot = v1+v2+v3
vfin = np.divide(vtot,m)
else:
vtot = v1+v2+v3+v4
vfin = np.divide(vtot,m)
vel.append(vfin)
ti+=1
trueVel = np.array(vel, float)
return trueVel
def uderivs(state,t):
v = state
deltax = vr - v
return deltax
def controller(time,desired,currentV):
z = integrate.odeint(uderivs, currentV, time)
u = kp*(vr-currentV)+ki*z
return u.flatten()
def torque(v):
return Tm*(1-B*(np.divide(an*v,wm)-1)**2)
def velocity(mass,desired,theta,t):
v = integrate.odeint(vderivs, desired, t)
return v.flatten()
test = velocity(m,vr,theta,time)
print(test)
他に何か必要なことがあれば教えてください。