more then one tag on object in figure

10 views (last 30 days)
slowlearner
slowlearner on 26 Oct 2020
Edited: slowlearner on 27 Oct 2020
I have a problem whith a line of code in which i have 3 robots with each a seperate tool. Each tool has the tag tool1-3 depending on the robot now the tool is drawn with the line command inside a loop where it extracts vectorised x,y,z values from a struct. The loop is within another loop inside a switch case for each robot.
my initial thought was to maby declare more than one tag to the obj with the use of j for allocating the same line obj ones it's suppoed to redraw it.
code in which the problem stems is this one:
for j = 1: size(td,2) %the td = rd.xyz a
% V 4x4 matrix is the hand position of the robot in the x,y,z plane V(1:3,1:3) = rotation
% V(1:3,4) = translation
p = V(1:3,4); % This is for the starting position of the line
V(1:3,4) = V(1:3,4)+td(1:3,j); % P is the handposition rd.xyz from the TCP!
q = V(1:3,4); % this is the end position of the line from vector in td(:,j)
x = [p(1) q(1)];
y = [p(2) q(2)];
z = [p(3) q(3)];
if isempty(findobj('tag',['tool3',num2str(j)]))
h = line(x,y,z);
set(h,'tag',['tool3',num2str(j)],...
'color','k',...
'linewidth',3)
else
set(findobj('tag',['tool3',num2str(j)],...
'linewidth',3,...
'color','k',...
'xdata',x,...
'ydata',y,...
'zdata',z)
end
end
what i get is a figure that prints multiple tool lines as the robot moves and i need someway to redraw those away for the updated position of the tool.
the thing i'm getting at the moment looks like this:
I might be going at this all wrong and maby whould collect the vectors in seperate x(j) and y(j), z(j) arrays and ones those have been gathered draw the new line with or something.

Answers (2)

Walter Roberson
Walter Roberson on 26 Oct 2020
No. The Tag field of an object must be a character vector or a scalar string. The only way to store multiple tags would be to encode them all into a single character vector. But then you cannot findobj() on them as there is no way to ask to process the content of the tags.
You should instead use addprop() to add properties to the objects, in which case you can find them with findobj -property
if ~hasprop(h, 'tool3'); addprop(h, 'tool3'); end
findobj(groot,'-property', 'tool3')
  1 Comment
slowlearner
slowlearner on 26 Oct 2020
ok might try however, atm the object moves with the frame by frame calculations but it wont rotate with the robot end link it's just stuck in a certain position so i'll have to take a look at the thing again.

Sign in to comment.


slowlearner
slowlearner on 26 Oct 2020
wrongh declaration in the 'tag' supposed to be an array ['string','string' ]
  1 Comment
Walter Roberson
Walter Roberson on 26 Oct 2020
That would create a tag property such as 'tool3tool7' . You would not be able to use findobj() to search for tool3 or tool7 and find those objects.

Sign in to comment.

Categories

Find more on Specifying Target for Graphics Output in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!