clear all; close all; % Parameters xt = 0; yt = 0; v = 1.0; d = 1.0; z0 = 0; k1 = 1; k2…
- User
clear all; close all;
% Parameters xt = 0; yt = 0; v = 1.0; d = 1.0; z0 = 0; k1 = 1;
k2 = 2.5; % kb = 0.75; r_i = 0.75; r_o = 1.75;% ka = 1; kb = d-r_i; ka = r_o -d; %ka = 0.166; %kb = 1.56; %theta = pi/2; % Initial conditions: [x-position; y-position; heading angle; z] x0 = [1.05; 0.53; 45pi/180; z0]; %x0 = [1.49; 0.91; 25pi/180; z0]; %x0 = [1.45; 0.89; 45pi/180; z0]; % %x0 = [1.0; 0.75; 90.1pi/180; z0]; % x0 = [-1; 0.6; 240*pi/180; z0]; tspan = [0 50];
opts = odeset('RelTol',1e-5,'AbsTol',1e-7);
% Solve ODE f = @(t, x) dynamics_unknown(t, x, v, k1, d, k2, ka,kb); [t, x] = ode45(f, tspan, x0, opts); control_terms = arrayfun(@(i) calculate_control_term(x(i, :), x(i, 3), v, k1, d, [], ka, kb), 1:size(x, 1));
%% % Plot Trajectories and Results figure(1) %plot(x(:, 1), x(:, 2), 'b', xt, yt, 'ro', 'LineWidth', 1.2); plot(x(:, 1), x(:, 2), 'b', xt, yt,'r.', 'LineWidth', 1.2, 'MarkerSize', 15); hold on; plot(x(1, 1), x(1, 2), 'LineWidth', 2); %plot(x(1, 1), x(1, 2), 'rx', 'MarkerSize', 8, 'LineWidth', 2); % viscircles([xt yt], kb, 'Color', [1 0 0], 'LineWidth', 1); % viscircles([xt yt], ka+d, 'Color', [1 0 0], 'LineWidth', 1); viscircles([xt yt], r_i, 'Color', [1 0 0], 'LineWidth', 1.5); viscircles([xt yt], r_o, 'Color', [1 0 0], 'LineWidth', 1.5); %rectangle('Position', [xt-r_i, yt-r_i, 2r_i, 2r_i], 'Curvature', [1, 1], 'EdgeColor', [1 0 0], 'LineWidth', 1.5, 'LineStyle', '-'); %rectangle('Position', [xt-r_o, yt-r_o, 2r_o, 2r_o], 'Curvature', [1, 1], 'EdgeColor', [1 0 0], 'LineWidth', 1.5, 'LineStyle', '-');
% axis([-kb-0.3 kb+0.3 -kb-0.3 kb+0.3]);
% axis([-ka-0.3 ka+0.3 -ka-0.3 ka+0.3]);
xlabel('x (m)','Interpreter','latex','fontsize',16); ylabel('y (m)','Interpreter','latex','fontsize',16); legend('Robot', 'Target');
xtraj = x(:,1); ytraj = x(:,2); theta=x(:,3); % axes('position', [0.25 0.25 0.5 0.5]); % box on; % alpha = 0 < t & t < 300; % plot(xtraj(alpha), ytraj(alpha), 'b' , 'LineWidth', 2, 'MarkerSize', 5.5); % hold on; % plot(x(1, 1), x(1, 2), 'rx', 'MarkerSize', 8, 'LineWidth', 2); % viscircles([xt yt], ka, 'Color', [1 0 0], 'LineWidth', 1); % hold off; % axis([0.66 1.1 0.45 1.05]); % grid on; axis square axis equal axis([ -2.5 2.5 -2.5 2.5]) hold off;
%% figure(2); plot(t, control_terms, 'm', 'LineWidth', 1.2); hold on; xlabel('Time (sec)','Interpreter','latex','fontsize',16); ylabel('Control Term','Interpreter','latex','fontsize',16); % axis square % axis equal %axis([ -2.5 2.5 -2.5 2.5]) hold off; %title('Control Term vs Time'); %%
figure(3); plot(t, x(:, 3), 'g'); xlabel('Time (sec.)','Interpreter','latex','fontsize',15); ylabel('Heading Angle ()','Interpreter','latex','fontsize',15); %% const1 = 1.2 * ones(1, length(t)); figure; % Plot distance to the target over time r = sqrt((x(:, 1) - xt).^2 + (x(:, 2) - yt).^2);
- Assistant