function build_sim_motion(varargin) %BUILD_TURTLE_MOTION Build motion_turtle.mdl. % % BUILD_TURTLE_MOTION() builds the motion_turtle Simulink scheme to a % generic executable for all robots (no robot id required). %% init curdir=pwd; addpathrobocup; %kill running application !sudo killall simulator % retrieve desired field desfield=''; if nargin, cd /home/robocup/svn/trunk/src/Turtle2/Global_par fieldnamelist=getfieldnamelist; cd(curdir); for i2=1:length(fieldnamelist), if strcmp(fieldnamelist{i2},varargin{1}), desfield=varargin{1}; break; end end if isempty(desfield), disp('You requested a non-existing field! Building for default field instead.'); 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 %remove old executable and build directories cd /home/robocup/svn/trunk/src/Turtle2/Simulator try warning('off','MATLAB:DELETE:FileNotFound'); delete('simulator'); warning('on','MATLAB:DELETE:FileNotFound'); rmdir('slprj','s'); rmdir('simulator_*','s'); disp('old executable and build directories have been removed') catch end %load motion settings, including port data from setparameters.m curdir = pwd; cd ../Motion; init_motion(); cd(curdir); %create copy of simulator.mdl, rename to simulator_temporary_copy.mdl try warning('off','MATLAB:DELETE:FileNotFound'); delete('simulator_temporary_copy.mdl'); warning('on','MATLAB:DELETE:FileNotFound'); catch end !cp simulator.mdl simulator_temporary_copy.mdl %% set rtw parameters %load motion scheme load_system('simulator'); cs = getActiveConfigSet('simulator'); %set the rtw custom code properties set_param(cs,'CustomInclude','../Libs/multicast ../Global_par') set_param(cs,'CustomSource','') set_param(cs,'CustomLibrary','/usr/lib/librtdb.so') %change the Simulink target file and make options switchTarget(cs,'mttarget.tlc',[]); set_param(cs,'TemplateMakefile','mt_unix.tmf') set_param(cs,'MakeCommand',['make_rtw OPT_OPTS="-g -O2" CC="ccache gcc" OPTS="-DNO_EC -D_GNU_SOURCE"']) %set external mode properties set_param(cs,'ExtMode','off') %save and close the system save_system('simulator'); close_system('simulator'); %% build executable try rtwbuild('simulator') cleanupsimulator(deffield,desfield); catch err = lasterr; cleanupsimulator(deffield,desfield); error(err); end cd(curdir); %% cleanup simulator after building function cleanupsimulator(deffield,desfield) %replace copy of simulator.mdl !cp simulator_temporary_copy.mdl simulator.mdl delete('simulator_temporary_copy.mdl'); %remove build directories try rmdir('slprj','s'); rmdir('simulator_*','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