How to plot two moving robot in the same figure and change one of them transparency?
10 views (last 30 days)
Show older comments
Hello guys ,i want plot two moving robot in the the figure and change on of them transparency.
but i don't know how to change just on of them transparency use the code
alpha(robot,0.2) %change robot transparency
and i just want to implement the effect like below

The code are below for the purpose change
axis([-.8 .8 -.8 .8 0 1.2]);
view(135,15)
for i=1:length(trajTimes)
% Current time
tNow= trajTimes(i);
% Interpolate simulated joint positions to get configuration at current time
configNow = interp1(tJoint,stateJoint(:,1:numJoints),tNow);
configNow1 = interp1(tJoint,stateJoint(:,1:numJoints),tNow+1);
poseNow = getTransform(robot,configNow,endEffector);
show(robot,configNow1,'PreservePlot',false,'Frames','off');
hold on
show(robot,configNow,'PreservePlot',false,'Frames','off');
jointSpaceMarker = plot3(poseNow(1,4),poseNow(2,4),poseNow(3,4),'r.-','MarkerSize',2);
% alpha(robot,0.2)% here didn't works
alpha 0.2
drawnow limitrate ;
end
but only one moveing like below picture shows

Can someone help me
Best wishes,
-jian
0 Comments
Accepted Answer
Karsh Tharyani
on 4 Oct 2022
Hi Jian,
I hope this snippet helps.
% Create two instances of a rigid body tree since we want two visuals
rbt=loadrobot("kinovagen3",DataFormat="row");
copyrbt=copy(rbt);
% Some random configurations
q0=homeConfiguration(rbt);
q1=randomConfiguration(rbt);
q2=randomConfiguration(rbt);
% Generate a trajectory to the random configurations
tpts=[0,1];
tquery=tpts(1):0.01:tpts(end);
traj1=quinticpolytraj([q0',q1'],tpts,tquery)';
traj2=quinticpolytraj([q0',q2'],tpts,tquery)';
% Find the patches which have a display name of '_mesh', and set their
% alpha values.
ax=show(rbt,traj1(1,:),PreservePlot=false,FastUpdate=true);
rbtpatches=findobj(ax.Children,'Type','patch','-regexp','DisplayName','_mesh');
set(rbtpatches,'FaceAlpha',0.2);
% Now visualize another instance of the same robot
hold on;
show(copyrbt,traj2(1,:),PreservePlot=false,FastUpdate=true,Parent=ax);
% This call will also find the previous patches. Hence we need to remove
% previously found patches from this query.
patchesnew=findobj(ax.Children,'Type','patch','-regexp','DisplayName','_mesh');
copyrbtpatches=patchesnew(~ismember(patchesnew,rbtpatches));
% You can also change the color aside from alpha
set(copyrbtpatches,'FaceAlpha',0.7);
set(copyrbtpatches,'FaceColor',[1,0,0]);
%% Visualize
rc=rateControl(50);
for i=1:size(tquery,2)
show(rbt,traj1(i,:),PreservePlot=false,FastUpdate=true);
show(copyrbt,traj2(i,:),PreservePlot=false,FastUpdate=true,Parent=ax);
waitfor(rc);
end
hold off;
Best,
Karsh
More Answers (0)
See Also
Categories
Find more on Robotics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!