Animation Vehicle Error Text Overlapping Each Other

조회 수: 1 (최근 30일)
Ivan Dwi Putra
Ivan Dwi Putra 2021년 1월 4일
I want animate simple of moving vehicle with delta of distance in vehicle 1 to vehicle 2 until vehicle 6 to vehicle 7, my problem the delta of distance is overlapping each other so can not see clearly.
This is my code
clear all; close all; clc;
%Untuk bikin video percobaan lurus dituker aja yg komen ama bukan komen
%Read .xls = kiri nama file, kanan blok kolom-baris
%% Leader
dataxleader = xlsread('DMPC_Train_PF.xlsx','A3:A102');
datayleader = xlsread('DMPC_Train_PF.xlsx','B3:B102');
%% Follower
% Follower 1
dataxfollower1 = xlsread('DMPC_Train_PF.xlsx','C3:C102');
datayfollower1 = xlsread('DMPC_Train_PF.xlsx','D3:D102');
% Follower 2
dataxfollower2 = xlsread('DMPC_Train_PF.xlsx','E3:E102');
datayfollower2 = xlsread('DMPC_Train_PF.xlsx','F3:F102');
% Follower 3
dataxfollower3 = xlsread('DMPC_Train_PF.xlsx','G3:G102');
datayfollower3 = xlsread('DMPC_Train_PF.xlsx','H3:H102');
% Follower 4
dataxfollower4 = xlsread('DMPC_Train_PF.xlsx','I3:I102');
datayfollower4 = xlsread('DMPC_Train_PF.xlsx','J3:J102');
% Follower 5
dataxfollower5 = xlsread('DMPC_Train_PF.xlsx','K3:K102');
datayfollower5 = xlsread('DMPC_Train_PF.xlsx','L3:L102');
% Follower 6
dataxfollower6 = xlsread('DMPC_Train_PF.xlsx','M3:M102');
datayfollower6 = xlsread('DMPC_Train_PF.xlsx','N3:N102');
%% Delta Jarak
% Delta Jarak 1
deltajarak1 = xlsread('DMPC_Train_PF.xlsx','AG3:AG102');
posisideltax1 = [dataxfollower1(1:100) + dataxleader(1:100)] / 2 ;
posisideltay1 = [datayfollower1(1:100) + datayleader(1:100)] / 2 ;
% Delta Jarak 2
deltajarak2 = xlsread('DMPC_Train_PF.xlsx','AH3:AH102');
posisideltax2 = [dataxfollower2(1:100) + dataxfollower1(1:100)] / 2 ;
posisideltay2 = [datayfollower2(1:100) + datayfollower1(1:100)] / 2 ;
% Delta Jarak 3
deltajarak3 = xlsread('DMPC_Train_PF.xlsx','AI3:AI102');
posisideltax3 = [dataxfollower3(1:100) + dataxfollower2(1:100)] / 2 ;
posisideltay3 = [datayfollower3(1:100) + datayfollower2(1:100)] / 2 ;
% Delta Jarak 4
deltajarak4 = xlsread('DMPC_Train_PF.xlsx','AJ3:AJ102');
posisideltax4 = [dataxfollower4(1:100) + dataxfollower3(1:100)] / 2 ;
posisideltay4 = [datayfollower4(1:100) + datayfollower3(1:100)] / 2 ;
% Delta Jarak 5
deltajarak5 = xlsread('DMPC_Train_PF.xlsx','AK3:AK102');
posisideltax5 = [dataxfollower5(1:100) + dataxfollower4(1:100)] / 2 ;
posisideltay5 = [datayfollower5(1:100) + datayfollower4(1:100)] / 2 ;
% Delta Jarak 6
deltajarak6 = xlsread('DMPC_Train_PF.xlsx','AL3:AL102');
posisideltax6 = [dataxfollower6(1:100) + dataxfollower5(1:100)] / 2 ;
posisideltay6 = [datayfollower6(1:100) + datayfollower5(1:100)] / 2 ;
% word '' tuh biar deklarasi awal string aja, karena matlabnya butuh ga
% kaya python.
word1 = '';
word2 = '';
word3 = '';
word4 = '';
word5 = '';
word6 = '';
waktu = '';
%t dapet dari total waktu percobaan dibagi jumlah data(dengan asumsi prosesnya pake waktu yg relatif sama 38ms)
t = 1500.2336/100; %waktu bisa aja pake dari data tinggal ditambah
%ada geser dari waktu asli ke waktu plot beda 0.2s
%walaupun data asli juga waktunya kepengaruh ama processing speed pas video
%ke data excel
time = 0;
% repeat bisi diilangin soalnya cuma buat ngecek berulang ada salah ato ga
for repeat = 1:1
figure;
for i = 1:100 %1:jumlah data
time = time + t;
% Leader
plot(dataxleader(1:i),datayleader(1:i),'--m');
text(dataxleader,datayleader,'deltajarak1')
circle (dataxleader(i),datayleader(i),5);
grid on;
hold on;
% Follower 1
plot(dataxfollower1(1:i),datayfollower1(1:i),'-.b');
text(dataxfollower1,datayfollower1,'deltajarak2')
circle (dataxfollower1(i),datayfollower1(i),5);
grid on;
hold on;
% Follower 2
plot(dataxfollower2(1:i),datayfollower2(1:i),'-.r');
text(dataxfollower2,datayfollower2,'deltajarak3')
circle (dataxfollower2(i),datayfollower2(i),5);
grid on;
hold on;
% Follower 3
plot(dataxfollower3(1:i),datayfollower3(1:i),'-.g');
text(dataxfollower3,datayfollower3,'deltajarak4')
circle (dataxfollower3(i),datayfollower3(i),5);
grid on;
hold on;
% Follower 4
plot(dataxfollower4(1:i),datayfollower4(1:i),'-.c');
text(dataxfollower4,datayfollower4,'deltajarak5')
circle (dataxfollower4(i),datayfollower4(i),5);
grid on;
hold on;
% Follower 5
plot(dataxfollower5(1:i),datayfollower5(1:i),'-.y');
text(dataxfollower5,datayfollower5,'deltajarak6')
circle (dataxfollower5(i),datayfollower5(i),5);
grid on;
hold on;
% Follower 6
plot(dataxfollower6(1:i),datayfollower6(1:i),'-.k');
% text(x,y,'delta')
circle (dataxfollower6(i),datayfollower6(i),5);
line([dataxleader(i),dataxfollower1(i)],[datayleader(i),datayfollower1(i)]);
line([dataxfollower1(i),dataxfollower2(i)], [datayfollower1(i),datayfollower2(i)]);
line([dataxfollower2(i),dataxfollower3(i)], [datayfollower2(i),datayfollower3(i)]);
line([dataxfollower3(i),dataxfollower4(i)], [datayfollower3(i),datayfollower4(i)]);
line([dataxfollower4(i),dataxfollower5(i)], [datayfollower4(i),datayfollower5(i)]);
line([dataxfollower5(i),dataxfollower6(i)], [datayfollower5(i),datayfollower6(i)]);
%title ama legend aku masih belum tau gimana dikeluarin dari
%loopnya biar prosesnya ga lemot tapi pas ke video tetep bisa
%soalnya ngatur fps diatur di akhir
title('Perubahan Posisi Mobile Robot Pada Percobaan Belok')
legend('Leader','Follower1','Follower2','Follower3','Follower4','Follower5','Follower6');
% writerObj.FrameRate = 26.1882 ;
xlim([0 1000]);
ylim([0 150]);
deltajarakcm1 = deltajarak1/1.5;
deltajarakcm2 = deltajarak2/1.5;
deltajarakcm3 = deltajarak3/1.5;
deltajarakcm4 = deltajarak4/1.5;
deltajarakcm5 = deltajarak5/1.5;
deltajarakcm6 = deltajarak6/1.5;
%delete biar tulisan word ama waktu ga tetep ada di plotnya
delete(word1);
delete(waktu);
word1 = text(posisideltax1(i),posisideltay1(i),sprintf('delta Jarak1 = %.2f Pixel, (%.2f cm)',deltajarak1(i),deltajarakcm1(i)'));
waktu = text(10,10,sprintf('waktu1 = %.2f s',time))
delete(word2);
word2 = text(posisideltax2(i),posisideltay2(i),sprintf('delta Jarak2 = %.2f Pixel, (%.2f cm)',deltajarak2(i),deltajarakcm2(i)'));
delete(word3);
word3 = text(posisideltax3(i),posisideltay3(i),sprintf('delta Jarak3 = %.2f Pixel, (%.2f cm)',deltajarak3(i),deltajarakcm3(i)'));
delete(word4);
word4 = text(posisideltax4(i),posisideltay4(i),sprintf('delta Jarak4 = %.2f Pixel, (%.2f cm)',deltajarak4(i),deltajarakcm4(i)'));
delete(word5);
word5 = text(posisideltax5(i),posisideltay5(i),sprintf('delta Jarak5 = %.2f Pixel, (%.2f cm)',deltajarak5(i),deltajarakcm5(i)'));
delete(word6);
word6 = text(posisideltax6(i),posisideltay6(i),sprintf('delta Jarak6 = %.2f Pixel, (%.2f cm)',deltajarak6(i),deltajarakcm6(i)'));
drawnow;
%getframe buat ambil frame
F(i) = getframe(gcf);
end
%video writer ya nama file
writerObj = VideoWriter('MPC Train.avi');
writerObj.FrameRate = 26.1882 ;
%frame rate aku dapet dari data/waktu
open(writerObj);
%bawah yang proses bikin videonya
for i = 1:length(F)
frame = F(i);
writeVideo(writerObj, frame);
end
close(writerObj);
end
close all;
I read data from excel
The problem is delta distance 1 until delta distance 6 overlapping each other

답변 (0개)

카테고리

Help CenterFile Exchange에서 Animation에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by