Home > src > BN_pol_rec > Hsand > updateWorld_err.m

updateWorld_err

PURPOSE ^

procedure that updates positions of enemy, own force and sensors

SYNOPSIS ^

This is a script file.

DESCRIPTION ^

 procedure that updates positions of enemy, own force and sensors

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 
0002 
0003 
0004 
0005 % procedure that updates positions of enemy, own force and sensors
0006 
0007 % R_det = radius of detection
0008 
0009 
0010 
0011 %
0012 
0013 % 040519 - rj - some more comments
0014 
0015 % 040520 - rj - rounded assigned positions
0016 
0017 % 040524 - rj - bug fixed
0018 
0019 %
0020 
0021 
0022 
0023 global simulationTime;
0024 
0025 global struct_enemy_comps;
0026 
0027 global struct_sensors;
0028 
0029 global noOfEnemyCompanies;
0030 
0031 global noOfSensors;
0032 
0033 R_det = 2;
0034 
0035 noOfPlatoons = 3;
0036 
0037 uncertanity_factor = 1;
0038 
0039 % E.g. struct_enemy_comp(1).plt(3).est_pos returns estimate of position of
0040 
0041 % platoon three that belongs to compani one
0042 
0043 
0044 
0045 % update properties of enemies
0046 
0047 for j = 1:noOfEnemyCompanies
0048 
0049   [pos_company] = getGround_TruthPos(struct_enemy_comps(j).id);
0050 
0051   for k = 1:noOfPlatoons
0052 
0053     [pos_plt] = getPlt_Pos(pos_company, k);
0054 
0055     struct_enemy_comps(j).plt(k).velocity = pos_plt - struct_enemy_comps(j).plt(k).real_pos;
0056 
0057     struct_enemy_comps(j).plt(k).real_pos = pos_plt;
0058 
0059     struct_enemy_comps;
0060 
0061   end;
0062 
0063 end;
0064 
0065 
0066 
0067 % update properties of sensors
0068 
0069 for i = 1:noOfSensors
0070 
0071   curr_sensor = struct_sensors(i);
0072 
0073   
0074 
0075   if ~strcmp(curr_sensor.target_id,'none')
0076 
0077     % if the sensor is on its way to something
0078 
0079     
0080 
0081     if strcmp(curr_sensor.target_id, 'home_base');
0082 
0083       % then the sensor is returning to its home base
0084 
0085       
0086 
0087       if (euclidean_distance(curr_sensor.home_base, curr_sensor.pos) < curr_sensor.max_speed)
0088 
0089     % if the sensor has reached (or approximately reached) the home base
0090 
0091     struct_sensors(i).target_id = 'none';
0092 
0093         struct_sensors(i).pos = curr_sensor.home_base;
0094 
0095       else
0096 
0097         % else it is still moving to its home base
0098 
0099     sensor_dir = curr_sensor.home_base - curr_sensor.pos;
0100 
0101     sensor_dir = sensor_dir./norm(sensor_dir);
0102 
0103     struct_sensors(i).pos = round( curr_sensor.pos + ...
0104 
0105     curr_sensor.max_speed*sensor_dir );
0106 
0107       end
0108 
0109     else
0110 
0111       % then the sensor is probably tracking a target
0112 
0113       [comp_no, plt_no] = getComp_Platoon_No(curr_sensor.target_id);
0114 
0115       target_pos = mean(struct_enemy_comps(comp_no).plt(plt_no).real_pos);
0116 
0117       
0118 
0119       if (euclidean_distance(target_pos, curr_sensor.pos) < curr_sensor.max_speed)
0120 
0121         % if close enough to the target
0122 
0123         struct_sensors(i).pos = round(target_pos);
0124 
0125       else
0126 
0127         sensor_dir = target_pos - struct_sensors(i).pos;
0128 
0129         sensor_dir = sensor_dir./norm(sensor_dir);
0130 
0131         struct_sensors(i).pos = round( curr_sensor.pos + ...
0132 
0133     curr_sensor.max_speed*sensor_dir );
0134 
0135       end
0136 
0137     end
0138 
0139   end;
0140 
0141 end;
0142 
0143 %struct_enemy_comps;
0144 
0145 %struct_sensors;
0146 
0147            
0148 
0149         
0150 
0151 
0152 
0153 
0154 
0155 
0156

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