Home > src > BN_pol_rec > Hsand > updateWorld.m

updateWorld

PURPOSE ^

UPDATEWORLD - procedure that updates positions of enemy, own force and sensors

SYNOPSIS ^

This is a script file.

DESCRIPTION ^

 UPDATEWORLD - procedure that updates positions of enemy, own force and sensors

 040519 - rj - some more comments
 040520 - rj - rounded assigned positions
 040524 - rj - bug fixed
 050119 - rj - minor change
 050123 - rj - another change

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 % UPDATEWORLD - procedure that updates positions of enemy, own force and sensors
0002 %
0003 % 040519 - rj - some more comments
0004 % 040520 - rj - rounded assigned positions
0005 % 040524 - rj - bug fixed
0006 % 050119 - rj - minor change
0007 % 050123 - rj - another change
0008 %
0009 
0010 global simulationTime;
0011 global struct_enemy_comps;
0012 global struct_sensors;
0013 global noOfEnemyCompanies;
0014 global noOfSensors;
0015 R_det = 2;
0016 noOfPlatoons = 3;
0017 uncertanity_factor = 1;
0018 % E.g. struct_enemy_comp(1).plt(3).est_pos returns estimate of position of
0019 % platoon three that belongs to compani one
0020 
0021 % update properties of enemies
0022 for j = 1:noOfEnemyCompanies
0023   [pos_company] = getGround_TruthPos(struct_enemy_comps(j).id);
0024   for k = 1:noOfPlatoons
0025     [pos_plt] = getPlt_Pos(pos_company, k);
0026     struct_enemy_comps(j).plt(k).velocity = pos_plt - struct_enemy_comps(j).plt(k).real_pos;
0027     struct_enemy_comps(j).plt(k).real_pos = pos_plt;
0028     struct_enemy_comps;
0029   end;
0030 end;
0031 
0032 % update properties of sensors
0033 for i = 1:noOfSensors
0034   curr_sensor = struct_sensors(i);
0035    
0036   if ~strcmp(curr_sensor.target_id, 'none')
0037     % if the sensor is on its way to something
0038        
0039     if strcmp(curr_sensor.target_id, 'home_base');
0040       % then the sensor is returning to its home base
0041      
0042       if (euclidean_distance(curr_sensor.home_base, curr_sensor.pos) < curr_sensor.max_speed)
0043       % if the sensor has reached (or approximately reached) the home base
0044     struct_sensors(i).target_id = 'none';
0045         struct_sensors(i).pos = curr_sensor.home_base;
0046         struct_sensors(i).sensor_plan = [];
0047       else
0048         % else it is still moving towards its home base
0049     sensor_dir = curr_sensor.home_base - curr_sensor.pos;
0050     sensor_dir = sensor_dir./norm(sensor_dir);
0051     struct_sensors(i).pos = round( curr_sensor.pos + ...
0052            curr_sensor.max_speed*sensor_dir );
0053       end
0054     else
0055       % then the sensor is probably going to some other destination
0056 %      [comp_no, plt_no] = getComp_Platoon_No(curr_sensor.target_id);
0057 %      target_pos = mean(struct_enemy_comps(comp_no).plt(plt_no).real_pos);
0058       next_pos = curr_sensor.sensor_plan(1,:);
0059 
0060       if (euclidean_distance( next_pos, curr_sensor.pos ) < curr_sensor.max_speed)
0061         % if close enough to the target
0062         struct_sensors(i).pos = round(next_pos);
0063         [no_of_path_nodes dummy] = size( curr_sensor.sensor_plan );
0064 %        if ~isempty(curr_sensor.sensor_plan)
0065         if no_of_path_nodes > 1
0066       % select next position from plan list
0067           struct_sensors(i).sensor_plan = struct_sensors(i).sensor_plan(2:end,:);
0068         else
0069           % if there are no more steps in the plan
0070           % set plan to go to home_base
0071       struct_sensors(i).target_id = 'home_base';
0072           struct_sensors(i).sensor_plan = curr_sensor.home_base;
0073         end
0074       else
0075     % move in the direction of the next flight point
0076         sensor_dir = next_pos - struct_sensors(i).pos;
0077         sensor_dir = sensor_dir./norm(sensor_dir);
0078         struct_sensors(i).pos = round( curr_sensor.pos + ...
0079              curr_sensor.max_speed*sensor_dir );
0080       end
0081     end
0082   end;
0083 end;
0084 
0085            
0086         
0087 
0088 
0089

Generated on Wed 16-Mar-2005 09:17:47 by m2html © 2003