예제 #1
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))
예제 #2
0
 def test_compound6(self):
     location = easy_Odom(x=0, y=0, v=0.0, heading=0.0, frame='map')
     goal = easy_Odom(x=-2.0, y=-1.0, v=0.0, heading=math.pi/4.0, frame='map')
     along, off, heading = self.driver_obj.calc_errors(location=location, goal=goal)
     self.assertTrue(is_close(along, 1.5*math.sqrt(2.0)))
     self.assertTrue(is_close(off, -0.5*math.sqrt(2.0)))
     self.assertTrue(is_close(heading, -math.pi/4.0))
예제 #3
0
 def test_compound1(self):
     location = easy_Odom(x=0, y=0, v=0.0, heading=0.0, frame='map')
     goal = easy_Odom(x=1.0, y=1.0, v=0.0, heading=0.0, frame='map')
     along, off, heading = self.driver_obj.calc_errors(location=location, goal=goal)
     self.assertTrue(is_close(along, -1.0))
     self.assertTrue(is_close(off, -1.0))
     self.assertTrue(is_close(heading, 0.0))
예제 #4
0
    def evaluate(self, obj):
        sub_fighter = getattr(obj, self.subject)
        obj_fighter = getattr(obj, self.object)

        # # Measure 3D Range
        # range = utils.get_range( sub_fighter.fcs.platform, obj_fighter.fcs.platform )
        # if range > self.max_range :
        #     self.measures['t'].append( obj.current_time)
        #     self.measures['score'].append( 0.0 )
        #     return
        #
        # # Measure 3D Target Aspect Angle
        # taa = utils.get_aspect_angle( sub_fighter.fcs.platform, obj_fighter.fcs.platform )
        # if (taa < 180.0 - self.max_angle) and (taa > 180.0 + self.max_angle) :
        #     self.measures['t'].append( obj.current_time)
        #     self.measures['score'].append( 0.0 )
        #     return

        if self.subject == 'viper' and utils.is_close(obj.current_time % 1, 1):
            self.check_is_behind(sub_fighter, obj_fighter)
            self.check_range(sub_fighter, obj_fighter)
            self.check_attack_angle(sub_fighter, obj_fighter)
            self.check_reverse_attack_angle(sub_fighter, obj_fighter)
            self.check_altitude(sub_fighter, obj_fighter)
            self.check_speed(sub_fighter, obj_fighter)
            sub_fighter.set_score(self.get_score())

        if self.subject == 'cobra' and utils.is_close(obj.current_time % 1, 1):
            self.check_is_behind(sub_fighter, obj_fighter)
            self.check_range(sub_fighter, obj_fighter)
            self.check_attack_angle(sub_fighter, obj_fighter)
            self.check_reverse_attack_angle(sub_fighter, obj_fighter)
            self.check_altitude(sub_fighter, obj_fighter)
            self.check_speed(sub_fighter, obj_fighter)
            sub_fighter.set_score(self.get_score())
예제 #5
0
 def test_aheady_target1(self):
     # print('test_ahead_target')
     location = easy_Odom(x=0, y=0, v=0.0, heading=math.pi/2.0, frame='map')
     goal = easy_Odom(x=0.0, y=1.0, v=0.0, heading=math.pi/2.0, frame='map')
     along, off, heading = self.driver_obj.calc_errors(location=location, goal=goal)
     self.assertTrue(is_close(along, -1.0))
     self.assertTrue(is_close(off, 0))
     self.assertTrue(is_close(heading, 0))
예제 #6
0
 def test_behindx_target3(self):
     # print('test_behind_target')
     location = easy_Odom(x=0, y=0, v=0.0, heading=0.0, frame='map')
     goal = easy_Odom(x=-3.0, y=0, v=0.0, heading=0.0, frame='map')
     along, off, heading = self.driver_obj.calc_errors(location=location, goal=goal)
     self.assertTrue(is_close(along, 3.0))
     self.assertTrue(is_close(off, 0))
     self.assertTrue(is_close(heading, 0))
