You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

95 lines
2.3 KiB

  1. %
  2. % Problem 2a: Nonlinear system roll model parameter estimation without disturbance
  3. %
  4. clear
  5. % True system parameters
  6. a1 = 2.0;
  7. a2 = 1.0;
  8. a3 = 0.5;
  9. b = 2.0;
  10. % Simulation setup
  11. Ts = 0.001;
  12. T_total = 30;
  13. t = 0:Ts:T_total;
  14. N = length(t);
  15. % Reference trajectory: step profile
  16. r_d = zeros(1, N);
  17. r_d(t >= 10 & t < 20) = pi/10;
  18. % Smooth bound phi(t)
  19. phi0 = 1.5;
  20. phi_inf = 0.05;
  21. lambda = 0.5;
  22. phi = (phi0 - phi_inf) * exp(-lambda * t) + phi_inf;
  23. % Control parameters
  24. k1 = 1.0;
  25. k2 = 1.0;
  26. rho = 1.0;
  27. % Initial conditions
  28. r = zeros(1, N);
  29. dr = zeros(1, N);
  30. ddr = zeros(1, N);
  31. % Parameter estimation setup
  32. theta_hat = zeros(4, N);
  33. theta_hat(:,1) = [1; 1; 1; 1];
  34. gamma = 0.66;
  35. % Output storage for control input and errors
  36. alpha = zeros(1, N);
  37. u = zeros(1, N);
  38. for k = 1:N-1
  39. % Compute normalized errors
  40. z1 = (r(k) - r_d(k)) / phi(k);
  41. z1 = max(min(z1, 0.999), -0.999);
  42. alpha(k) = -k1 * log((1 + z1) / (1 - z1));
  43. z2 = (dr(k) - alpha(k)) / rho;
  44. z2 = max(min(z2, 0.999), -0.999);
  45. u(k) = -k2 * log((1 + z2) / (1 - z2));
  46. % True system dynamics
  47. phi_true = [-dr(k); -sin(r(k)); dr(k)^2 * sin(2*r(k)); u(k)];
  48. ddr(k) = a1 * phi_true(1) + a2 * phi_true(2) + a3 * phi_true(3) + b * phi_true(4);
  49. % Integrate dynamics
  50. dr(k+1) = dr(k) + Ts * ddr(k);
  51. r(k+1) = r(k) + Ts * dr(k);
  52. % Estimation
  53. phi_est = phi_true; % same form
  54. y = ddr(k);
  55. y_hat = theta_hat(:,k)' * phi_est;
  56. e = y - y_hat;
  57. theta_hat(:,k+1) = theta_hat(:,k) + Ts * gamma * e * phi_est;
  58. end
  59. % Final estimates
  60. fprintf('\n2a: Final estimated parameters:\n');
  61. fprintf('a1: %.4f, a2: %.4f, a3: %.4f, b: %.4f\n', theta_hat(1,end), theta_hat(2,end), theta_hat(3,end), theta_hat(4,end));
  62. % Plot parameter estimates
  63. figure('Name', 'Problem 2a - Parameter Estimation', 'Position', [100, 100, 1280, 860]);
  64. sgtitle('Nonlinear Roll System - Parameter Estimation');
  65. subplot(2,1,1);
  66. plot(t, theta_hat', 'LineWidth', 1.4);
  67. legend('a_1', 'a_2', 'a_3', 'b');
  68. ylabel('\theta estimates'); grid on; title('Εκτιμήσεις παραμέτρων');
  69. subplot(2,1,2);
  70. plot(t, r, 'b', t, r_d, '--r', 'LineWidth', 1.4);
  71. legend('r(t)', 'r_d(t)');
  72. ylabel('Roll angle [rad]'); xlabel('Time [s]'); grid on; title('Παρακολούθηση τροχιάς');
  73. if ~exist('output', 'dir')
  74. mkdir('output');
  75. end
  76. saveas(gcf, 'output/Problem2a_estimation.png');