118 lines
3.3 KiB
Matlab
118 lines
3.3 KiB
Matlab
clear -all
|
|
graphics_toolkit('gnuplot')
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% config nang kene
|
|
conRobot = [1 2 1;
|
|
3 2 1;
|
|
3 1 1;
|
|
];
|
|
length_d = .5;
|
|
dRobot = [ 1;
|
|
1;
|
|
1;
|
|
];
|
|
corRobot = [1.5; 1.7;0;
|
|
2; 2.5;0;
|
|
2.5; 2.8;0;
|
|
]; % xy xy xy
|
|
robStateLen = length(corRobot)/length(dRobot)
|
|
B = [
|
|
1 0; 0 1;
|
|
0 0; 0 0;
|
|
0 0; 0 0;
|
|
];
|
|
kp = 80;
|
|
ki = 1;
|
|
% fvref = fncSpeedRef('ysin',50,2,robStateLen);
|
|
% fvref = fncSpeedRef('xsin',50,2,robStateLen);
|
|
% fvref = fncSpeedRef('cw',-300,1,robStateLen);
|
|
% fvref = fncSpeedRef('s',50,50,robStateLen);
|
|
fvref = fncSpeedRef('s',0,0,robStateLen);
|
|
h = .1;
|
|
tspan = 1:h:10;
|
|
sys = formationControl2ndBuilder(conRobot,robStateLen,kp,kp,ki,ki,length_d,1);
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% config nang nduwur
|
|
|
|
[R,K,d] = rigidityMatrixFnc(conRobot,robStateLen);
|
|
_zero = zeros(size(R(corRobot,K),1),1);
|
|
sInit = [corRobot; _zero;];
|
|
sAnsInit =[_zero; _zero;];
|
|
s2ndInit = [corRobot; %x1
|
|
zeros(length(corRobot),1); %x2
|
|
zeros(length(corRobot),1); %xi1
|
|
_zero]; %xi2
|
|
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% start solving
|
|
printf("Mulai memecakan masalah \n\n");
|
|
startExe = tic;
|
|
|
|
dydt = @(t, y) sys.ss(y,fvref(t));
|
|
[t,y] = ode45(dydt, tspan, s2ndInit);
|
|
|
|
endExe = toc(startExe);
|
|
printf("Membutuhkan waktu %i menit, %i detik \n untuk memecahkan masalah mu \n\n",
|
|
floor(endExe/60), rem(endExe,60))
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% End Solving
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% start plot it
|
|
|
|
close all
|
|
|
|
figure(1)
|
|
|
|
% plot trayektori dari setiap robot
|
|
str_tmp = "plot(";
|
|
|
|
|
|
xi = 1:robStateLen:length(corRobot)-1
|
|
yi = 2:robStateLen:length(corRobot)
|
|
|
|
for i = 1:sys.n-1
|
|
str_tmp = strcat(str_tmp,sprintf("y'(%i,:),y'(%i,:),",xi(i),yi(i)));
|
|
endfor
|
|
str_tmp = strcat(str_tmp,sprintf("y'(%i,:),y'(%i,:));",xi(i+1),yi(i+1)));
|
|
eval(str_tmp);
|
|
|
|
hold on
|
|
% membuat fungsi plot robot di waktu
|
|
% tertentu
|
|
str_tmp = "@(t) plot( [";
|
|
for i = 1:robStateLen:length(corRobot)
|
|
str_tmp = strcat( str_tmp, sprintf("y'(%i,t), ",i));
|
|
endfor
|
|
str_tmp = strcat( str_tmp, sprintf("], ["));
|
|
for i = 2:robStateLen:length(corRobot)
|
|
str_tmp = strcat( str_tmp, sprintf("y'(%i,t), ",i));
|
|
endfor
|
|
str_tmp = strcat( str_tmp, sprintf("], \"^\");"));
|
|
plot_rb = eval(str_tmp);
|
|
|
|
xrb = 1:robStateLen:length(corRobot);
|
|
yrb = 2:robStateLen:length(corRobot);
|
|
|
|
% fungsi untuk plot coneksi di waktu
|
|
% tertentu
|
|
function plot_con (pltRb, yOut, conIn,xm,ym, time)
|
|
pltRb(time);
|
|
for i = 1:length(conIn)
|
|
plot([yOut(xm(conIn(i, 1)),time), yOut(xm(conIn(i, 2)),time)],
|
|
[yOut(ym(conIn(i,1)),time), yOut(ym(conIn(i,2)),time)], "r" )
|
|
endfor
|
|
endfunction
|
|
|
|
plot_con(plot_rb, y', conRobot, xrb, yrb, 1);
|
|
% plot_con(plot_rb, y', conRobot, xrb, yrb, round(length(tspan)/2));
|
|
plot_con(plot_rb, y', conRobot, xrb, yrb, length(tspan));
|
|
|
|
|
|
str_tmp = "legend(";
|
|
for i = 1:numNodes(edgeL2adjL(conRobot))-1;
|
|
str_tmp =strcat(str_tmp,sprintf("\"R%i \", ",i));
|
|
endfor
|
|
str_tmp =strcat(str_tmp,sprintf("\"R%i \" )",++i));
|
|
eval(str_tmp)
|
|
title("Motion dari Robot");
|
|
|
|
csvwrite("DataOutMotion.csv", [t y])
|
|
% save DataOutMotion.data y
|
|
% save DataErrorEdge.data yans
|
|
|