How to plot two moving robot in the same figure and change one of them transparency?

조회 수: 13 (최근 30일)
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
And i try to use the task and joint space trajectory example to implement the result
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

채택된 답변

Karsh Tharyani
Karsh Tharyani 2022년 10월 4일
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
  댓글 수: 1
snow John
snow John 2022년 10월 5일
Hi Karsh,
Thanks very much for your kindness help ,The source code are really help a lot. I do want to implement these kind of result,this kinds of visualization is very attractive for representation use.
Thanks agian
Best ,
-Jian

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Robotics에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by