フィルターのクリア

Animate 3D figure imported from stl

15 ビュー (過去 30 日間)
TheIOzikI
TheIOzikI 2024 年 1 月 20 日
回答済み: Aman 2024 年 2 月 5 日
Hi,
I need to modify some code to work for my project.
I can't get the animation to work correctly. it looks like that.
robot looks like that
here is whole folder
I can't upload it direcly because of limit.
There's start.m file with correct order
%%%MAKE FIGURE WITH OBJECT (ROBOT ARM)
% Rysuj czlony
P2=C2.Vertices';
P3=C3.Vertices';
% ustawianie czlonow
P2=F12(0)*[P2; ones(1, size(P2, 2))];
%
C2R=C2;
%
C2R.Vertices=P2(1:3,1:size(P2, 2))';
%
P3=F12(0)*F23(0)*[P3;ones(1,size(P3, 2))];
%
C3R=C3;
C3R.Vertices=P3(1:3,1:size(P3, 2))';
%% rysowanie
figure(1);
axis equal;
grid on;
hold on;
czlon11=trisurf(C11.Vertices-1, C11.Faces(:,1), C11.Faces(:,2), C11.Faces(:,3), 'FaceColor',C11.FaceColor, 'EdgeColor','none');
lightangle(-45, 25);
lighting('flat');
czlon12=trisurf(C12.Vertices-1, C12.Faces(:,1), C12.Faces(:,2), C12.Faces(:,3), 'FaceColor',C12.FaceColor, 'EdgeColor','none');
lightangle(-45, 25);
lighting('flat');
czlon2=trisurf(C2.Vertices-1, C2.Faces(:,1), C2.Faces(:,2), C2.Faces(:,3), 'FaceColor',C2.FaceColor, 'EdgeColor','none');
lightangle(45, 65);
lighting('flat');
czlon3=trisurf(C3.Vertices-1, C3.Faces(:,1), C3.Faces(:,2), C3.Faces(:,3), 'FaceColor',C3.FaceColor, 'EdgeColor','none');
lightangle(45, 65);
lighting('flat');
clear P2 P3 C2R C3R;
fi1=[0:1:180, 180:-1:0];
fi2=[0:0.5:90, 90:-0.5:0];
fi3=[0:-0.5:-90, -90:0.5:0];
%%%%%%%%%%%Generate movie
% parametry
lbpow=2;
%przeliczenie fi na radjany
Fi1=fi1*pi/180;
Fi2=fi2*pi/180;
Fi3=fi3*pi/180;
[m,n]=size(fi1);
%pozycja zerowa
P11=C11.Vertices';
P12=C12.Vertices';
P2=C2.Vertices';
P3=C3.Vertices';
%%
% transformacja
for i=1:n
aP11=F01(Fi1(i))*[P11;ones(1,size(P11, 2))];
aP12=F01(Fi1(i))*[P12;ones(1,size(P12, 2))];
aP2=F01(Fi1(i))*F12(Fi2(i))*[P2;ones(1,size(P2, 2))];
aP3=F01(Fi1(i))*F12(Fi2(i))*F23(Fi3(i))*[P3;ones(1,size(P3, 2))];
% przesunięcie
set(czlon11,'Vertices',aP11(1:3,1:size(aP11, 2))');
set(czlon12,'Vertices',aP12(1:3,1:size(aP12, 2))');
set(czlon2,'Vertices',aP2(1:3,1:size(aP2, 2))');
set(czlon3,'Vertices',aP3(1:3,1:size(aP3, 2))');
film(i)=getframe;
end
%%
movie(film,lbpow)
clear P11 P12 P2 P3 Fi1 Fi2 Fi3
  6 件のコメント
Star Strider
Star Strider 2024 年 1 月 21 日
So just to clarify, whoever has the skills to do the animation needs to use those files (that I assume are in the offsite location) rather than writing new code? (Animating robots is far outside my areas of expertise.)
TheIOzikI
TheIOzikI 2024 年 1 月 21 日
I need to have the c1 c21 c22 files for future purposes. I can modify some of the code. This is basic movement of arm left right and up down with sliding rack. It should work but there're some artifacts on that figure that shouldn't be there. Meaby Matlab can't process that big matrix? I don't know. If it was on me I would have done this in simulink via solidworks.

サインインしてコメントする。

回答 (1 件)

Aman
Aman 2024 年 2 月 5 日
Hi Thel,
As per my understanding, you are trying to simulate a scenario for bot arm movement but are facing issues while creating animation for the same.
The issue that you are facing is due to the transformation that you are trying to do by the following piece of code, which is not transforming the vertices correctly, due to which you are seeing such an absurd figure.
% transformacja
for i=1:n
aP1=F01(d1(i))*[P1;ones(1,size(P1, 2))];
aP21=F01(d1(i))*F12(Fi2(i))*[P21;ones(1,size(P21, 2))];
aP22=F01(d1(i))*F12(Fi2(i))*[P22;ones(1,size(P22, 2))];
aP3=F01(d1(i))*F12(Fi2(i))*F23(Fi3(i))*[P3;ones(1,size(P3, 2))];
aP4=F01(d1(i))*F12(Fi2(i))*F23(Fi3(i))*F34(Fi4(i))*[P4;ones(1,size(P4, 2))];
% przesunięcie
set(czlon1,'Vertices',aP1(1:3,1:size(aP1, 2))');
set(czlon21,'Vertices',aP21(1:3,1:size(aP21, 2))');
set(czlon22,'Vertices',aP22(1:3,1:size(aP22, 2))');
set(czlon3,'Vertices',aP3(1:3,1:size(aP3, 2))');
set(czlon4,'Vertices',aP4(1:3,1:size(aP4, 2))');
film(i)=getframe;
end
A better approach for doing the same would be to use the "applyTranform" method, which applies forward transformation to the mesh, and once you have transformed vertices with you, you can call the "show" method in a loop to display the animation. Please refer to the following documentation, where the animation has been achieved using the described approach.
You can use the below matrices for rotation along the x, y, and z axes, respectively.
Rx = [1 0 0 0;
0 cos(theta_rad) -sin(theta_rad) 0;
0 sin(theta_rad) cos(theta_rad) 0;
0 0 0 1];
Ry = [cos(theta_rad) 0 sin(theta_rad) 0;
0 1 0 0;
-sin(theta_rad) 0 cos(theta_rad) 0;
0 0 0 1];
Rz = [cos(theta_rad) -sin(theta_rad) 0 0;
sin(theta_rad) cos(theta_rad) 0 0;
0 0 1 0;
0 0 0 1];
Hope it helps!

カテゴリ

Help Center および File ExchangeSimulation についてさらに検索

製品


リリース

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by