I was working on simulating suspension systems in quarter car vehicle using second order differential equations, and I was using Bees Algorithm to as PID controller.
def optimal_stiff(kt):
acc_t=-(kt\*(0-1)-ks\*(0-xt\[0\])-b\*(xs\[1\]-xt\[1\]))/Mt
return -abs(acc_t)
def cartire_optim(current_state,t):
xs[0],xt[0],xs[1],xt[1]=current_state # initialize the variables
if t<1: # initialize the road profile
xr=0
else:
xr=1
search_bound=([ks],[2*ks])
optimal= BeesAlgorithm(optimal_stiff,search_bound[0],search_bound[1])
optimal.performFullOptimisation(max_iteration=20)
stiff= optimal.best_solution
acc_s=-(ks*(xs[0]-xt[0])+b*(xs[1]-xt[1]))/Ms # acceleration of the Sprung mass
acc_t=-(stiff.values[0]*(xt[0]-xr)-ks*(xs[0]-xt[0])-b*(xs[1]-xt[1]))/Mt # acceleration of the Unsprung mass
return np.array([xs[1],xt[1],acc_s,acc_t])
solution_optim= odeint(cartire_optim,state,time_point)
When I define the variables needed and run the code, it works till a time step around 1.75 sec and spit out zeros.
The Graph of the xs
This line should stabilize at 1 not zero.