Advertisement
Teo_Protoulis

Untitled

Nov 19th, 2020
989
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 3.63 KB | None | 0 0
  1. function d_theta = ode_simulation_kuka(t,theta)
  2.  
  3.     %disp(t)
  4.  
  5.     global l_1 l_2 k1 k2 p_i p_1_0 p_2_0 gamma_1 gamma_2 K step_size_angle step_size_velocity
  6.     global q_prev_theta_1 q_prev_theta_2 q_prev_theta_3 q_prev_theta_4
  7.     global k_1 k_2 % Joints Friction Coeefficients
  8.     global I_1 I_2 m_1 m_2 l1 l2 g
  9.    
  10.     % Matrices Computations
  11.     M_11 = I_1 + I_2 + m_1*((l1^2)/4) + m_2*((l1^2) + ((l2^2)/4) + l1*l2*cos(theta(3)));
  12.     M_12 = I_2 + m_2*(((l2^2)/4) + (l1*l2*cos(theta(3)))/2);
  13.     M_21 = M_12;
  14.     M_22 = I_2 + m_2*((l2^2)/4);
  15.     M = [M_11 M_12 ; M_21 M_22];
  16.     c = (m_2*l1*l2*sin(theta(3)))/2;
  17.     C = [-c*theta(4) -c*(theta(2,:)+theta(4)) ; ...
  18.         c*theta(2) 0];
  19.     G = [((m_1*g*l1*cos(theta(1)))/2)+(m_2*g*(l1*cos(theta(1))+(l2*cos(theta(1)+theta(3)))/2)) ; ...
  20.         (m_2*g*l2*cos(theta(1)+theta(3)))/2];
  21.    
  22.     % Quantize Measurements
  23.     if t ~= 0
  24.         q_theta_1 = uniform_hysteretic_quantizer(theta(1), q_prev_theta_1, step_size_angle/2);
  25.         q_theta_2 = uniform_hysteretic_quantizer(theta(2), q_prev_theta_2, step_size_velocity/2);
  26.         q_theta_3 = uniform_hysteretic_quantizer(theta(3), q_prev_theta_3, step_size_angle/2);
  27.         q_theta_4 = uniform_hysteretic_quantizer(theta(4), q_prev_theta_4, step_size_velocity/2);    
  28.         q_theta = [q_theta_1 q_theta_2 q_theta_3 q_theta_4];
  29.     else
  30.         q_theta_1 = q_prev_theta_1;
  31.         q_theta_2 = q_prev_theta_2;
  32.         q_theta_3 = q_prev_theta_3;
  33.         q_theta_4 = q_prev_theta_4;
  34.         q_theta = [q_theta_1 q_theta_2 q_theta_3 q_theta_4];
  35.     end
  36.     q_prev_theta_1 = q_theta_1;
  37.     q_prev_theta_2 = q_theta_2;
  38.     q_prev_theta_3 = q_theta_3;
  39.     q_prev_theta_4 = q_theta_4;
  40.    
  41.     % Desired Angle Trajectories
  42.     if t <= 6
  43.  
  44.         theta_d_1 = 0.01454441*t^3 - 0.0036361*t^4 + 0.00024241*t^5;
  45.         theta_dot_d_1 = 3*0.01454441*t^2 - 4*0.0036361*t^3 + 5*0.00024241*t^4;
  46.         %theta_d_1 = 0.5*sin(0.3*pi*t);
  47.         %theta_dot_d_1 = 0.5*0.3*pi*cos(0.3*pi*t);
  48.        
  49.         theta_d_2 = 0.01454441*t^3 - 0.0036361*t^4 + 0.00024241*t^5;
  50.         theta_dot_d_2 = 3*0.01454441*t^2 - 4*0.0036361*t^3 + 5*0.00024241*t^4;
  51.         %theta_d_2 = 0.5*cos(0.3*pi*t);
  52.         %theta_dot_d_2 = -0.5*0.3*pi*sin(0.3*pi*t);
  53.        
  54.     else
  55.         theta_d_1 = pi/10;
  56.         theta_dot_d_1 = 0;
  57.        
  58.         theta_d_2 = pi/10;
  59.         theta_dot_d_2 = 0;
  60.  
  61.     end
  62.  
  63.     % Disturbance Signals
  64.     d_1 = 0.25*sin(t);
  65.     d_2 = 0.75*cos(t);
  66.    
  67.     % Performance Functions --> Define the envelope in which the output
  68.     % (tracking) error resides
  69.     p_1 = p_1_0*exp(-l_1*t)+k1*p_i;
  70.     p_2 = p_2_0*exp(-l_2*t)+k2*p_i;
  71.    
  72.     % Construct Essential Signal for the final Control Signal
  73.     delta_1 = k1*step_size_velocity+k1*step_size_angle;
  74.     delta_2 = k2*step_size_velocity+k2*step_size_angle;
  75.    
  76.     e_q_1 = q_theta(1)-theta_d_1;
  77.     dot_e_q_1 = q_theta(2)-theta_dot_d_1;
  78.     s_1_q = (dot_e_q_1+k1*e_q_1)/(p_1-delta_1);
  79.     T_dot_s_q_1 = -(2/((s_1_q^2)-1));
  80.    
  81.     e_q_2 = q_theta(3)-theta_d_2;
  82.     dot_e_q_2 = q_theta(4)-theta_dot_d_2;
  83.     s_2_q = (dot_e_q_2+k2*e_q_2)/(p_2-delta_2);
  84.     T_dot_s_q_2 = -(2/((s_2_q^2)-1));
  85.        
  86.     u_1 = (K*gamma_1*(p_1-delta_1)*s_1_q)/(T_dot_s_q_1*(gamma_1*(s_1_q^2)+gamma_2*(s_2_q^2)-1));
  87.     u_2 = (K*gamma_2*(p_2-delta_2)*s_2_q)/(T_dot_s_q_2*(gamma_1*(s_1_q^2)+gamma_2*(s_2_q^2)-1));
  88.     u = [u_1 ; u_2];
  89.    
  90.     inv_M = inv(M);
  91.    
  92.     d_theta =[ theta(2) ; ...
  93.         -inv_M(1,:)*C*[theta(2) ; theta(4)]-inv_M(1,:)*G+inv_M(1,:)*u+d_1 ;  ...
  94.         theta(4) ; ...
  95.         -inv_M(2,:)*C*[theta(2) ; theta(4)]-inv_M(2,:)*G+inv_M(2,:)*u+d_2 ...
  96.         ];
  97.  
  98. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement