how to use "getframe" commander for making animation video.
Afficher commentaires plus anciens
hello everybody
i want to make animation video.
but something matter. i think "F(i2) = getframe;" is problem.
but i don't know how to correct.
please help me.
thank you in advance.
d = fopen('displacement.dat','w');
v= fopen('velocity.dat','w');
a=fopen('acceleration.dat','w');
length1 = input('Enter length of link1:');
length2 = input('Enter length of link2:');
n1=input('Enter the number of image:');
t=0.0;
t_step =0.01;
t_end = 1.0;
local_r1 = [length1,0]';
local_r2 = [length2,0]';
while(t<=t_end)
theta_1=t;
theta_2=3*t;
r_d1=trans1(local_r1,theta_1);
r_d2=trans1(local_r2,theta_2);
r_td=addition(r_d1,r_d2);
r_v1=trans_velocity(theta_1,3,local_r1);
r_v2=trans_velocity(theta_2,1,local_r2);
r_tv=addition(r_v1,r_v2);
r_a1=trans_acceleration(3,0,r_d1);
r_a2=trans_acceleration(1,0,r_d2);
r_ta=addition(r_a1,r_a2);
fprintf(d,'%7.5f %15.6e %15.6e',t,r_td(1),r_td(2));
fprintf(d,'%15.6e %15.6e',r_d1(1),r_d1(2));
fprintf(d,'%15.6e %15.6e\n',r_d2(1),r_d2(2));
fprintf(v,'%15.6e %15.6e\n',r_tv(1),r_tv(2));
fprintf(a,'%15.6e %15.6e\n',r_ta(1),r_ta(2));
t=t+t_step;
end
fclose(d);
fclose(v);
fclose(a);
load displacement.dat
load velocity.dat
load acceleration.dat
time=displacement(:,1);
x_p=displacement(:,2); y_p=displacement(:,3);
rd1_xp=displacement(:,4); rd1_yp=displacement(:,5);
rd2_xp=displacement(:,6); rd2_yp=displacement(:,7);
x_p_dot=velocity(:,1); y_p_dot=velocity(:,2);
x_p_ddot=acceleration(:,1); y_p_ddot=acceleration(:,2);
subplot 331
plot(time,x_p,'r')
xlabel('Time(s)','Fontsize',14)
ylabel('x_p','Fontsize',14)
title('end-effector x','Fontsize',16)
legend('x_p&time','Location','SouthEast');
subplot 332
plot(time,y_p,'r')
xlabel('Time(s)','Fontsize',14)
ylabel('y_p','Fontsize',14)
title('end-effector y','Fontsize',16)
legend('y_p&time','Location','SouthEast');
subplot 333
plot(x_p,y_p,'r')
xlabel('x_p','Fontsize',14)
ylabel('y_p','Fontsize',14)
title('x-y relationship','Fontsize',16)
legend('x_p&y_p','Location','SouthEast');
subplot 334
plot(time,x_p_dot,'g')
xlabel('Time(s)','Fontsize',14)
ylabel('x_pdot','Fontsize',14)
title('velocity-x ','Fontsize',16)
legend('x_pdot&time','Location','SouthEast');
subplot 335
plot(time,y_p_dot,'g')
xlabel('Time(s)','Fontsize',14)
ylabel('y_p_dot','Fontsize',14)
title('velocity-y','Fontsize',16)
legend('y_pdot&time','Location','SouthEast');
subplot 336
plot(x_p_dot,y_p_dot,'g')
xlabel('x_p_dot','Fontsize',14)
ylabel('y_p_dot','Fontsize',14)
title('x-y velocity relationship','Fontsize',16)
legend('x_pdot&y_pdot','Location','SouthEast');
subplot 337
plot(time,x_p_ddot,'b')
xlabel('Time(s)','Fontsize',14)
ylabel('x_p_ddot','Fontsize',14)
title('acceleration-x','Fontsize',16)
legend('x_pddot&time','Location','SouthEast');
subplot 338
plot(time,y_p_ddot,'b')
xlabel('Time(s)','Fontsize',14)
ylabel('y_p_ddot','Fontsize',14)
title('acceleration-y','Fontsize',16)
legend('y_pddot&time','Location','SouthEast');
figure(2)
plot(x_p_ddot,y_p_ddot,'b')
xlabel('x_p_ddot)','Fontsize',14)
ylabel('y_p_ddot','Fontsize',14)
title('x-y acceleration relationship','Fontsize',16)
legend('x_pddot&y_pddot','Location','SouthEast')
k=VideoWriter('n2me2tion2.avi');
open(k);
for i2=1:length(time)
n2=fix(length(time)/n1);
figure(3)
hold on
axis equal
plot(x_p(i2),y_p(i2),'o-r','MarkerSize',3);
u1=line([0 rd1_xp(i2)],[0 rd1_yp(i2)],'Color','k','LineWidth',2);
u2=line([rd1_xp(i2) rd1_xp(i2)+rd2_xp(i2)],...
[rd1_yp(i2) rd1_yp(i2)+rd2_yp(i2)],'Color','b','LineWidth',2);
u3=line([x_p(i2) x_p(i2)+x_p_dot(i2)],...
[y_p(i2) y_p(i2)+y_p_dot(i2)],'Color','g','LineWidth',2);
if(i2==length(time))
break;
end
if(0==rem(i2,n2))
else
delete(u1)
delete(u2)
delete(u3)
end
F(i2) = getframe;
end
writeVideo(k,F);
close(k);
function r_prime= trans1(local_r1,theta_1)
A=[cos(theta_1),-sin(theta_1); sin(theta_1),cos(theta_1)];
r_prime=A*local_r1;
end
function r_dot=trans_velocity(theta,theta_dot,r_prime)
B=[-sin(theta),-cos(theta);cos(theta),-sin(theta)];
r_dot=theta_dot*B*r_prime;
end
function r_ddot=trans_acceleration(theta_dot,theta_ddot,r)
R=[0,-1;1,0];
r_ddot=theta_ddot*R*r-(theta_dot)^2*r;
end
function r=addition(r_prime1,r_prime2)
r=r_prime1 + r_prime2;
end
9 commentaires
Walter Roberson
le 28 Nov 2020
Is there a reason you line() and then plot() and then delete the line before the plot is saved? I guess that could have an effect on setting axes limits, but xlim/ylim would be better for that purpose
상태 박
le 28 Nov 2020
Walter Roberson
le 28 Nov 2020
u=line([0 x_p(i2)],[0 y_p(i2)]); %x_p(i2), y_p(i2) is 100*1 matrix
That draws a single diagonal line on the axes
plot(x_p(i2),y_p(i2),'o-r','MarkerSize',3);
that draws a single point on the axes, with marker 'o' and marker size 3, with the color 'r'
delete(u)
that deletes the diagonal line before anyone could have seen the line being drawn and before anything took a record of the diagonal line.
Why are you drawing the diagonal line and then deleting it right after the plot() ?
상태 박
le 29 Nov 2020
상태 박
le 29 Nov 2020
Walter Roberson
le 29 Nov 2020
You seem to be using trans1() function, but I am not able to find a function with that name?
What error message are you getting?
Note: we would need all of your functions and all of your data files in order to test your function ourselves. Because we do not have that, you need to describe the problems more clearly.
상태 박
le 29 Nov 2020
Image Analyst
le 29 Nov 2020
You keep forgetting to upload the three .dat files, so how can we run your code???
상태 박
le 29 Nov 2020
Réponse acceptée
Plus de réponses (2)
Image Analyst
le 29 Nov 2020
It looks like your image might change size partway through. Try maximizing the figure in the loop after your last call to plot(), so it's always the same size for each frame (full screen).
g = gcf;
g.WindowState = 'maximized';
Catégories
En savoir plus sur Animation dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!