FormationControlSimulation/SOURCE/fncSpeedRef.m

46 lines
1.4 KiB
Matlab

function fncSr = fncSpeedRef(param,r,v,robStateLen)
sp = [1, 2]; % 1 = x; 2 = y
if (length(param) == 4)
% 'xsin' / 'xcos'
strSinOcos = strcat(sprintf("%s", param(2:length(param))));
if (param(1) == 'x')
strSfx = strcat(sprintf("%i*%s(%i*t)",r,strSinOcos,v));
strSfy = strcat(sprintf("%i",r));
% 'ysin' / 'ycos'
elseif (param(1) == 'y')
strSfx = strcat(sprintf("%i",r));
strSfy = strcat(sprintf("%i*%s(%i*t)",r,strSinOcos,v));
endif
elseif (param(1) == 'c')
if(param(2) == 'c')
%'circle'
strSfx = strcat(sprintf("%i*cos(%i*t)",r,v));
strSfy = strcat(sprintf("%i*sin(%i*t)",r,v));
else
strSfx = strcat(sprintf("%i*sin(%i*t)",r,v));
strSfy = strcat(sprintf("%i*cos(%i*t)",r,v));
endif
elseif (param == 's')
strSfx = strcat(sprintf("%i",r));
strSfy = strcat(sprintf("%i",v));
else
printf("Karepmu opo ? \n\n bukak fungsi speedRef sek diwoco komen e \n\n");
endif
if (robStateLen==2)
strAll = strcat("fncSr = @(t) [",strSfx, ";\ ", strSfy, "];");
elseif(robStateLen==3)
strAll = strcat("fncSr = @(t) [",strSfx, ";\ ", strSfy, ";\ 0];");
else
printf("ERROR REFSPEED NOT SUPPORT!!");
endif
%% printf(strAll)
eval(strAll);
%% spx = sfx(t);
%% spy = sfy(t);
endfunction