def execute(self, t, dt): StateAgent.execute(self, t, dt) # Check threat is detected if not self.beliefs.threat_state: return entity = self.beliefs.entity_state threat = self.beliefs.threat_state # Check if the threat heading is exactly reciprocal if ut.is_reciprocal(entity.heading, threat.heading): # Issue command to turn toward the threat aircraft threat_bearing = ut.relative_bearing(entity.x, entity.y, threat.x, threat.y) if not ut.is_close(entity.desired_heading, threat_bearing, abs_tol=1.0): # self.commands.append(SetHeadingCmd(threat_bearing)) # TODO: extract GLoad, calculate based on desired displacement self.commands.append(SetHeadingGLoadCmd(psi_c=threat_bearing, gload_c=5)) elif not ut.is_close(entity.desired_heading, threat.heading): # Issue command to turn to match the threat aircraft heading # self.commands.append(SetHeadingCmd(threat.heading)) # TODO: extract GLoad, calculate based on desired displacement self.commands.append(SetHeadingGLoadCmd(psi_c=threat.heading, gload_c=5)) # Adjust the entity speed to avoid overshooting if (entity.desired_v > threat.v and not ut.is_close(entity.desired_v, threat.v)): distance = ut.distance(entity.pos_2d(), threat.pos_2d()) if ut.metres_to_nautical_miles(distance) <= \ self.NO_CLOSER_RANGE: # Issue command to match threat speed self.commands.append(SetSpeedCmd(threat.v))
def process_state(self, t, dt): StateAgent.process_state(self, t, dt) if self.beliefs.threat_state: entity = self.beliefs.entity_state threat = self.beliefs.threat_state # Check whether threat is aligned with aircraft taa = ut.target_aspect_angle(entity.x, entity.y, threat.x, threat.y, threat.heading) bearing_to_entity = ut.relative_bearing(threat.x, threat.y, entity.x, entity.y) bearing_offset = abs(threat.heading - bearing_to_entity) if bearing_offset > self.MAX_ALIGNMENT_DIFF: # Threat not aligned so don't proceed to next state return # Check whether at turn range from threat distance = ut.distance(entity.pos_2d(), threat.pos_2d()) if ut.metres_to_nautical_miles(distance) <= self.TURN_RANGE: self.transition_request = FlyRelativeBearing
def process_state(self, t, dt): StateAgent.process_state(self, t, dt) if self.beliefs.threat_state: entity = self.beliefs.entity_state threat = self.beliefs.threat_state distance = ut.distance(entity.pos_2d(), threat.pos_2d()) # Check whether the conversion point has been reached if ut.metres_to_nautical_miles(distance) <= self.CONVERSION_RANGE: self.transition_request = Converting # Check if still closing with threat if self._last_range: if distance > self._last_range: # Not closing with threat so return to default state self.transition_request = PureIntercept self._last_range = distance else: # No threats detected so return to default state self.transition_request = PureIntercept