예제 #7
0
    def test_parsing(self, ethane_system_topology):
        nb_force = openmm.NonbondedForce()
        nb_force.addParticle(1, 2, 3)
        my_ommp = Ommperator(ethane_system_topology[0], ethane_system_topology[1])
        my_nb_ommp = NonbondedForceOmmperator(my_ommp, nb_force, 0)

        assert my_nb_ommp.charge == nb_force.getParticleParameters(0)[0]
        assert my_nb_ommp.sigma == nb_force.getParticleParameters(0)[1]
        assert my_nb_ommp.epsilon == nb_force.getParticleParameters(0)[2]
        
        assert is_close(my_nb_ommp.charge, 1*unit.elementary_charge)
        assert is_close(my_nb_ommp.sigma, 2*unit.nanometer)
        assert is_close(my_nb_ommp.epsilon, 3*unit.kilojoule_per_mole)
예제 #8
0
 def test_linear_veloicty5(self):
     along = -0.5
     off = 0.0
     ang_vel = 0.0
     goal_vel = 0.0
     lin_vel = self.driver_obj.calc_linear_velocity(along, off, ang_vel, goal_vel)
     self.assertTrue(is_close(lin_vel, 0.5))
예제 #9
0
 def test_linear_veloicty3(self):
     along = 0.0
     off = 0.0
     ang_vel = 0.0
     goal_vel = -self.driver_obj.max_v
     lin_vel = self.driver_obj.calc_linear_velocity(along, off, ang_vel, goal_vel)
     self.assertTrue(is_close(lin_vel, -self.driver_obj.max_v))
예제 #10
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))
예제 #11
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))
예제 #12
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))
예제 #13
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))
예제 #14
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))
예제 #15
0
    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))
예제 #16
0
              ).flatten()

# Iterate raising to the power
zs = initial_zs
zs = ne.evaluate('initial_zs**zs')
for i in tqdm(range(iterations)):
    zs = ne.re_evaluate()

final_zs = np.copy(zs)

# Record periodicities
period = np.zeros_like(final_zs, dtype=np.int32)
for i in tqdm(range(record_history_length)):
    zs = ne.evaluate('initial_zs**zs')

    close = is_close(final_zs, zs, atol=1e-6)
    # If we've found a repeat for a point we've not previously
    # found a repeat for, record the period
    period[np.logical_and(period == 0, close)] = i + 1

# Image array, initially white
rgb = np.ones((h_resolution * v_resolution, 3)) * 255
# Diverging points are black
rgb[~np.isfinite(zs)] = np.array([0, 0, 0])
# Colour points for each periodicity
for i in range(1, record_history_length, 1):
    rgb[period == i] = get_colour(i - 1)

# Save the image
im = Image.fromarray(
    rgb.astype(np.uint8).reshape(v_resolution, h_resolution, 3))
예제 #17
0
 def test_zero(self):
     heading = 0
     offset = 0
     adjusted_heading = self.driver_obj.calc_adjusted_heading(heading, offset)
     self.assertTrue(is_close(adjusted_heading, 0.0))
예제 #18
0
 def test_neg_heading(self):
     heading = -1.0
     offset = 0
     adjusted_heading = self.driver_obj.calc_adjusted_heading(heading, offset)
     self.assertTrue(is_close(adjusted_heading, heading))
예제 #19
0
 def test_pure_offset2(self):
     heading = 0
     offset = -.5
     adjusted_heading = self.driver_obj.calc_adjusted_heading(heading, offset)
     self.assertTrue(adjusted_heading < 0.0)
     self.assertTrue(is_close(adjusted_heading, -.75*math.pi/2, 4))
예제 #20
0
 def test_angular_vel2(self):
     adjusted_heading = 0.5
     ang_vel = self.driver_obj.calc_angular_velocity(adjusted_heading)
     self.assertTrue(ang_vel < 0.0)
     self.assertTrue(is_close(ang_vel, -0.5))
예제 #21
0
 def test_angular_vel7(self):
     adjusted_heading = -100.0
     ang_vel = self.driver_obj.calc_angular_velocity(adjusted_heading)
     self.assertTrue(ang_vel > 0.0)
     self.assertTrue(is_close(ang_vel, self.driver_obj.max_omega))
예제 #22
0
 def test_angular_vel5(self):
     adjusted_heading = -0.25
     ang_vel = self.driver_obj.calc_angular_velocity(adjusted_heading)
     self.assertTrue(ang_vel > 0.0)
     self.assertTrue(is_close(ang_vel, 0.4333), 3)