clc clear all %constant epsilon = 0.05; zeta2 = 0.05; alpha = 0.01; neta2 = 2; rho0 =…
- User
clc clear all %constant epsilon = 0.05; zeta2 = 0.05; alpha = 0.01; neta2 = 2; rho0 = 0.5; %constraint m2 = 0; l1 = 0; l2 = 1.5; %initial q1s = 0; q2s = 0.9; %final q1f = 120*(pi/180); q2f = 1.3; x0 = 0; y0 = 0; %obsctle b = [0.75;-0.0];
q1(1) = q1s; q2(1) = q2s; o2f = [q2fsin(q1f); - q2fcos(q1f)]; i = 1;
while norm([q1(i) ; q2(i)] - [q1f ; q2f]) > epsilon th1 = q1(i); d2 = q2(i); o2 = [d2sin(th1) ; -d2cos(th1)]; %force_due_repulsive fatt_2 = -zeta2*(o2 - o2f); % Obstacle avoide if norm(o2 - b) <= rho0 frep2 = neta2*((1/norm(o2 - b)) - (1/rho0))((1/norm(o2 - b))^2)((o2 - b)/norm(o2 - b)); else frep2 = 0; end %net force Jo2 = [d2cos(th1), sin(th1) ; d2sin(th1), -cos(th1)]; tau = transpose(Jo2)fatt_2 + transpose(Jo2)frep2; %angles and distance q1(i+1) = q1(i) + alpha(tau(1,1)/norm(tau)); q2(i+1) = q2(i) + alpha(tau(2,1)/norm(tau));
if q2(i+1)>l2 q2(i+1) = l2; elseif q2(i+1)<= 0 q2(i+1) = 0.01; else q2(i+1) = q2(i+1); end x = d2*sin(th1); y = -d2*cos(th1); xe = (d2-l2)*sin(th1); ye = -(d2-l2)*cos(th1); ax(i) = x; ay(i) = y;%animating sec. figure(1) plot([x0 x], [y0 y], [x0 xe], [y0 ye], ax, ay, b(1,1), b(2,1), ".",'MarkerSize',30) %plot([x0 x], [y0 y], [x0 xe], [y0 ye], ax, ay, ".",'MarkerSize',5) grid on axis equal axis([-1.5 1.5 -1.5 1.5])
frep_2_plot(i) = norm(frep2); fatt_2_plot(i) = norm(fatt_2); tau1_plot(i) = tau(1,1); tau2_plot(i) = tau(2,1); i_plot(i) = i; pause(0.01) i = i+1;end figure(2) plot(i_plot, frep_2_plot ) title("Repulsive Force ")
figure(3) plot(i_plot, fatt_2_plot ) title("Attractive Force")
figure(4) plot(i_plot, tau1_plot ) title("Tau 1") figure(5) plot(i_plot, tau2_plot) title("Tau 2")
- Assistant