Skip to content

Commit 7e212c1

Browse files
committed
SerialLink.double and Link.double
Link.double converts link parameters to numeric (double) type dl = l.double is a Link object in which all the parameters are numeric ('double') type. Useful when you are using Pi=sym('pi') to avoid round off errors (e.g in sin(Pi/2)), but later you want to pass the link object to a method (e.g. ikine) which only supports real numbers. Will give an error if a symbolic variable is not convertable to double number. See also SerialLink.double %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SerialLink.double converts SerialLink object parameters to numeric (double) type dr = r.double is a SerialLink object in which all the parameters are numeric ('double') type. Useful when you are using Pi=sym('pi') to avoid round off errors e.g in sin(Pi/2)), but later you want to pass the SerialLink object to a method (e.g. ikine) which only supports real numbers. Will give an error if a symbolic variable is not convertable to double number. See also Link.double Author: Amin Yahyaabadi ([email protected])
1 parent 9cfdfd8 commit 7e212c1

File tree

2 files changed

+65
-1
lines changed

2 files changed

+65
-1
lines changed

@SerialLink/SerialLink.m

+23-1
Original file line numberDiff line numberDiff line change
@@ -901,7 +901,29 @@ function dyn(r, j)
901901
sr.links(i) = r.links(i).sym;
902902
end
903903
end
904-
904+
905+
function dr = double(r)
906+
% SerialLink.double converts SerialLink object parameters to numeric (double) type
907+
%
908+
% dr = r.double is a SerialLink object in which all the parameters are
909+
% numeric ('double') type.
910+
%
911+
% Useful when you are using Pi=sym('pi') to avoid round off errors
912+
% e.g in sin(Pi/2)), but later you want to pass the SerialLink object to
913+
% a method (e.g. ikine) which only supports real numbers.
914+
%
915+
% Will give an error if a symbolic variable is not convertable to
916+
% double number.
917+
%
918+
% See also Link.double
919+
%
920+
% Author: Amin Yahyaabadi ([email protected])
921+
922+
dr = SerialLink(r);
923+
for i=1:r.n
924+
dr.links(i) = r.links(i).double;
925+
end
926+
end
905927

906928
function p = isprismatic(robot)
907929
%SerialLink.isprismatic identify prismatic joints

Link.m

+42
Original file line numberDiff line numberDiff line change
@@ -991,6 +991,48 @@ function dyn(links)
991991
l.B = sym(l.B);
992992
l.Tc = sym(l.Tc);
993993
end
994+
995+
function l = double(l)
996+
%Link.double converts link parameters to numeric (double) type
997+
%
998+
% dl = l.double is a Link object in which all the parameters are
999+
% numeric ('double') type.
1000+
%
1001+
% Useful when you are using Pi=sym('pi') to avoid round off errors
1002+
% (e.g in sin(Pi/2)), but later you want to pass the link object to
1003+
% a method (e.g. ikine) which only supports real numbers.
1004+
%
1005+
% Will give an error if a symbolic variable is not convertable to
1006+
% double number.
1007+
%
1008+
% See also SerialLink.double
1009+
%
1010+
% Author: Amin Yahyaabadi ([email protected])
1011+
1012+
if l.issym % we can disable the check, we should compare the speed.
1013+
1014+
if ~isempty(l.theta) % && isa(l.d,'sym') % we can check for sym class individually, speed should be compared.
1015+
l.d=double(l.d);
1016+
end
1017+
1018+
if ~isempty(l.theta)
1019+
l.theta=double(l.theta);
1020+
end
1021+
1022+
l.alpha=double(l.alpha);
1023+
l.a=double(l.a);
1024+
l.offset=double(l.offset);
1025+
1026+
l.offset=double(l.I);
1027+
l.offset=double(l.r);
1028+
l.offset=double(l.m);
1029+
1030+
l.Jm = double(l.Jm);
1031+
l.G = double(l.G);
1032+
l.B = double(l.B);
1033+
l.Tc = double(l.Tc);
1034+
end
1035+
end
9941036

9951037

9961038
end % methods

0 commit comments

Comments
 (0)