How to fix Error using atan2 Inputs must be real?

4 views (last 30 days)
Function
function ConcLin = Line(A,B)
%% Linear Moving along desired path
% **** Linear First Movement ***
% Calling Inverse Kinematics to
%% number of increments
ResLin = 100;
%% Equations
DeltaX = (B(1,1) - A(1,1)) / ResLin;
DeltaY = (B(1,2) - A(1,2)) / ResLin;
DeltaZ = (B(1,3) - A(1,3)) / ResLin;
%% Looping through each point of the line
tic;
AnglesLin = zeros(6); %preallocating memory
for f = 1:ResLin
%% calculating actual point
A(1,1) = A(1,1) + DeltaX * f;
A(1,2) = A(1,2) + DeltaY * f;
A(1,3) = A(1,3) + DeltaZ * f;
AnglesLin(f,:) = IKine(A);
end
toc
%% Increments of Time
tic;
TimeLin = zeros(1); %preallocating memory
for clockLin = 1:ResLin
TickTockLin = clockLin*0.1+10;
TimeLin(clockLin,:) = TickTockLin;
end
toc
%% Concatenating Time & Angles. Time will be the first column
ConcLin = [TimeLin,AnglesLin];
Main
%% Coordinates Input
% LINE desired Paths. If Input method is used, comment out this block of code.
% *****We will define these as one matrix 1x12*****
Lin1 = [750, -75, 670, 0, 0, 1, 0, -1, 0, 1, 0, 0];%A
% Xa = Lin1(1,1); Ya = Lin1(1,2); Za = Lin1(1,3);
Lin2 = [750, -75, 550, 0, 0, 1, 0, -1, 0, 1, 0, 0];%B
% Xb = Lin2(1,1); Yb = Lin2(1,2); Zb = Lin2(1,3);
Lin3 = [750, 75, 550, 0, 0, 1, 0, -1, 0, 1, 0, 0];
Lin4 = [750, 75, 670, 0, 0, 1, 0, -1, 0, 1, 0, 0];
Lin5 = [750, 0, 700, 0, 0, 1, 0, -1, 0, 1, 0, 0];
Lin6 = [750, 0, 550, 0, 0, 1 0, -1, 0, 1, 0, 0];
%% Calling Linear Motion
ConcLin = Line(Lin1, Lin2);
  5 Comments
Steven Lord
Steven Lord on 26 Jan 2022
You're assuming d3/p1 is strictly less than or equal to 1. What guarantee do you have that this is the case?
If it was ever so slightly greater than 1:
d3 = 2;
p1 = 2 - eps(2); % Just barely less than 2
s = (d3/p1)
s = 1.0000
s > 1 % true
ans = logical
1
sqrt(1-s^2) % complex
ans = 0.0000e+00 + 2.1073e-08i
You can use min and max to ensure s is strictly in a desired range.
Konard Adams
Konard Adams on 27 Jan 2022
Thank you. Here is the solution.:
When we move from previous point to next point, the coordinate equals to the previous coordinate plus the Delta, so we don't need to multiply f.
Before:
for f = 1:ResLin
%% calculating actual point
A(1,1) = A(1,1) + DeltaX * f;
A(1,2) = A(1,2) + DeltaY * f;
A(1,3) = A(1,3) + DeltaZ * f;
AnglesLin(f,:) = IKine(A);
Correct:
for f = 1:ResLin
%% calculating actual point
A(1,1) = A(1,1) + DeltaX;
A(1,2) = A(1,2) + DeltaY;
A(1,3) = A(1,3) + DeltaZ;
AnglesLin(f,:) = IKine(A);

Sign in to comment.

Accepted Answer

Konard Adams
Konard Adams on 27 Jan 2022
When we move from previous point to next point, the coordinate equals to the previous coordinate plus the Delta, so we don't need to multiply f.
Before:
for f = 1:ResLin
%% calculating actual point
A(1,1) = A(1,1) + DeltaX * f;
A(1,2) = A(1,2) + DeltaY * f;
A(1,3) = A(1,3) + DeltaZ * f;
AnglesLin(f,:) = IKine(A);
Correct:
for f = 1:ResLin
%% calculating actual point
A(1,1) = A(1,1) + DeltaX;
A(1,2) = A(1,2) + DeltaY;
A(1,3) = A(1,3) + DeltaZ;
AnglesLin(f,:) = IKine(A);
Now it works. @Torsten @Steven Lord Thanks for helping. I learn a lot from these discussions. Cheers!

More Answers (0)

Products


Release

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!