def system(t, x): # System parameters g, mc, m, l = 9.8, 1, 0.1, 0.5 # Controller parameters r1, r2, r3 = 0.91, 0.09, 2 q1, q2, a1, a2 = 0.5, 0.5, 1, 1.1 i = 4 # Reference r = np.sin(0.5 * np.pi * t) dr = 0.5 * np.pi * np.cos(0.5 * np.pi * t) d2r = -(0.5 * np.pi)**2 * r # State variables x1, x2 = x[0], x[1] # Error variables e1, e2 = x1 - r, x2 - dr # Disturbance Delta = np.sin(10 * x1) + np.cos(x2) # Sliding variable s = e2 + sol.odd_pow( sol.odd_pow(e2, 2) + 2 / (r1**2) * sol.odd_pow(invdW(i, e1, q1, a1), 2), 0.5) # Controller us = -1 / r2 * invdW(i, s, q2, a2) - r3 * np.sign(invdW( i, s, q2, a2)) - 2 / (r1**2) * proddW(i, e1, q1, a1) * np.sign( invdW(i, s, q2, a2)) f = (g * np.sin(x1) - m * l * x2**2 * np.cos(x1) * np.sin(x1) / (mc + m)) / (l * (4 / 3 - m * np.cos(x1)**2 / (mc + m))) - d2r g = (np.cos(x1) / (mc + m)) / (l * (4 / 3 - m * np.cos(x1)**2 / (mc + m))) u = (-f + us) / g return np.array([x2, f + g * u + Delta])
def system(t, x): # Controller parameters r1, r2, q = 0.5, 2, 0.4 # Disturbance Delta = np.sin(2 * np.pi * 5 * t) # State variables x1, x2 = x[0], x[1] # Sliding variable s = x2 - v(x1, q, r1) sd = x2 + sol.odd_pow(sol.odd_pow(x2,2) - 2 * sol.odd_pow(v(x1, q, r1), 2), 0.5) # Controller u = v(sd, q, r1) - r2 * np.sign(sd) - s + 2 * vdv(x1, q, r1) * np.sign(sd) return np.array([x2, u+Delta])
def system(t, x): # Controller parameters a1, a2, b1, b2 = 128, 64, 128, 64 k = 1.1 # Disturbance Delta = np.sin(2 * np.pi * 5 * t) # State variables x1, x2 = x[0], x[1] # Sliding variable s = x2 + sol.odd_pow( sol.odd_pow(x2, 2) + a1 * x1 + b1 * sol.odd_pow(x1, 3), 0.5) # Controller u = -(a1 + 3 * b1 * x1**2 + 2 * k) / 2 * np.sign(s) - sol.odd_pow( a2 * s + b2 * sol.odd_pow(s, 3), 0.5) return np.array([x2, u + Delta])
def phi2(x1, x2, r1, r2, r7): r11, r21, r31, r41, r51, r61 = r1 mr51 = (1-r41*r51)/(r61-r51) mr61 = (r41*r61-1)/(r61-r51) g1 = beta(mr51, mr61)/(r21**(mr61)*r31**(mr51)*(r61-r51)) r12, r22, r32, r42, r52, r62 = r2 mr52 = (1-r42*r52)/(r62-r52) mr62 = (r42*r62-1)/(r62-r52) g2 = beta(mr52, mr62)/(r22**(mr62)*r32**(mr52)*(r62-r52)) xi = r21*odd_pow(x1, r51)+r31*odd_pow(x1, r61) s = x2 + odd_pow(odd_pow(x2, 2)+odd_pow(xi, 2*r41), 1/2) return -((g2/r12)*(r22*np.abs(s)**r52+r32*np.abs(s)**r62)**r42+r7)*np.sign(s)-(2*g1**2*r41/(r11**2))*(r21*r51+r31*r61*np.abs(x1)**(r61-r51))*(r21+r31*np.abs(x1)**(r61-r51))*np.abs(x1)**(2*r41*r51-1)*np.sign(s)
def system(t, x): import solver as sol import numpy as np Delta = np.sin(2 * np.pi * t / 5) q, Tc, zeta = 0.3, 1, 1 a = 1 return predefined4(x, q, a, Tc) - zeta * sol.odd_pow(x, 0) + Delta
def invdW4(x, q, a): return gamma(a) / (q) * np.exp(np.abs(x)**q) * sol.odd_pow(x, 1 - a * q)
def invdW3(x, q, a): return 1 / (a * q) * (np.abs(x)**q + a)**2 * sol.odd_pow(x, 1 - q)
def invdW2(x, q): return np.pi / (2 * q) * (sol.odd_pow(x, 1 + q) + sol.odd_pow(x, 1 - q))
def invdW1(x, q): return 1 / q * np.exp(np.abs(x)**q) * sol.odd_pow(x, 1 - q)
x1, x2 = x # Reference r = np.sin(0.5 * np.pi * t) dr = 0.5 * np.pi * np.cos(0.5 * np.pi * t) d2r = -(0.5 * np.pi)**2 * r # Error variables e1, e2 = x1 - r, x2 - dr # Controller # System parameters g, mc, m, l = 9.8, 1, 0.1, 0.5 # Controller parameters r1, r2, r3 = 0.91, 0.09, 2 q1, q2, a1, a2 = 0.5, 0.5, 1, 1.1 i = 4 s = e2 + sol.odd_pow( sol.odd_pow(e2, 2) + 2 / (r1**2) * sol.odd_pow(invdW(i, e1, q1, a1), 2), 0.5) us = -1 / r2 * invdW(i, s, q2, a2) - r3 * np.sign(invdW(i, s, q2, a2)) - 2 / ( r1**2) * proddW(i, e1, q1, a1) * np.sign(invdW(i, s, q2, a2)) f = (g * np.sin(x1) - m * l * x2**2 * np.cos(x1) * np.sin(x1) / (mc + m)) / (l * (4 / 3 - m * np.cos(x1)**2 / (mc + m))) - d2r g = (np.cos(x1) / (mc + m)) / (l * (4 / 3 - m * np.cos(x1)**2 / (mc + m))) u = (-f + us) / g ## Trajectories #plt.figure(num=1) #plt.plot(t, r, color=0.5*np.ones(3), lw=3, label='$r(t)$') #plt.plot(t, dr, color=0.7*np.ones(3), lw=3, label='$\dot{r}(t)$') #plt.plot(t, x1, '--', color=0*np.ones(3), lw=2, label='$x_1(t)$') #plt.plot(t, x2, '--', color=0.3*np.ones(3), lw=2, label='$x_2(t)$') #plt.ylim(-2,5)
x1, x2 = x # Plot of the trajectories ax1.plot(t, x1, color=0 * np.ones(3), lw=2, label='$x_1(t)$') ax1.plot(t, x2, '--', color=0.5 * np.ones(3), lw=2, label='$x_2(t)$') ax1.set_xlim(0, 1.2) ax1.set_ylim(-5, 5) ax1.set_xlabel('$t$', fontsize=14) ax1.axvline(x=1, ymin=-1, ymax=2, linestyle='dashed', color=0.6 * np.ones(3)) ax1.legend(loc='best') ax1.grid() # Controller parameters a1, a2, b1, b2 = 128, 64, 128, 64 k = 1.1 # Sliding variable s = x2 + sol.odd_pow( sol.odd_pow(x2, 2) + a1 * x1 + b1 * sol.odd_pow(x1, 3), 0.5) # Controller u = -(a1 + 3 * b1 * x1**2 + 2 * k) / 2 * np.sign(s) - sol.odd_pow( a2 * s + b2 * sol.odd_pow(s, 3), 0.5) # Plot of the control ax2.plot(t, u, color=0 * np.ones(3), lw=2) ax2.set_xlim(0, 1.2) ax2.set_ylim(-100, 100) ax2.set_xlabel('$t$', fontsize=14) ax2.grid() fig.savefig('figures/poly_controller.eps', bbox_inches='tight', format='eps', dpi=1500)
# Simulation t, x = sol.ode1(system, np.array([1000, 0]), t0, tf, h) # States x1, x2 = x # Plot of the trajectories ax1.plot(t, x1, color=0*np.ones(3), lw=2, label='$x_1(t)$') ax1.plot(t, x2, '--', color=0.5*np.ones(3), lw=2, label='$x_2(t)$') ax1.set_xlim(0, 1.2) ax1.set_ylim(-5, 5) ax1.set_xlabel('$t$', fontsize = 14) ax1.axvline(x = 1, ymin = -1, ymax = 2, linestyle='dashed', color = 0.6*np.ones(3)) ax1.legend(loc='best') ax1.grid() # Controller parameters r1, r2, q = 0.5, 2, 0.4 # Sliding variable s = x2 - v(x1, q, r1) sd = x2 + sol.odd_pow(sol.odd_pow(x2,2) - 2 * sol.odd_pow(v(x1, q, r1), 2), 0.5) # Controller u = v(sd, q, r1) - r2 * np.sign(sd) - s + 2 * vdv(x1, q, r1) * np.sign(sd) # Plot of the control ax2.plot(t, u, color=0*np.ones(3), lw=2) ax2.set_xlim(0, 1.2) ax2.set_ylim(-100, 100) ax2.set_xlabel('$t$', fontsize = 14) ax2.grid() fig.savefig('figures/my_controller.eps', bbox_inches='tight', format='eps', dpi=1500)
def predefined4(x, q, a, Tc): from scipy.special import gamma return -gamma(a) / (q * Tc) * np.exp(np.abs(x)**q) * sol.odd_pow( x, 1 - a * q)
def predefined3(x, q, a, Tc): return -1 / (a * q * Tc) * (np.abs(x)**q + a)**2 * sol.odd_pow(x, 1 - q)
def predefined2(x, q, Tc): return -np.pi / (2 * q * Tc) * (sol.odd_pow(x, 1 + q) + sol.odd_pow(x, 1 - q))
def predefined1(x, q, Tc): return -1 / (q * Tc) * np.exp(np.abs(x)**q) * sol.odd_pow(x, 1 - q)