Exemple #1
0
 def execute(self, t, dt):
     StateAgent.execute(self, t, dt)
     self.commands.append(SetPitchAngleCmd(theta_c=self.THETA_C))
     self.commands.append(
         SetHeadingGLoadCmd(psi_c=self.PSI_C +
                            self.beliefs.entity_state.psi,
                            gload_c=5))
Exemple #2
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))
    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))
Exemple #4
0
    def execute(self, t, dt):
        StateAgent.execute(self, t, dt)

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

        # Issue command to match threat altitude
        entity = self.beliefs.entity_state
        threat = self.beliefs.threat_state
        if not ut.is_close(threat.z, entity.z_c):
            self.commands.append(SetAltitudeCmd(threat.z, 7.0))
Exemple #5
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))
Exemple #6
0
    def execute(self, t, dt):
        StateAgent.execute(self, t, dt)

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

        # Check whether we are within sensor range
        entity = self.beliefs.entity_state
        threat = self.beliefs.threat_state
        distance = ut.distance(entity.pos_2d(), threat.pos_2d())
        sensor_max = self.beliefs.entity_state.sensor_state.max_range
        if distance < sensor_max:
            if not ut.is_close(entity.desired_v, threat.v):
                # Issue command to match threat speed
                self.commands.append(SetSpeedCmd(threat.v))
Exemple #7
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))
    def execute(self, t, dt):
        StateAgent.execute(self, t, dt)

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

        # Determine heading parallel to flight path of threat
        entity = self.beliefs.entity_state
        threat = self.beliefs.threat_state
        parallel_heading = ut.reciprocal_heading(threat.heading)

        # Issue the change heading command
        if not ut.is_close(parallel_heading, entity.desired_heading,
                abs_tol=1.0):
            # self.commands.append(SetHeadingCmd(parallel_heading))
            # TODO: extract GLoad, calculate based on desired displacement
            self.commands.append(SetHeadingGLoadCmd(psi_c=parallel_heading, gload_c=5))
Exemple #9
0
 def execute(self, t, dt):
     StateAgent.execute(self, t, dt)
     self.commands.append(SetPitchAngleCmd(theta_c=self.THETA_C))
Exemple #10
0
 def execute(self, t, dt):
     StateAgent.execute(self, t, dt)
     self.commands.append(SetFlyLevelCmd())