function build_sim_worldmodel(varargin) %BUILD_TURTLE_WORLDMODEL Build worldmodel.mdl. % % BUILD_TURTLE_WORLDMODEL() builds the worldmodel Simulink scheme to a % generic executable for all robots (no robot id required). % % To build the worldmodel for a specific version, specify the desired % version as the first input argument, e.g. BUILD_SIM_WORLDMODEL('real'). % By default the 'lite' version is used. % % To build the worldmodel_turtle simulink scheme for specific turtles, % include an array with the turtle numbers in the function call, e.g. % BUILD_SIM_WORLDMODEL(version,[1 3 4]). %% init curdir=pwd; addpathrobocup; %kill running application !sudo killall appman_sim % retrieve list of turtles, desired field and version turtle_select=[]; desfield=''; version='lite'; for i1=1:nargin, if isnumeric(varargin{i1}), turtle_select=[turtle_select,varargin{i1}]; else %check for 'lite' or 'real' if strcmp(varargin{i1},'real'), version='real'; disp('Building real worldmodel for simulator'); break; elseif strcmp(varargin{i1},'lite'), disp('Building lite version of worldmodel for simulator'); break; end %check for fieldname cd /home/robocup/svn/trunk/src/Turtle2/Global_par fieldnamelist=getfieldnamelist; cd(curdir) for i2=1:length(fieldnamelist), if strcmp(fieldnamelist{i2},varargin{i1}), desfield=varargin{i1}; break; end end if isempty(desfield), disp('You requested a non-existing field! Building for default field instead.'); end end end %set field size deffield = get_global_par('DEFAULTFIELDSELECTION'); if isempty(desfield), desfield = get_global_par('DEFAULTSIMFIELD'); end if ~strcmp(deffield,desfield), disp(['setting ',desfield,' field size']); cd /home/robocup/svn/trunk/src/Turtle2/Global_par selectfield(-1,['global_par_',desfield,'.h']) end if version == 'real' cd /home/robocup/svn/trunk/src/Turtle2/WorldModel %create copy of worldmodel.mdl, rename to worldmodel_sim.mdl !cp worldmodel.mdl worldmodel_sim.mdl else cd /home/robocup/svn/trunk/src/Turtle2/Simulator %create copy of worldmodel_sim.mdl, rename to worldmodel_sim_temporary_copy.mdl try warning('off','MATLAB:DELETE:FileNotFound'); delete('worldmodel_sim_temporary_copy.mdl'); warning('on','MATLAB:DELETE:FileNotFound'); catch end !cp worldmodel_sim.mdl worldmodel_sim_temporary_copy.mdl end % init tuning %get tunable parameter definitions evalin('base','WMTuneparams = get_global_par(''WMTuneparams'');') %define tunable parameters set_tunabledata_worldmodel(); % worldmodel tuning defaults init_worldmodel_tuning; %remove old executable and build directories try warning('off','MATLAB:DELETE:FileNotFound'); delete('worldmodel_sim'); warning('on','MATLAB:DELETE:FileNotFound'); rmdir('slprj','s'); rmdir('worldmodel_sim_*','s'); disp('old executable and build directories have been removed') catch end %% set rtw parameters % standard rtw configurations load_system('worldmodel_sim') cs = getActiveConfigSet('worldmodel_sim'); % set the rtw custom code properties set_param(cs,'CustomInclude','./include ./src ../Libs/multicast ../Libs/ipcomm2 ../Targets/wintarget ../Global_par ../Vision/src ../Libs/GeneralFunctions') set_param(cs,'CustomSource','') set_param(cs,'CustomLibrary','/usr/lib/librtdb.so /usr/lib/libpthread.so /usr/lib/libipcomm2_client.so /usr/lib/libipcomm2_server.so /usr/lib/libgeneral_functions.a') % change the Simulink target file and make options switchTarget(cs,'wmtarget.tlc',[]); set_param(cs,'TemplateMakefile','wm_unix.tmf') set_param(cs,'MakeCommand',['make_rtw OPT_OPTS="-g -O2 -W" CC="ccache gcc" OPTS="-DTIMER_ID=2 -D_GNU_SOURCE"']) % set external mode properties set_param(cs,'ExtMode','off') % save and close the system save_system('worldmodel_sim'); close_system('worldmodel_sim'); %% build executable try rtwbuild('worldmodel_sim') %copy executable if version == 'real' if isempty(turtle_select) !cp worldmodel_sim ../Simulator/bin/worldmodel_sim1 !cp worldmodel_sim ../Simulator/bin/worldmodel_sim2 !cp worldmodel_sim ../Simulator/bin/worldmodel_sim3 !cp worldmodel_sim ../Simulator/bin/worldmodel_sim4 !cp worldmodel_sim ../Simulator/bin/worldmodel_sim5 !cp worldmodel_sim ../Simulator/bin/worldmodel_sim6 else for i = 1:length(turtle_select) eval(['!cp worldmodel_sim ../Simulator/bin/worldmodel_sim' num2str(turtle_select(i))]) end end % delete the copied version of the worldmodel delete('worldmodel_sim.mdl'); else if isempty(turtle_select) !cp worldmodel_sim bin/worldmodel_sim1 !cp worldmodel_sim bin/worldmodel_sim2 !cp worldmodel_sim bin/worldmodel_sim3 !cp worldmodel_sim bin/worldmodel_sim4 !cp worldmodel_sim bin/worldmodel_sim5 !cp worldmodel_sim bin/worldmodel_sim6 else for i = 1:length(turtle_select) eval(['!cp worldmodel_sim bin/worldmodel_sim' num2str(turtle_select(i))]) end end %replace copy of worldmodel_sim.mdl !cp worldmodel_sim_temporary_copy.mdl worldmodel_sim.mdl delete('worldmodel_sim_temporary_copy.mdl'); end %delete original delete('worldmodel_sim'); cleanupworldmodelsim(deffield,desfield); catch err = lasterr; cleanupworldmodelsim(deffield,desfield); error(err); end cd(curdir); %% cleanup worldmodel sim after building function cleanupworldmodelsim(deffield,desfield) %remove build directories try rmdir('slprj','s'); rmdir('worldmodel_sim_*','s'); disp('build directories have been removed') catch end %set original field parameters if ~strcmp(deffield,desfield), cd /home/robocup/svn/trunk/src/Turtle2/Global_par selectfield(-1,['global_par_',deffield,'.h']); end