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). % % To build the motion_turtle simulink scheme for specific turtles, % include an array with the turtle numbers in the function call, e.g. % BUILD_SIM_MOTION([1 3 4]). %% init curdir_init = pwd; addpathrobocup; %kill running application !sudo killall appman_sim % retrieve list of turtles and desired field turtle_select=[]; desfield=''; for i1=1:nargin, if isnumeric(varargin{i1}), turtle_select=[turtle_select,varargin{i1}]; else cd /home/robocup/svn/trunk/src/Turtle2/Global_par fieldnamelist=getfieldnamelist; cd(curdir_init); 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 %remove old executable and build directories cd /home/robocup/svn/trunk/src/Turtle2/Motion try warning('off','MATLAB:DELETE:FileNotFound'); delete('motion_sim'); delete('motion_sim.mdl'); warning('on','MATLAB:DELETE:FileNotFound'); rmdir('slprj','s'); rmdir('motion_sim_*','s'); disp('old executable and build directories have been removed') catch end %load motion settings, including port data from setparameters.m init_motion(); %create copy of motion_turtle.mdl, rename to motion_sim.mdl !cp motion_turtle.mdl motion_sim.mdl % obtain svn version svnver = 0; fid = fopen('/home/robocup/svnver.txt'); if(fid > 0) [svnver,count] = fscanf(fid,'%*s %d'); fclose(fid); end if(count ~= 1) svnver = 0; end %% set rtw parameters %load motion scheme load_system('motion_sim'); cs = getActiveConfigSet('motion_sim'); % check for log blocks logblocks = find_system(gcs,'BlockType','ToWorkspace'); if(~isempty(logblocks)) disp(' ') disp('WARNING : Logging block found in motion_turtle.mdl! Please remove before checking in!') for(k=1:size(logblocks)) disp(logblocks{k}) end disp('') disp('') end % set data aquisition block to simulator set_param('motion_sim/decoupled controlled robot/decoupled robot/Subsystem/Data aquisition','BlockChoice','Simulator'); % set low level control block to turtle set_param('motion_sim/decoupled controlled robot/decoupled robot/Low Level Control','BlockChoice','Turtle'); %set the rtw custom code properties set_param(cs,'CustomInclude',['../Libs/kinect/include ../Libs/voronoi ./src ../Libs/ipcomm2 ../Libs/GeneralFunctions ../Libs/multicast ../Global_par ../Motion/src/refbox_handler/ ../Motion/src/role_handler/ ../Motion/src/pass_handler/ ../Motion/src/mu_positioning_lib/ ../Motion/src/strategy_handler/ /usr/include/gsl/ /usr/local/lib/ /usr/lib/ /usr/local/include/c_urg/ ./src/LaserRangeFinder/include/ ./src/LaserRangeFinder/ ' buspath]) set_param(cs,'CustomSource','') set_param(cs,'CustomLibrary','/usr/lib/libfreenect.so /usr/lib/libvoronoi.so /usr/lib/libpthread.so /usr/lib/libipcomm2_server.so /usr/lib/librtdb.so /usr/lib/libgd.so /usr/lib/libgeneral_functions.a /usr/lib/libgslcblas.so /usr/lib/libgsl.so /usr/lib/libc_urg.so /usr/lib/libc_urg_connection.so /usr/lib/libc_urg_system.so ') %change the Simulink target file and make options % switchTarget(cs,'mttarget.tlc',[]); set_param(cs,'TemplateMakefile','mtt_unix.tmf') set_param(cs,'MakeCommand',['make_rtw OPT_OPTS="-g -O2 -W" CC="ccache gcc" OPTS="-DNO_EC -DSIMULATOR -DNETIF_ID=1 -DPRIO=99 -D_GNU_SOURCE -DSVN_VER=',num2str(svnver),'"']) %set external mode properties set_param(cs,'ExtMode','off') %save and close the system save_system('motion_sim'); close_system('motion_sim'); %% build executable try rtwbuild('motion_sim') %copy executable if nargin == 0 %copy executable !cp motion_sim ../Simulator/bin/motion_sim1 !cp motion_sim ../Simulator/bin/motion_sim2 !cp motion_sim ../Simulator/bin/motion_sim3 !cp motion_sim ../Simulator/bin/motion_sim4 !cp motion_sim ../Simulator/bin/motion_sim5 !cp motion_sim ../Simulator/bin/motion_sim6 else for i = 1:length(turtle_select) eval(['!cp motion_sim ../Simulator/bin/motion_sim' num2str(turtle_select(i))]) end end %delete original delete('motion_sim'); cleanupmotionsim(deffield,desfield); catch err = lasterr; cleanupmotionsim(deffield,desfield); error(err); end cd(curdir_init); %% cleanup motion sim after building function cleanupmotionsim(deffield,desfield) %remove build directories try delete('motion_sim.mdl'); rmdir('slprj','s'); rmdir('motion_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