Beispiel #1
0
    def run(self):
        self.up_plane_process.start()
        self.down_plane_process.start()
        tee = self.periscope.target

        exit_app = False
        iteration = 0
        while not exit_app:
            p1_intersect = self.periscope.laser.intersect_plane(self.periscope.mirror_down.triangle)
            p2_intersect = self.periscope.laser.reflect_plane(self.periscope.mirror_down.triangle).\
                intersect_plane(self.periscope.mirror_up.triangle)
            p_aim = self.periscope.ray_to_aim().intersect_plane(
                Triangle(Point3d(tee.location.x, 0.5, 0.2),
                         Point3d(tee.location.x, 0.4, 0.1),
                         Point3d(tee.location.x, 0.3, 0.5)
                         ))
            self.renderer.render(p1_intersect, p2_intersect, tee, p_aim)

            exit_app, need_rebuild = self.__move_target()

            if need_rebuild:
                self.down_plane_queue.put(self.periscope.target)
                self.up_plane_queue.put(self.periscope.target)

                self.update_log(iteration, p_aim)
                iteration += 1

            self.apply_changes(self.periscope.mirror_down.triangle, self.down_plane_points)
            self.apply_changes(self.periscope.mirror_up.triangle, self.up_plane_points)

        self.up_plane_process.terminate()
        self.down_plane_process.terminate()
        self.write_log()
        exit()
Beispiel #2
0
    def __init__(self, input_model: str = '2d'):
        self.log_list = []
        pygame.init()
        self.input_model = input_model
        config = parse(input_model)

        self.periscope: Periscope = Periscope(config)
        p_target = self.periscope.ray_to_aim().intersect_plane(
            Triangle(Point3d(0.2, 0.5, 0.2),
                     Point3d(0.2, 0.4, 0.1),
                     Point3d(0.2, 0.3, 0.5)
                     ))
        tee = Target(p_target, config["target_radius"])
        self.periscope.set_target(tee)

        self.renderer = Renderer(self.periscope)

        # Shared memory
        self.down_plane_points = mp.Array('d', 6)
        self.up_plane_points = mp.Array('d', 6)
        self.__init_share_memory()

        self.up_plane_queue = mp.Queue()
        self.down_plane_queue = mp.Queue()

        self.up_plane_process: mp.Process = mp.Process(
            target=DirectAlgorithm.plane_direct_process,
            args=(self.up_plane_queue, self.up_plane_points, self.periscope, MirrorLocation.UP))
        self.down_plane_process: mp.Process = mp.Process(
            target=DirectAlgorithm.plane_direct_process,
            args=(self.down_plane_queue, self.down_plane_points, self.periscope, MirrorLocation.DOWN))
Beispiel #3
0
    def backray(self, p3_intersect, p_aim, delta):
        new_taget = Point3d(p_aim.x + delta, p_aim.y, p_aim.z)
        ret_ray = Ray(new_taget, Vector(p3_intersect, p_aim))

        p3_new = ret_ray.intersect_plane(self.periscope.mirror_3.triangle)

        p2_new = ret_ray.reflect_plane(self.periscope.mirror_3.triangle). \
            intersect_plane(self.periscope.mirror_up.triangle)

        p1_new = ret_ray.reflect_plane(self.periscope.mirror_3.triangle). \
            reflect_plane(self.periscope.mirror_up.triangle).intersect_plane(self.periscope.mirror_down.triangle)

        target = ret_ray.reflect_plane(self.periscope.mirror_3.triangle). \
            reflect_plane(self.periscope.mirror_up.triangle).reflect_plane(self.periscope.mirror_down.triangle).dir

        p5 = Point3d(p1_new.x + 0.25 * target.x, p1_new.y + 0.25 * target.y,
                     p1_new.z + 0.25 * target.z)

        return (p5.get_point(), p1_new.get_point(), p2_new.get_point(),
                p3_new.get_point(), new_taget.get_point(), p_aim.get_point())
Beispiel #4
0
 def apply_changes(plane: Triangle, arr: mp.Array):
     plane.point_b = Point3d(arr[0], arr[1], arr[2])
     plane.point_c = Point3d(arr[3], arr[4], arr[5])
