FormationControlSimulation/SOURCE/fncSpeedRef.m

58 lines
1.8 KiB
Matlab
Raw Normal View History

2020-07-29 11:31:38 +07:00
function fncSr = fncSpeedRef(param,r,v,robStateLen)
2019-12-18 14:23:12 +07:00
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(1) == 's')
strSinOcos = strcat(sprintf("%s", param(3:end)));
if (length(param) > 1)
if (param(2) == 'y')
strSfx = strcat(sprintf("%i*%s(%i*t)",r,strSinOcos,v));
strSfy = strcat(sprintf("%i",0));
% 'ysin' / 'ycos'
else %if (param(2) == 'x')
strSfx = strcat(sprintf("%i",0));
strSfy = strcat(sprintf("%i*%s(%i*t)",r,strSinOcos,v));
endif
else
strSfx = strcat(sprintf("%i",r));
strSfy = strcat(sprintf("%i",v));
endif
2019-12-18 14:23:12 +07:00
else
printf("Karepmu opo ? \n\n bukak fungsi speedRef sek diwoco komen e \n\n");
endif
2020-07-29 11:31:38 +07:00
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
2019-12-18 14:23:12 +07:00
%% printf(strAll)
eval(strAll);
%% spx = sfx(t);
%% spy = sfy(t);
endfunction