Octave faster animation
I created 2-foot robot animation in Octave, which is 6 degree of freedom.
I created gragh by plotting each link. By repeting deleting and creating, the robot looks moving.
However, the animation is very slow, it cannot move smoothly.
I want to know if there is better way to create animation.
Here is the part of the code.
for ii=1:1:length(t)
pause(0.1)
%delete handle object under gca
h = findobj(gca, 'Parent', gca);
delete(h);
end
%3 dimention
view(3)
box on
grid on
axis square
%time
time=['time=' num2str(t(ii),'%4.2f') '[s]'];
set(ha,'String',time);
%coordinate transformation of the sole(right leg)
R_0_S(1).x=R_0_JR1(ii).x+0;
R_0_S(2).y=R_0_JR1(ii).y+0;
R_0_S(3).z=R_0_JR1(ii).z+0;
R_0_S(2).x=R_0_JR1(ii).x+s;
R_0_S(2).y=R_0_JR1(ii).y+s;
R_0_S(2).z=R_0_JR1(ii).z+0;
R_0_S(3).x=R_0_JR1(ii).x+s;
R_0_S(3).y=R_0_JR1(ii).y-s;
R_0_S(3).z=R_0_JR1(ii).z+0;
R_0_S(4).x=R_0_JR1(ii).x-s;
R_0_S(4).y=R_0_JR1(ii).y-s;
R_0_S(4).z=R_0_JR1(ii).z+0;
R_0_S(5).x=R_0_JR1(ii).x-s;
R_0_S(5).y=R_0_JR1(ii).y+s;
R_0_S(5).z=R_0_JR1(ii).z+0;
%coordinate transformation of the sole(left leg)
L_0_S(1).x=R_0_JL1(ii).x+0;
L_0_S(1).y=R_0_JL1(ii).y+0;
L_0_S(1).z=R_0_JL1(ii).z+0;
L_0_S(2).x=R_0_JL1(ii).x+s;
L_0_S(2).y=R_0_JL1(ii).y+s;
L_0_S(2).z=R_0_JL1(ii).z+0;
L_0_S(3).x=R_0_JL1(ii).x+s;
L_0_S(3).y=R_0_JL1(ii).y-s;
L_0_S(3).z=R_0_JL1(ii).z+0;
L_0_S(4).x=R_0_JL1(ii).x-s;
L_0_S(4).y=R_0_JL1(ii).y-s;
L_0_S(4).z=R_0_JL1(ii).z+0;
L_0_S(5).x=R_0_JL1(ii).x-s;
L_0_S(5).y=R_0_JL1(ii).y+s;
L_0_S(5).z=R_0_JL1(ii).z+0;
%drowing right sole
X=[R_0_S(2).x R_0_S(3).x R_0_S(4).x R_0_S(5).x R_0_S(2).x];
Y=[R_0_S(2).y R_0_S(3).y R_0_S(4).y R_0_S(5).y R_0_S(2).y];
Z=[R_0_S(2).z R_0_S(3).z R_0_S(4).z R_0_S(5).z R_0_S(2).z];
h1=line(X,Y,Z);
set(h1,'Color','c');
set(h1,'LineWidth',3);
hold on %overwrite
%drowing left sole
X=[L_0_S(2).x L_0_S(3).x L_0_S(4).x L_0_S(5).x L_0_S(2).x];
Y=[L_0_S(2).y L_0_S(3).y L_0_S(4).y L_0_S(5).y L_0_S(2).y];
Z=[L_0_S(2).z L_0_S(3).z L_0_S(4).z L_0_S(5).z L_0_S(2).z];
h2=line(X,Y,Z);
set(h2,'Color','m');
set(h2,'LineWidth',3);
%right knee
X=[R_0_JR1(ii).x R_0_JR2(ii).x];
Y=[R_0_JR1(ii).y R_0_JR2(ii).y];
Z=[R_0_JR1(ii).z R_0_JR2(ii).z];
h3=line(X,Y,Z);
set(h3,'Color','c');
set(h3,'LineWidth',3);
%Right thigh
X=[R_0_JR2(ii).x R_0_JR3(ii).x];
Y=[R_0_JR2(ii).y R_0_JR3(ii).y];
Z=[R_0_JR2(ii).z R_0_JR3(ii).z];
h4=line(X,Y,Z);
set(h4,'Color','c');
set(h4,'LineWidth',3);
%left thigh
X=[R_0_JL3(ii).x R_0_JL2(ii).x];
Y=[R_0_JL3(ii).y R_0_JL2(ii).y];
Z=[R_0_JL3(ii).z R_0_JL2(ii).z];
h6=line(X,Y,Z);
set(h6,'Color','m');
set(h6,'LineWidth',3);
%left knee
X=[R_0_JL2(ii).x R_0_JL1(ii).x];
Y=[R_0_JL2(ii).y R_0_JL1(ii).y];
Z=[R_0_JL2(ii).z R_0_JL1(ii).z];
h7=line(X,Y,Z);
set(h7,'Color','m');
set(h7,'LineWidth',3);
if(CGCTR_Enable==1)
Centroid regulator
x=R_0_CGCTR_CG(ii).x;
y=R_0_CGCTR_CG(ii).y;
z=R_0_CGCTR_CG(ii).z;
wd=r_CGCTR/2;
p1=[x+wd y-wd z-wd];%底面点1
p2=[x+wd y+wd z-wd];%底面点2
p3=[x-wd y+wd z-wd];%底面点3
p4=[x-wd y-wd z-wd];%底面点4
p5=[x+wd y-wd z+wd];%上面点5
p6=[x+wd y+wd z+wd];%上面点6
p7=[x-wd y+wd z+wd];%上面点7
p8=[x-wd y-wd z+wd];%上面点8
X=[p1(1) p2(1)];
Y=[p1(2) p2(2)];
Z=[p1(3) p2(3)];
h8=line(X,Y,Z);
set(h8,'Color','r');
set(h8,'LineWidth',3);
X=[p2(1) p3(1)];
Y=[p2(2) p3(2)];
Z=[p2(3) p3(3)];
h9=line(X,Y,Z);
set(h9,'Color','r');
set(h9,'LineWidth',3);
X=[p3(1) p4(1)];
Y=[p3(2) p4(2)];
Z=[p3(3) p4(3)];
h10=line(X,Y,Z);
set(h10,'Color','r');
set(h10,'LineWidth',3);
X=[p4(1) p1(1)];
Y=[p4(2) p1(2)];
Z=[p4(3) p1(3)];
h11=line(X,Y,Z);
set(h11,'Color','r');
set(h11,'LineWidth',3);
X=[p5(1) p6(1)];
Y=[p5(2) p6(2)];
Z=[p5(3) p6(3)];
h12=line(X,Y,Z);
set(h12,'Color','r');
set(h12,'LineWidth',3);
X=[p6(1) p7(1)];
Y=[p6(2) p7(2)];
Z=[p6(3) p7(3)];
h13=line(X,Y,Z);
set(h13,'Color','r');
set(h13,'LineWidth',3);
X=[p7(1) p8(1)];
Y=[p7(2) p8(2)];
Z=[p7(3) p8(3)];
h14=line(X,Y,Z);
set(h14,'Color','r');
set(h14,'LineWidth',3);
X=[p8(1) p5(1)];
Y=[p8(2) p5(2)];
Z=[p8(3) p5(3)];
h15=line(X,Y,Z);
set(h15,'Color','r');
set(h15,'LineWidth',3);
X=[p1(1) p5(1)];
Y=[p1(2) p5(2)];
Z=[p1(3) p5(3)];
h16=line(X,Y,Z);
set(h16,'Color','r');
set(h16,'LineWidth',3);
X=[p2(1) p6(1)];
Y=[p2(2) p6(2)];
Z=[p2(3) p6(3)];
h17=line(X,Y,Z);
set(h17,'Color','r');
set(h17,'LineWidth',3);
X=[p3(1) p7(1)];
Y=[p3(2) p7(2)];
Z=[p3(3) p7(3)];
h18=line(X,Y,Z);
set(h18,'Color','r');
set(h18,'LineWidth',3);
X=[p4(1) p8(1)];
Y=[p4(2) p8(2)];
Z=[p4(3) p8(3)];
h19=line(X,Y,Z);
set(h19,'Color','r');
set(h19,'LineWidth',3);
end
if (Pause_On==1) && (mod(t(ii),Pause_Sample_Time)==0)
pause;
end
end
matlab animation octave simulation
add a comment |
I created 2-foot robot animation in Octave, which is 6 degree of freedom.
I created gragh by plotting each link. By repeting deleting and creating, the robot looks moving.
However, the animation is very slow, it cannot move smoothly.
I want to know if there is better way to create animation.
Here is the part of the code.
for ii=1:1:length(t)
pause(0.1)
%delete handle object under gca
h = findobj(gca, 'Parent', gca);
delete(h);
end
%3 dimention
view(3)
box on
grid on
axis square
%time
time=['time=' num2str(t(ii),'%4.2f') '[s]'];
set(ha,'String',time);
%coordinate transformation of the sole(right leg)
R_0_S(1).x=R_0_JR1(ii).x+0;
R_0_S(2).y=R_0_JR1(ii).y+0;
R_0_S(3).z=R_0_JR1(ii).z+0;
R_0_S(2).x=R_0_JR1(ii).x+s;
R_0_S(2).y=R_0_JR1(ii).y+s;
R_0_S(2).z=R_0_JR1(ii).z+0;
R_0_S(3).x=R_0_JR1(ii).x+s;
R_0_S(3).y=R_0_JR1(ii).y-s;
R_0_S(3).z=R_0_JR1(ii).z+0;
R_0_S(4).x=R_0_JR1(ii).x-s;
R_0_S(4).y=R_0_JR1(ii).y-s;
R_0_S(4).z=R_0_JR1(ii).z+0;
R_0_S(5).x=R_0_JR1(ii).x-s;
R_0_S(5).y=R_0_JR1(ii).y+s;
R_0_S(5).z=R_0_JR1(ii).z+0;
%coordinate transformation of the sole(left leg)
L_0_S(1).x=R_0_JL1(ii).x+0;
L_0_S(1).y=R_0_JL1(ii).y+0;
L_0_S(1).z=R_0_JL1(ii).z+0;
L_0_S(2).x=R_0_JL1(ii).x+s;
L_0_S(2).y=R_0_JL1(ii).y+s;
L_0_S(2).z=R_0_JL1(ii).z+0;
L_0_S(3).x=R_0_JL1(ii).x+s;
L_0_S(3).y=R_0_JL1(ii).y-s;
L_0_S(3).z=R_0_JL1(ii).z+0;
L_0_S(4).x=R_0_JL1(ii).x-s;
L_0_S(4).y=R_0_JL1(ii).y-s;
L_0_S(4).z=R_0_JL1(ii).z+0;
L_0_S(5).x=R_0_JL1(ii).x-s;
L_0_S(5).y=R_0_JL1(ii).y+s;
L_0_S(5).z=R_0_JL1(ii).z+0;
%drowing right sole
X=[R_0_S(2).x R_0_S(3).x R_0_S(4).x R_0_S(5).x R_0_S(2).x];
Y=[R_0_S(2).y R_0_S(3).y R_0_S(4).y R_0_S(5).y R_0_S(2).y];
Z=[R_0_S(2).z R_0_S(3).z R_0_S(4).z R_0_S(5).z R_0_S(2).z];
h1=line(X,Y,Z);
set(h1,'Color','c');
set(h1,'LineWidth',3);
hold on %overwrite
%drowing left sole
X=[L_0_S(2).x L_0_S(3).x L_0_S(4).x L_0_S(5).x L_0_S(2).x];
Y=[L_0_S(2).y L_0_S(3).y L_0_S(4).y L_0_S(5).y L_0_S(2).y];
Z=[L_0_S(2).z L_0_S(3).z L_0_S(4).z L_0_S(5).z L_0_S(2).z];
h2=line(X,Y,Z);
set(h2,'Color','m');
set(h2,'LineWidth',3);
%right knee
X=[R_0_JR1(ii).x R_0_JR2(ii).x];
Y=[R_0_JR1(ii).y R_0_JR2(ii).y];
Z=[R_0_JR1(ii).z R_0_JR2(ii).z];
h3=line(X,Y,Z);
set(h3,'Color','c');
set(h3,'LineWidth',3);
%Right thigh
X=[R_0_JR2(ii).x R_0_JR3(ii).x];
Y=[R_0_JR2(ii).y R_0_JR3(ii).y];
Z=[R_0_JR2(ii).z R_0_JR3(ii).z];
h4=line(X,Y,Z);
set(h4,'Color','c');
set(h4,'LineWidth',3);
%left thigh
X=[R_0_JL3(ii).x R_0_JL2(ii).x];
Y=[R_0_JL3(ii).y R_0_JL2(ii).y];
Z=[R_0_JL3(ii).z R_0_JL2(ii).z];
h6=line(X,Y,Z);
set(h6,'Color','m');
set(h6,'LineWidth',3);
%left knee
X=[R_0_JL2(ii).x R_0_JL1(ii).x];
Y=[R_0_JL2(ii).y R_0_JL1(ii).y];
Z=[R_0_JL2(ii).z R_0_JL1(ii).z];
h7=line(X,Y,Z);
set(h7,'Color','m');
set(h7,'LineWidth',3);
if(CGCTR_Enable==1)
Centroid regulator
x=R_0_CGCTR_CG(ii).x;
y=R_0_CGCTR_CG(ii).y;
z=R_0_CGCTR_CG(ii).z;
wd=r_CGCTR/2;
p1=[x+wd y-wd z-wd];%底面点1
p2=[x+wd y+wd z-wd];%底面点2
p3=[x-wd y+wd z-wd];%底面点3
p4=[x-wd y-wd z-wd];%底面点4
p5=[x+wd y-wd z+wd];%上面点5
p6=[x+wd y+wd z+wd];%上面点6
p7=[x-wd y+wd z+wd];%上面点7
p8=[x-wd y-wd z+wd];%上面点8
X=[p1(1) p2(1)];
Y=[p1(2) p2(2)];
Z=[p1(3) p2(3)];
h8=line(X,Y,Z);
set(h8,'Color','r');
set(h8,'LineWidth',3);
X=[p2(1) p3(1)];
Y=[p2(2) p3(2)];
Z=[p2(3) p3(3)];
h9=line(X,Y,Z);
set(h9,'Color','r');
set(h9,'LineWidth',3);
X=[p3(1) p4(1)];
Y=[p3(2) p4(2)];
Z=[p3(3) p4(3)];
h10=line(X,Y,Z);
set(h10,'Color','r');
set(h10,'LineWidth',3);
X=[p4(1) p1(1)];
Y=[p4(2) p1(2)];
Z=[p4(3) p1(3)];
h11=line(X,Y,Z);
set(h11,'Color','r');
set(h11,'LineWidth',3);
X=[p5(1) p6(1)];
Y=[p5(2) p6(2)];
Z=[p5(3) p6(3)];
h12=line(X,Y,Z);
set(h12,'Color','r');
set(h12,'LineWidth',3);
X=[p6(1) p7(1)];
Y=[p6(2) p7(2)];
Z=[p6(3) p7(3)];
h13=line(X,Y,Z);
set(h13,'Color','r');
set(h13,'LineWidth',3);
X=[p7(1) p8(1)];
Y=[p7(2) p8(2)];
Z=[p7(3) p8(3)];
h14=line(X,Y,Z);
set(h14,'Color','r');
set(h14,'LineWidth',3);
X=[p8(1) p5(1)];
Y=[p8(2) p5(2)];
Z=[p8(3) p5(3)];
h15=line(X,Y,Z);
set(h15,'Color','r');
set(h15,'LineWidth',3);
X=[p1(1) p5(1)];
Y=[p1(2) p5(2)];
Z=[p1(3) p5(3)];
h16=line(X,Y,Z);
set(h16,'Color','r');
set(h16,'LineWidth',3);
X=[p2(1) p6(1)];
Y=[p2(2) p6(2)];
Z=[p2(3) p6(3)];
h17=line(X,Y,Z);
set(h17,'Color','r');
set(h17,'LineWidth',3);
X=[p3(1) p7(1)];
Y=[p3(2) p7(2)];
Z=[p3(3) p7(3)];
h18=line(X,Y,Z);
set(h18,'Color','r');
set(h18,'LineWidth',3);
X=[p4(1) p8(1)];
Y=[p4(2) p8(2)];
Z=[p4(3) p8(3)];
h19=line(X,Y,Z);
set(h19,'Color','r');
set(h19,'LineWidth',3);
end
if (Pause_On==1) && (mod(t(ii),Pause_Sample_Time)==0)
pause;
end
end
matlab animation octave simulation
1
Possible duplicate of Animate trajectory using Octave
– Cris Luengo
Nov 16 at 6:32
4
There are more examples if you search for "MATLAB faster animation", this works the same way in MATLAB. In short, instead of deleting and re-creating the plot, update the XData and YData properties of the line objects.
– Cris Luengo
Nov 16 at 6:34
3
YOu have to show your code...so that people can edit it and help you. It is suggested to use set functions for faster and smoother animation.
– Siva Srinivas Kolukula
Nov 16 at 7:20
add a comment |
I created 2-foot robot animation in Octave, which is 6 degree of freedom.
I created gragh by plotting each link. By repeting deleting and creating, the robot looks moving.
However, the animation is very slow, it cannot move smoothly.
I want to know if there is better way to create animation.
Here is the part of the code.
for ii=1:1:length(t)
pause(0.1)
%delete handle object under gca
h = findobj(gca, 'Parent', gca);
delete(h);
end
%3 dimention
view(3)
box on
grid on
axis square
%time
time=['time=' num2str(t(ii),'%4.2f') '[s]'];
set(ha,'String',time);
%coordinate transformation of the sole(right leg)
R_0_S(1).x=R_0_JR1(ii).x+0;
R_0_S(2).y=R_0_JR1(ii).y+0;
R_0_S(3).z=R_0_JR1(ii).z+0;
R_0_S(2).x=R_0_JR1(ii).x+s;
R_0_S(2).y=R_0_JR1(ii).y+s;
R_0_S(2).z=R_0_JR1(ii).z+0;
R_0_S(3).x=R_0_JR1(ii).x+s;
R_0_S(3).y=R_0_JR1(ii).y-s;
R_0_S(3).z=R_0_JR1(ii).z+0;
R_0_S(4).x=R_0_JR1(ii).x-s;
R_0_S(4).y=R_0_JR1(ii).y-s;
R_0_S(4).z=R_0_JR1(ii).z+0;
R_0_S(5).x=R_0_JR1(ii).x-s;
R_0_S(5).y=R_0_JR1(ii).y+s;
R_0_S(5).z=R_0_JR1(ii).z+0;
%coordinate transformation of the sole(left leg)
L_0_S(1).x=R_0_JL1(ii).x+0;
L_0_S(1).y=R_0_JL1(ii).y+0;
L_0_S(1).z=R_0_JL1(ii).z+0;
L_0_S(2).x=R_0_JL1(ii).x+s;
L_0_S(2).y=R_0_JL1(ii).y+s;
L_0_S(2).z=R_0_JL1(ii).z+0;
L_0_S(3).x=R_0_JL1(ii).x+s;
L_0_S(3).y=R_0_JL1(ii).y-s;
L_0_S(3).z=R_0_JL1(ii).z+0;
L_0_S(4).x=R_0_JL1(ii).x-s;
L_0_S(4).y=R_0_JL1(ii).y-s;
L_0_S(4).z=R_0_JL1(ii).z+0;
L_0_S(5).x=R_0_JL1(ii).x-s;
L_0_S(5).y=R_0_JL1(ii).y+s;
L_0_S(5).z=R_0_JL1(ii).z+0;
%drowing right sole
X=[R_0_S(2).x R_0_S(3).x R_0_S(4).x R_0_S(5).x R_0_S(2).x];
Y=[R_0_S(2).y R_0_S(3).y R_0_S(4).y R_0_S(5).y R_0_S(2).y];
Z=[R_0_S(2).z R_0_S(3).z R_0_S(4).z R_0_S(5).z R_0_S(2).z];
h1=line(X,Y,Z);
set(h1,'Color','c');
set(h1,'LineWidth',3);
hold on %overwrite
%drowing left sole
X=[L_0_S(2).x L_0_S(3).x L_0_S(4).x L_0_S(5).x L_0_S(2).x];
Y=[L_0_S(2).y L_0_S(3).y L_0_S(4).y L_0_S(5).y L_0_S(2).y];
Z=[L_0_S(2).z L_0_S(3).z L_0_S(4).z L_0_S(5).z L_0_S(2).z];
h2=line(X,Y,Z);
set(h2,'Color','m');
set(h2,'LineWidth',3);
%right knee
X=[R_0_JR1(ii).x R_0_JR2(ii).x];
Y=[R_0_JR1(ii).y R_0_JR2(ii).y];
Z=[R_0_JR1(ii).z R_0_JR2(ii).z];
h3=line(X,Y,Z);
set(h3,'Color','c');
set(h3,'LineWidth',3);
%Right thigh
X=[R_0_JR2(ii).x R_0_JR3(ii).x];
Y=[R_0_JR2(ii).y R_0_JR3(ii).y];
Z=[R_0_JR2(ii).z R_0_JR3(ii).z];
h4=line(X,Y,Z);
set(h4,'Color','c');
set(h4,'LineWidth',3);
%left thigh
X=[R_0_JL3(ii).x R_0_JL2(ii).x];
Y=[R_0_JL3(ii).y R_0_JL2(ii).y];
Z=[R_0_JL3(ii).z R_0_JL2(ii).z];
h6=line(X,Y,Z);
set(h6,'Color','m');
set(h6,'LineWidth',3);
%left knee
X=[R_0_JL2(ii).x R_0_JL1(ii).x];
Y=[R_0_JL2(ii).y R_0_JL1(ii).y];
Z=[R_0_JL2(ii).z R_0_JL1(ii).z];
h7=line(X,Y,Z);
set(h7,'Color','m');
set(h7,'LineWidth',3);
if(CGCTR_Enable==1)
Centroid regulator
x=R_0_CGCTR_CG(ii).x;
y=R_0_CGCTR_CG(ii).y;
z=R_0_CGCTR_CG(ii).z;
wd=r_CGCTR/2;
p1=[x+wd y-wd z-wd];%底面点1
p2=[x+wd y+wd z-wd];%底面点2
p3=[x-wd y+wd z-wd];%底面点3
p4=[x-wd y-wd z-wd];%底面点4
p5=[x+wd y-wd z+wd];%上面点5
p6=[x+wd y+wd z+wd];%上面点6
p7=[x-wd y+wd z+wd];%上面点7
p8=[x-wd y-wd z+wd];%上面点8
X=[p1(1) p2(1)];
Y=[p1(2) p2(2)];
Z=[p1(3) p2(3)];
h8=line(X,Y,Z);
set(h8,'Color','r');
set(h8,'LineWidth',3);
X=[p2(1) p3(1)];
Y=[p2(2) p3(2)];
Z=[p2(3) p3(3)];
h9=line(X,Y,Z);
set(h9,'Color','r');
set(h9,'LineWidth',3);
X=[p3(1) p4(1)];
Y=[p3(2) p4(2)];
Z=[p3(3) p4(3)];
h10=line(X,Y,Z);
set(h10,'Color','r');
set(h10,'LineWidth',3);
X=[p4(1) p1(1)];
Y=[p4(2) p1(2)];
Z=[p4(3) p1(3)];
h11=line(X,Y,Z);
set(h11,'Color','r');
set(h11,'LineWidth',3);
X=[p5(1) p6(1)];
Y=[p5(2) p6(2)];
Z=[p5(3) p6(3)];
h12=line(X,Y,Z);
set(h12,'Color','r');
set(h12,'LineWidth',3);
X=[p6(1) p7(1)];
Y=[p6(2) p7(2)];
Z=[p6(3) p7(3)];
h13=line(X,Y,Z);
set(h13,'Color','r');
set(h13,'LineWidth',3);
X=[p7(1) p8(1)];
Y=[p7(2) p8(2)];
Z=[p7(3) p8(3)];
h14=line(X,Y,Z);
set(h14,'Color','r');
set(h14,'LineWidth',3);
X=[p8(1) p5(1)];
Y=[p8(2) p5(2)];
Z=[p8(3) p5(3)];
h15=line(X,Y,Z);
set(h15,'Color','r');
set(h15,'LineWidth',3);
X=[p1(1) p5(1)];
Y=[p1(2) p5(2)];
Z=[p1(3) p5(3)];
h16=line(X,Y,Z);
set(h16,'Color','r');
set(h16,'LineWidth',3);
X=[p2(1) p6(1)];
Y=[p2(2) p6(2)];
Z=[p2(3) p6(3)];
h17=line(X,Y,Z);
set(h17,'Color','r');
set(h17,'LineWidth',3);
X=[p3(1) p7(1)];
Y=[p3(2) p7(2)];
Z=[p3(3) p7(3)];
h18=line(X,Y,Z);
set(h18,'Color','r');
set(h18,'LineWidth',3);
X=[p4(1) p8(1)];
Y=[p4(2) p8(2)];
Z=[p4(3) p8(3)];
h19=line(X,Y,Z);
set(h19,'Color','r');
set(h19,'LineWidth',3);
end
if (Pause_On==1) && (mod(t(ii),Pause_Sample_Time)==0)
pause;
end
end
matlab animation octave simulation
I created 2-foot robot animation in Octave, which is 6 degree of freedom.
I created gragh by plotting each link. By repeting deleting and creating, the robot looks moving.
However, the animation is very slow, it cannot move smoothly.
I want to know if there is better way to create animation.
Here is the part of the code.
for ii=1:1:length(t)
pause(0.1)
%delete handle object under gca
h = findobj(gca, 'Parent', gca);
delete(h);
end
%3 dimention
view(3)
box on
grid on
axis square
%time
time=['time=' num2str(t(ii),'%4.2f') '[s]'];
set(ha,'String',time);
%coordinate transformation of the sole(right leg)
R_0_S(1).x=R_0_JR1(ii).x+0;
R_0_S(2).y=R_0_JR1(ii).y+0;
R_0_S(3).z=R_0_JR1(ii).z+0;
R_0_S(2).x=R_0_JR1(ii).x+s;
R_0_S(2).y=R_0_JR1(ii).y+s;
R_0_S(2).z=R_0_JR1(ii).z+0;
R_0_S(3).x=R_0_JR1(ii).x+s;
R_0_S(3).y=R_0_JR1(ii).y-s;
R_0_S(3).z=R_0_JR1(ii).z+0;
R_0_S(4).x=R_0_JR1(ii).x-s;
R_0_S(4).y=R_0_JR1(ii).y-s;
R_0_S(4).z=R_0_JR1(ii).z+0;
R_0_S(5).x=R_0_JR1(ii).x-s;
R_0_S(5).y=R_0_JR1(ii).y+s;
R_0_S(5).z=R_0_JR1(ii).z+0;
%coordinate transformation of the sole(left leg)
L_0_S(1).x=R_0_JL1(ii).x+0;
L_0_S(1).y=R_0_JL1(ii).y+0;
L_0_S(1).z=R_0_JL1(ii).z+0;
L_0_S(2).x=R_0_JL1(ii).x+s;
L_0_S(2).y=R_0_JL1(ii).y+s;
L_0_S(2).z=R_0_JL1(ii).z+0;
L_0_S(3).x=R_0_JL1(ii).x+s;
L_0_S(3).y=R_0_JL1(ii).y-s;
L_0_S(3).z=R_0_JL1(ii).z+0;
L_0_S(4).x=R_0_JL1(ii).x-s;
L_0_S(4).y=R_0_JL1(ii).y-s;
L_0_S(4).z=R_0_JL1(ii).z+0;
L_0_S(5).x=R_0_JL1(ii).x-s;
L_0_S(5).y=R_0_JL1(ii).y+s;
L_0_S(5).z=R_0_JL1(ii).z+0;
%drowing right sole
X=[R_0_S(2).x R_0_S(3).x R_0_S(4).x R_0_S(5).x R_0_S(2).x];
Y=[R_0_S(2).y R_0_S(3).y R_0_S(4).y R_0_S(5).y R_0_S(2).y];
Z=[R_0_S(2).z R_0_S(3).z R_0_S(4).z R_0_S(5).z R_0_S(2).z];
h1=line(X,Y,Z);
set(h1,'Color','c');
set(h1,'LineWidth',3);
hold on %overwrite
%drowing left sole
X=[L_0_S(2).x L_0_S(3).x L_0_S(4).x L_0_S(5).x L_0_S(2).x];
Y=[L_0_S(2).y L_0_S(3).y L_0_S(4).y L_0_S(5).y L_0_S(2).y];
Z=[L_0_S(2).z L_0_S(3).z L_0_S(4).z L_0_S(5).z L_0_S(2).z];
h2=line(X,Y,Z);
set(h2,'Color','m');
set(h2,'LineWidth',3);
%right knee
X=[R_0_JR1(ii).x R_0_JR2(ii).x];
Y=[R_0_JR1(ii).y R_0_JR2(ii).y];
Z=[R_0_JR1(ii).z R_0_JR2(ii).z];
h3=line(X,Y,Z);
set(h3,'Color','c');
set(h3,'LineWidth',3);
%Right thigh
X=[R_0_JR2(ii).x R_0_JR3(ii).x];
Y=[R_0_JR2(ii).y R_0_JR3(ii).y];
Z=[R_0_JR2(ii).z R_0_JR3(ii).z];
h4=line(X,Y,Z);
set(h4,'Color','c');
set(h4,'LineWidth',3);
%left thigh
X=[R_0_JL3(ii).x R_0_JL2(ii).x];
Y=[R_0_JL3(ii).y R_0_JL2(ii).y];
Z=[R_0_JL3(ii).z R_0_JL2(ii).z];
h6=line(X,Y,Z);
set(h6,'Color','m');
set(h6,'LineWidth',3);
%left knee
X=[R_0_JL2(ii).x R_0_JL1(ii).x];
Y=[R_0_JL2(ii).y R_0_JL1(ii).y];
Z=[R_0_JL2(ii).z R_0_JL1(ii).z];
h7=line(X,Y,Z);
set(h7,'Color','m');
set(h7,'LineWidth',3);
if(CGCTR_Enable==1)
Centroid regulator
x=R_0_CGCTR_CG(ii).x;
y=R_0_CGCTR_CG(ii).y;
z=R_0_CGCTR_CG(ii).z;
wd=r_CGCTR/2;
p1=[x+wd y-wd z-wd];%底面点1
p2=[x+wd y+wd z-wd];%底面点2
p3=[x-wd y+wd z-wd];%底面点3
p4=[x-wd y-wd z-wd];%底面点4
p5=[x+wd y-wd z+wd];%上面点5
p6=[x+wd y+wd z+wd];%上面点6
p7=[x-wd y+wd z+wd];%上面点7
p8=[x-wd y-wd z+wd];%上面点8
X=[p1(1) p2(1)];
Y=[p1(2) p2(2)];
Z=[p1(3) p2(3)];
h8=line(X,Y,Z);
set(h8,'Color','r');
set(h8,'LineWidth',3);
X=[p2(1) p3(1)];
Y=[p2(2) p3(2)];
Z=[p2(3) p3(3)];
h9=line(X,Y,Z);
set(h9,'Color','r');
set(h9,'LineWidth',3);
X=[p3(1) p4(1)];
Y=[p3(2) p4(2)];
Z=[p3(3) p4(3)];
h10=line(X,Y,Z);
set(h10,'Color','r');
set(h10,'LineWidth',3);
X=[p4(1) p1(1)];
Y=[p4(2) p1(2)];
Z=[p4(3) p1(3)];
h11=line(X,Y,Z);
set(h11,'Color','r');
set(h11,'LineWidth',3);
X=[p5(1) p6(1)];
Y=[p5(2) p6(2)];
Z=[p5(3) p6(3)];
h12=line(X,Y,Z);
set(h12,'Color','r');
set(h12,'LineWidth',3);
X=[p6(1) p7(1)];
Y=[p6(2) p7(2)];
Z=[p6(3) p7(3)];
h13=line(X,Y,Z);
set(h13,'Color','r');
set(h13,'LineWidth',3);
X=[p7(1) p8(1)];
Y=[p7(2) p8(2)];
Z=[p7(3) p8(3)];
h14=line(X,Y,Z);
set(h14,'Color','r');
set(h14,'LineWidth',3);
X=[p8(1) p5(1)];
Y=[p8(2) p5(2)];
Z=[p8(3) p5(3)];
h15=line(X,Y,Z);
set(h15,'Color','r');
set(h15,'LineWidth',3);
X=[p1(1) p5(1)];
Y=[p1(2) p5(2)];
Z=[p1(3) p5(3)];
h16=line(X,Y,Z);
set(h16,'Color','r');
set(h16,'LineWidth',3);
X=[p2(1) p6(1)];
Y=[p2(2) p6(2)];
Z=[p2(3) p6(3)];
h17=line(X,Y,Z);
set(h17,'Color','r');
set(h17,'LineWidth',3);
X=[p3(1) p7(1)];
Y=[p3(2) p7(2)];
Z=[p3(3) p7(3)];
h18=line(X,Y,Z);
set(h18,'Color','r');
set(h18,'LineWidth',3);
X=[p4(1) p8(1)];
Y=[p4(2) p8(2)];
Z=[p4(3) p8(3)];
h19=line(X,Y,Z);
set(h19,'Color','r');
set(h19,'LineWidth',3);
end
if (Pause_On==1) && (mod(t(ii),Pause_Sample_Time)==0)
pause;
end
end
matlab animation octave simulation
matlab animation octave simulation
edited Nov 18 at 0:34
asked Nov 16 at 6:25
shmpwk
12
12
1
Possible duplicate of Animate trajectory using Octave
– Cris Luengo
Nov 16 at 6:32
4
There are more examples if you search for "MATLAB faster animation", this works the same way in MATLAB. In short, instead of deleting and re-creating the plot, update the XData and YData properties of the line objects.
– Cris Luengo
Nov 16 at 6:34
3
YOu have to show your code...so that people can edit it and help you. It is suggested to use set functions for faster and smoother animation.
– Siva Srinivas Kolukula
Nov 16 at 7:20
add a comment |
1
Possible duplicate of Animate trajectory using Octave
– Cris Luengo
Nov 16 at 6:32
4
There are more examples if you search for "MATLAB faster animation", this works the same way in MATLAB. In short, instead of deleting and re-creating the plot, update the XData and YData properties of the line objects.
– Cris Luengo
Nov 16 at 6:34
3
YOu have to show your code...so that people can edit it and help you. It is suggested to use set functions for faster and smoother animation.
– Siva Srinivas Kolukula
Nov 16 at 7:20
1
1
Possible duplicate of Animate trajectory using Octave
– Cris Luengo
Nov 16 at 6:32
Possible duplicate of Animate trajectory using Octave
– Cris Luengo
Nov 16 at 6:32
4
4
There are more examples if you search for "MATLAB faster animation", this works the same way in MATLAB. In short, instead of deleting and re-creating the plot, update the XData and YData properties of the line objects.
– Cris Luengo
Nov 16 at 6:34
There are more examples if you search for "MATLAB faster animation", this works the same way in MATLAB. In short, instead of deleting and re-creating the plot, update the XData and YData properties of the line objects.
– Cris Luengo
Nov 16 at 6:34
3
3
YOu have to show your code...so that people can edit it and help you. It is suggested to use set functions for faster and smoother animation.
– Siva Srinivas Kolukula
Nov 16 at 7:20
YOu have to show your code...so that people can edit it and help you. It is suggested to use set functions for faster and smoother animation.
– Siva Srinivas Kolukula
Nov 16 at 7:20
add a comment |
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53332534%2foctave-faster-animation%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53332534%2foctave-faster-animation%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Possible duplicate of Animate trajectory using Octave
– Cris Luengo
Nov 16 at 6:32
4
There are more examples if you search for "MATLAB faster animation", this works the same way in MATLAB. In short, instead of deleting and re-creating the plot, update the XData and YData properties of the line objects.
– Cris Luengo
Nov 16 at 6:34
3
YOu have to show your code...so that people can edit it and help you. It is suggested to use set functions for faster and smoother animation.
– Siva Srinivas Kolukula
Nov 16 at 7:20