diff --git a/DrawObstacles.m b/DrawObstacles.m index b1ec829..c764d34 100644 --- a/DrawObstacles.m +++ b/DrawObstacles.m @@ -27,11 +27,15 @@ function DrawObstacles() x = -(L1+L2) + rand()*2*(L1+L2); %creating random x and y values y = -(L1+L2) + rand()*2*(L1+L2); if((y >= L1)|| (y<=-L1) || (x>=-L2 && x<=L2 && y>=-L2 && y<=L2)) % keeping them if they are inside the obstacles - [q1 q2 q1_ q2_] = MyIK(L1, L2, x, y); % computing their corresponding q1 q2 coordinates - % saving the computed coordinates - q1_plot = [q1_plot q1 q1_]; - - q2_plot = [q2_plot q2 q2_]; + [nbSol, qi] = solveIK2LinkPlanarRobot(L1, L2, x, y);% computing their corresponding q1 q2 coordinates + for j=1:nbSol + % saving the computed coordinates + q1 = qi(j,1); + q2 = qi(j,2); + q1_plot = [q1_plot q1]; + + q2_plot = [q2_plot q2]; + endfor x_plot = [x_plot x]; y_plot = [y_plot y]; diff --git a/MyFK.m b/MyFK.m index 8a7baf2..ac7fd41 100644 --- a/MyFK.m +++ b/MyFK.m @@ -5,7 +5,7 @@ function [x, y] = MyFK(L1, L2, Q1, Q2) % Task: returns the x y coordinates in the cartesian space % from a given point in the q1 q2 joint space % using geometry rules since we know that we have two links only of length L1 and L2 -% +% computation way faster than the method with matrices % % Inputs: %-L1: length of the first link of the 2d planar 2 link robot arm diff --git a/MyIK.m b/MyIK.m deleted file mode 100644 index 224a2ea..0000000 --- a/MyIK.m +++ /dev/null @@ -1,32 +0,0 @@ -function [q1 q2 q1_ q2_] = MyIK(L1, L2, x, y) -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%function [q1 q2 q1_ q2_] = MyIK(L1, L2, x, y) -% -% Task: returns the two possible solutions of q1 q2 coordinate in the joint space -% from a given point in the x y cartesian space -% using geometry rules since we know that we have two links only of length L1 and L2 -% -% -% Inputs: -%-L1: length of the first link of the 2d planar 2 link robot arm -%-L2: length of the second link of the 2d planar 2 link robot arm -%-x: x coordinate of the given point -%-y: x coordinate of the given point -% -% Outputs: -%-q1: q1 coordinate of the given point (first solution) -%-q2: q2 coordinate of the given point (first solution) -%-q1_: q1 coordinate of the given point (second solution) -%-q2_: q2 coordinate of the given point (second solution) -% -% -% Thomas OLIVE (thomas.olive@ecam.fr) -% 18/12/2021 -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - - q1 = acosd(x/sqrt(x^2+y^2)) - acosd( (-L2^2+x^2+y^2+L1^2) / (2*L1*sqrt(x^2+y^2))); - q2 = 180 - acosd( (L1^2+L2^2-(x^2+y^2)) / (2*L1*L2)); - - q1_ = q1 + 2*acosd( (-L2^2+x^2+y^2+L1^2) / (2*L1*sqrt(x^2+y^2))); - q2_ = -q2; -endfunction \ No newline at end of file