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 Comments
Direct link to this comment
https://es.mathworks.com/matlabcentral/answers/666013-how-to-use-getframe-commander-for-making-animation-video#comment_1166258
Direct link to this comment
https://es.mathworks.com/matlabcentral/answers/666013-how-to-use-getframe-commander-for-making-animation-video#comment_1166258
Direct link to this comment
https://es.mathworks.com/matlabcentral/answers/666013-how-to-use-getframe-commander-for-making-animation-video#comment_1166383
Direct link to this comment
https://es.mathworks.com/matlabcentral/answers/666013-how-to-use-getframe-commander-for-making-animation-video#comment_1166383
Direct link to this comment
https://es.mathworks.com/matlabcentral/answers/666013-how-to-use-getframe-commander-for-making-animation-video#comment_1168038
Direct link to this comment
https://es.mathworks.com/matlabcentral/answers/666013-how-to-use-getframe-commander-for-making-animation-video#comment_1168038
Direct link to this comment
https://es.mathworks.com/matlabcentral/answers/666013-how-to-use-getframe-commander-for-making-animation-video#comment_1168153
Direct link to this comment
https://es.mathworks.com/matlabcentral/answers/666013-how-to-use-getframe-commander-for-making-animation-video#comment_1168153
Direct link to this comment
https://es.mathworks.com/matlabcentral/answers/666013-how-to-use-getframe-commander-for-making-animation-video#comment_1168163
Direct link to this comment
https://es.mathworks.com/matlabcentral/answers/666013-how-to-use-getframe-commander-for-making-animation-video#comment_1168163
Direct link to this comment
https://es.mathworks.com/matlabcentral/answers/666013-how-to-use-getframe-commander-for-making-animation-video#comment_1168193
Direct link to this comment
https://es.mathworks.com/matlabcentral/answers/666013-how-to-use-getframe-commander-for-making-animation-video#comment_1168193
Direct link to this comment
https://es.mathworks.com/matlabcentral/answers/666013-how-to-use-getframe-commander-for-making-animation-video#comment_1168208
Direct link to this comment
https://es.mathworks.com/matlabcentral/answers/666013-how-to-use-getframe-commander-for-making-animation-video#comment_1168208
Direct link to this comment
https://es.mathworks.com/matlabcentral/answers/666013-how-to-use-getframe-commander-for-making-animation-video#comment_1168403
Direct link to this comment
https://es.mathworks.com/matlabcentral/answers/666013-how-to-use-getframe-commander-for-making-animation-video#comment_1168403
Direct link to this comment
https://es.mathworks.com/matlabcentral/answers/666013-how-to-use-getframe-commander-for-making-animation-video#comment_1168428
Direct link to this comment
https://es.mathworks.com/matlabcentral/answers/666013-how-to-use-getframe-commander-for-making-animation-video#comment_1168428
Sign in to comment.