Esempio n. 1
0
    def execute(self, t, dt):
        StateAgent.execute(self, t, dt)

        # Execute state behaviour only on first tick after entering state
        if self._first_tick:
            self._first_tick = False

            # Check threat is detected
            if not self.beliefs.threat_state:
                return

            # Calculate bearing from entity to threat and the reverse
            entity = self.beliefs.entity_state
            threat = self.beliefs.threat_state
            threat_bearing = ut.relative_bearing(entity.x, entity.y, threat.x,
                                                 threat.y)
            entity_bearing = ut.reciprocal_heading(threat_bearing)

            # Add or subtract the turn angle depending on whether we are
            # clockwise or counter-clockwise from the threat's heading, so that
            # we turn away from the threat not across it
            if ut.is_angle_ccw(threat.heading, entity_bearing):
                new_heading = threat_bearing + self.TURN_ANGLE
            else:
                new_heading = threat_bearing - self.TURN_ANGLE
            new_heading = ut.constrain_360(new_heading)

            # Issue the change heading command
            if not ut.is_close(
                    new_heading, entity.desired_heading, abs_tol=1.0):
                # self.commands.append(SetHeadingCmd(new_heading))
                # TODO: extract GLoad, calculate based on desired displacement
                self.commands.append(
                    SetHeadingGLoadCmd(psi_c=new_heading, gload_c=5))
Esempio n. 2
0
    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))
Esempio n. 3
0
    def execute(self, t, dt):
        StateAgent.execute(self, t, dt)

        if self.beliefs.threat_state:
            # Determine the bearing to the threat aircraft
            entity = self.beliefs.entity_state
            threat = self.beliefs.threat_state
            threat_bearing = utils.relative_bearing(entity.x, entity.y,
                    threat.x, threat.y)

            # Issue the change heading command
            if not ut.is_close(threat_bearing, entity.desired_heading):
                self.commands.append(SetHeadingGLoadCmd(psi_c=threat_bearing,
                                                        gload_c=5))
Esempio n. 4
0
    def execute(self, t, dt):
        StateAgent.execute(self, t, dt)

        # Check threat is detected
        if not self.beliefs.threat_state:
            return

        # Determine the bearing to the threat aircraft
        entity = self.beliefs.entity_state
        threat = self.beliefs.threat_state
        threat_bearing = ut.relative_bearing(entity.x, entity.y,
                threat.x, threat.y)

        # Issue command to turn toward threat
        if not ut.is_close(threat_bearing, entity.desired_heading):
            self.commands.append(SetHeadingGLoadCmd(psi_c=threat_bearing,
                                                    gload_c=10))
Esempio n. 5
0
    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