Ejemplo n.º 1
0
def setup_scene(scene):
    """ (随机)初始化场景. """
    scene.set_params(end=50.0)
    scene.add(Jammer(name='jammer', pos=[0, 0]))
    scene.add(Radar(pos=[10, 10]))

    d, theta = random.uniform(50, 100), random.uniform(0, math.pi * 2)
    pt = (d * math.cos(theta), d * math.sin(theta))
    speed = random.uniform(3, 5)
    scene.add(Uav(name='target', tracks=[pt, [0, 0]], speed=speed, life=30.0))
Ejemplo n.º 2
0
def setup_scene(scene):
    """ (随机)初始化场景. """
    scene.set_params(end=50.0)
    # scene.add(Radar(pos=[10, 10]))

    # d, theta = random.uniform(50, 100), random.uniform(0, math.pi * 2)
    # pt = (d * math.cos(theta), d * math.sin(theta))
    # speed = random.uniform(3, 5)
    pt = [50, 50]
    speed = 5
    scene.add(Uav(name='uav', tracks=[pt, [-10, -10]], speed=speed, life=50.0, two_way=False))
Ejemplo n.º 3
0
def main():
    scene = Scenario(end=20)
    scene.step_handlers.append(print_scene)

    jammer = scene.add(Jammer(name='jammer-1', pos=[0, 0]))
    jammer.step_handlers.append(TimeEvent(times=[5, 11], evt=switch_jammer))

    scene.add(Uav(name='uav-1', tracks=[[0, 0], [10, 10]], two_way=True))

    scene.reset()
    scene.run()
Ejemplo n.º 4
0
 def test_create(self):
     uav = Uav()
     self.assertTrue(uav is not None)
Ejemplo n.º 5
0
def print_uav_value(env: Environment, uav: Uav):
    t, _ = env.time_info
    if uav.is_alive():
        print(
            f'{t:.2f} : Uav-{uav.id} - {uav.control.state} {uav.position} {uav.velocity}'
        )
Ejemplo n.º 6
0
def print_uav_value(env: Environment, uav: Uav):
    t, _ = env.time_info
    if uav.is_alive():
        print(
            f'{t:.2f} : Uav-{uav.id} - {uav.control.state} {uav.position} {uav.velocity}'
        )


def print_radar_value(env: Environment, radar: Radar):
    t, _ = env.time_info
    if radar.current_results:
        print(f'{t:.2f} : Radar-{radar.id} - {radar.current_results}')


if __name__ == '__main__':
    env = Environment()
    env.step_events.append(print_time)

    uav = env.add(Uav(track=[[0, 100, 10], [100, 100, 10]], speed=2.5))
    env.step_events.append(partial(print_uav_value, uav=uav))

    # uav2 = env.add(Uav(track=[[0, 0, 10], [10, 10, 10]], speed=2.5))
    # env.step_events.append(partial(print_uav_value, uav=uav2))

    radar = env.add(Radar(pos=[0, 0, 0], out='ar', rate=2, r_range=[None,
                                                                    150]))
    env.step_events.append(partial(print_radar_value, radar=radar))

    env.run(stop=40)
Ejemplo n.º 7
0
    else:
        print(f'{t:.2f} :')


def power_switch(env: Environment, jammer, on=None):
    t, _ = env.time_info
    if on is None:
        jammer.power_on = not jammer.power_on
    else:
        jammer.power_on = on
    print(f'{t:.2f} : jammer {jammer.power_on}')


if __name__ == "__main__":
    env = Environment()
    uav = env.add(Uav(track=[[1, 1], [11, 1], [11, 11]], speed=2.5))
    jammer1 = env.add(Jammer())
    jammer2 = env.add(Jammer(kind='gps'))

    uav_print = partial(print_uav_value, uav=uav)
    env.step_events.append(uav_print)

    # jammer1_switch = partial(power_switch, jammer=jammer1, on=None)
    # env.step_events.append(EventScheduler(evt=jammer1_switch, times=[2, 4]))

    jammer2_switch = partial(power_switch, jammer=jammer2, on=None)
    env.step_events.append(EventScheduler(evt=jammer2_switch, times=[3, 5]))

    env.run(stop=20)
    pass
Ejemplo n.º 8
0
def setup_scene(scene):
    """ 初始化场景. """
    scene.add(Uav())
    scene.add(Radar())
    scene.add(Jammer())
    scene.add(Uav())