Beispiel #5
0
    def __init__(
        self,
        input_model: str = '2d',
        algorithm: SolveAlgorithm = SolveAlgorithm.DIRECT,
        mode: str = '',
    ):
        self.log_list = []
        pygame.init()
        self.input_model = input_model
        self.mode = mode
        config = parse(input_model)

        self.periscope: Periscope = Periscope(config)
        p_target = self.periscope.ray_to_aim().intersect_plane(
            Triangle(Point3d(0.4, 0.7, 0.2), Point3d(0.5, 0.4, 0.1),
                     Point3d(0.2, 0.6, 0.5)))
        p_target = Point3d(0.62, 0.66, 0)
        tee = Target(p_target, config["target_radius"])
        self.periscope.set_target(tee)

        self.renderer = Renderer(self.periscope)

        # Shared memory
        self.down_plane_points = mp.Array('d', 6)
        self.up_plane_points = mp.Array('d', 6)
        self.plane_3_points = mp.Array('d', 6)
        self.__init_share_memory()

        self.up_plane_queue = mp.Queue()
        self.down_plane_queue = mp.Queue()
        self.plane_3_queue = mp.Queue()

        if algorithm == SolveAlgorithm.DIRECT:
            self.up_plane_process: mp.Process = mp.Process(
                target=DirectAlgorithm.plane_direct_process,
                args=(self.up_plane_queue, self.up_plane_points,
                      self.periscope, MirrorLocation.UP))
            self.down_plane_process: mp.Process = mp.Process(
                target=DirectAlgorithm.plane_direct_process,
                args=(self.down_plane_queue, self.down_plane_points,
                      self.periscope, MirrorLocation.DOWN))
            self.plane_3_process: mp.Process = mp.Process(
                target=DirectAlgorithm.plane_direct_process,
                args=(self.plane_3_queue, self.plane_3_points, self.periscope,
                      MirrorLocation.THIRD))
        else:  # algorithm == SolveAlgorithm.NEURAL_NET:
            from keras.models import load_model
            from src.algorithms.net import NeuralNetAlgorithm
            model = load_model(
                str(get_project_root()) + '\\src\\neuralnet\\' +
                self.input_model + '_model.h5')
            self.up_plane_process: mp.Process = mp.Process(
                target=NeuralNetAlgorithm.run,
                args=(self.up_plane_queue, self.up_plane_points,
                      self.periscope, MirrorLocation.UP, model))
            self.down_plane_process: mp.Process = mp.Process(
                target=NeuralNetAlgorithm.run,
                args=(self.down_plane_queue, self.down_plane_points,
                      self.periscope, MirrorLocation.DOWN, model))
            self.plane_3_process: mp.Process = mp.Process(
                target=NeuralNetAlgorithm.run,
                args=(self.plane_3_queue, self.plane_3_points, self.periscope,
                      MirrorLocation.THIRD, model))
Beispiel #6
0
    def run(self):
        self.up_plane_process.start()
        self.down_plane_process.start()
        tee = self.periscope.target
        prev_tee = self.periscope.prev_target

        str_down = f'sending 1st target coord: {self.periscope.target.get_description()} to down plane process by ' + mp.process.current_process(
        ).name + '\n'
        print(str_down)
        with open('первый_опыт.txt', 'a') as f:
            f.write(str_down)
        self.down_plane_queue.put(self.periscope.target)  # send

        str_up = f'sending 1st target coord: {self.periscope.target.get_description()} to up plane process by ' + mp.process.current_process(
        ).name + '\n'
        print(str_up)
        with open('первый_опыт.txt', 'a') as f:
            f.write(str_up)
        self.up_plane_queue.put(self.periscope.target)  # send

        exit_app = False
        iteration = 0
        max_iteration = 4
        sleep_time = 2
        while not exit_app and iteration <= max_iteration:

            p1_intersect = self.periscope.laser.intersect_plane(
                self.periscope.mirror_down.triangle)
            p2_intersect = self.periscope.laser.reflect_plane(self.periscope.mirror_down.triangle). \
                intersect_plane(self.periscope.mirror_up.triangle)
            p_aim = self.periscope.ray_to_aim().intersect_plane(
                Triangle(Point3d(tee.location.x, 0.5, 0.2),
                         Point3d(tee.location.x, 0.4, 0.1),
                         Point3d(tee.location.x, 0.3, 0.5)))
            self.renderer.render(p1_intersect, p2_intersect, tee, prev_tee,
                                 p_aim)

            if iteration == max_iteration:
                sleep(sleep_time)
                break

            self.update_log(iteration, p_aim, 'before move')
            exit_app, need_rebuild = self.__move_target(iteration)

            str_down = f'sending target coord: {self.periscope.target.get_description()} to down plane process by ' + mp.process.current_process(
            ).name + '\n'
            print(str_down)
            with open('первый_опыт.txt', 'a') as f:
                f.write(str_down)
            self.down_plane_queue.put(self.periscope.target)  # send

            str_up = f'sending target coord: {self.periscope.target.get_description()} to up plane process by ' + mp.process.current_process(
            ).name + '\n'
            print(str_up)
            with open('первый_опыт.txt', 'a') as f:
                f.write(str_up)
            self.up_plane_queue.put(self.periscope.target)  # send

            self.update_log(iteration, p_aim, 'after move')
            iteration += 1

            self.apply_changes(self.periscope.mirror_down.triangle,
                               self.down_plane_points)
            self.apply_changes(self.periscope.mirror_up.triangle,
                               self.up_plane_points)
            # update log
            sleep(sleep_time)

        self.up_plane_process.terminate()
        self.down_plane_process.terminate()
        self.write_log()
        exit()