%% 本程序用作绘制matlab动图 dot 20220728
% Poten
data1 = importdata(‘poten_dot2.txt’);
inition_30 = min(find(data1.data(:,1)>=30));
Poten_dot = data1.data(inition_30:end,:);
EEF_Error_X = (Poten_dot(:,34) - Poten_dot(1,34))*100;
EEF_Error_Y = (Poten_dot(:,35) - Poten_dot(1,35))*100;
EEF_Error_Z = (Poten_dot(:,36) - Poten_dot(1,36))*100;
Poten_EEF_Norm = sqrt(EEF_Error_X.^2 + EEF_Error_Y.^2 + EEF_Error_Z.^2 );
% MPC
data1 = importdata(‘MPC_dot.txt’);
inition_30 = min(find(data1.data(:,1)>=30));
inition_80 = min(find(data1.data(:,1)>=90));
MPC_dot = data1.data(inition_30:inition_80,:);
EEF_Error_X = (MPC_dot(:,34) - MPC_dot(1,34))*100; ;
EEF_Error_Y = (MPC_dot(:,35) - MPC_dot(1,35))*100; ;
EEF_Error_Z = (MPC_dot(:,36) - MPC_dot(1,36) )*100;;
MPC_EEF_Norm = sqrt(EEF_Error_X.^2 + EEF_Error_Y.^2 + EEF_Error_Z.^2);
% Feedback
data1 = importdata(‘Feedback_dot2.txt’);
inition_30 = min(find(data1.data(:,1)>=30));
Feedback_dot = data1.data(inition_30:end,:);
EEF_Error_X = (Feedback_dot(:,34) - Feedback_dot(1,34))*100;
EEF_Error_Y = (Feedback_dot(:,35) - Feedback_dot(1,35))*100;
EEF_Error_Z = (Feedback_dot(:,36) - Feedback_dot(1,36))*100;
Feedback_EEF_Norm = sqrt(EEF_Error_X.^2 + EEF_Error_Y.^2 + EEF_Error_Z.^2);
data_x = Poten_dot(:,1)-30;
data_y = Poten_EEF_Norm;
writerObj=VideoWriter(‘ALL.mp4’,‘MPEG-4’); %// 定义一个视频文件用来存动画 mp4
open(writerObj); %// 打开该视频文件
figure
for i=2:66:length(data_x)
scatter(MPC_dot(i)-30,MPC_EEF_Norm(i),60,[1 0 0])
hold on
plot(MPC_dot(1:i)-30,MPC_EEF_Norm(1:i),'LineWidth',1.5,'Color',[1 0 0])
scatter(Poten_dot(i)-30,Poten_EEF_Norm(i),60,[0 1 0])
hold on
plot(Poten_dot(1:i)-30,Poten_EEF_Norm(1:i),'LineWidth',1.5,'Color',[0 1 0])
scatter(Feedback_dot(i)-30,Feedback_EEF_Norm(i),60,[0 0 1])
hold on
plot(Feedback_dot(1:i)-30,Feedback_EEF_Norm(1:i),'LineWidth',1.5,'Color',[0 0 1])
hold off
%
% scatter(data_x(i),data_y(i),60,[0 0 1])
% hold on
% plot(data_x(1:i),data_y(1:i),‘LineWidth’,1.5,‘Color’,[0 0 1])
% hold off
%
axis([0 60 0 6])
grid on
xlabel('Time(s)','FontSize',25)
ylabel('Error(cm)','FontSize',25)
F=getframe(gcf);
frame = F; %// 把图像存入视频文件中
writeVideo(writerObj,frame)
end
close(writerObj); %// 关闭视频文件句柄