Ejemplo n.º 1
0
def main(params: ClientParams):

    logger = ss.create_logger(params.log_fname_const, params.log_level,
                              'mtmind')
    logger.info('mtmind running! Log level set to {}'.format(params.log_level))
    image_path = params.google_path + "mt_mind\\captured_images\\"
    logger.debug(image_path)

    logger.debug("loading learner....")
    mtmind = load_learner(params.model_path, params.model_fname)
    logger.info("Learner loaded!")

    while True:
        t_start = time.perf_counter()

        if params.pipe_recv.poll(0):
            part: ss_classes.PartInstance = params.pipe_recv.recv()
            pred: Category = mtmind.predict(part.part_image)
            part.category_name = pred[0].obj
            part.server_status = 'mtm_done'
            params.pipe_send.send(part)

        t_stop = time.perf_counter()
        t_duration = t_stop - t_start
        if t_duration < params.tick_rate:
            time.sleep(params.tick_rate - t_duration)
Ejemplo n.º 2
0
 def __init__(self, init: ServerInit, bb: BbClient):
     self.params = init
     self.part_list = []
     self.sort_log = ss.create_logger(
         self.params.server_sort_log_file_const, 'INFO', "sort_log")
     self.logger = self.params.logger
     self.bb = bb
     self.pipes = init.pipes
Ejemplo n.º 3
0
def classifist(client_params: ClientParams):
    """ Assigns parts to bins """

    # TODO: Eliminate SQL and replace this with a config file.

    logger = ss.create_logger(client_params.log_fname_const,
                              client_params.log_level, 'classifist')
    logger.info('classifist running! Log level set to {}'.format(
        client_params.log_level))
    while True:
        t_start = time.perf_counter()

        if client_params.pipe_recv.poll(0):

            read_part: ss_classes.PartInstance = client_params.pipe_recv.recv()
            sqconn = sqlite3.connect(client_params.server_db_fname_const)
            sqcur = sqconn.cursor()

            # evaluate query
            for part_bin in sqcur.execute("SELECT * FROM table_bin_config"):
                if part_bin[1] == 'part':
                    if part_bin[2] == str(
                            read_part.part_number
                    ):  # assume all values are strings, just to be safe!
                        read_part.bin_assignment = part_bin[0]
                        read_part.server_status = 'cf_done'
                        client_params.pipe_send.send(read_part)
                        break

                if part_bin[1] == 'category_name':
                    if part_bin[2] == str(
                            read_part.category_name
                    ):  # assume all values are strings, just to be safe!
                        read_part.bin_assignment = part_bin[0]
                        read_part.server_status = 'cf_done'
                        client_params.pipe_send.send(read_part)
                        break
            else:
                read_part.bin_assignment = 0
                read_part.server_status = 'cf_done'
                client_params.pipe_send.send(read_part)

            sqconn.close()

        t_stop = time.perf_counter()
        t_duration = t_stop - t_start
        if t_duration < 0.017:
            time.sleep(0.017 - t_duration)
Ejemplo n.º 4
0
def mt_mind_sim(client_params: ClientParams):
    """Simulates behavior of the MTMind by adding a random part number and category to a part instance"""

    logger = ss.create_logger(client_params.log_fname_const,
                              client_params.log_level, 'mt_mind')
    logger.info('part sim running!')
    import random

    while True:
        t_start = time.perf_counter()
        if client_params.pipe_recv.poll(0):

            part = client_params.pipe_recv.recv()
            part.part_number = random.randint(3001, 3002)

            category = random.randint(1, 4)
            if category == 1:
                part_category = 5  # brick
                category_name = 'brick'
            elif category == 2:
                part_category = 26  # plate
                category_name = 'plate'

            elif category == 3:
                part_category = 21  # cone
                category_name = 'cone'

            elif category == 4:
                part_category = 37  # tile
                category_name = 'tile'

            else:
                part_category = -1
                category_name = 'null'

            part.category_name = category_name
            part.part_color = str(random.randint(1, 20))
            part.server_status = 'mtm_done'
            client_params.pipe_send.send(part)
            # print("mtm sim just ident'd part {0}".format(part.instance_id))

        t_stop = time.perf_counter()
        t_duration = t_stop - t_start
        if t_duration < 0.017:
            time.sleep(0.017 - t_duration)
Ejemplo n.º 5
0
def dev_mule(pipe_me_recv, pipe_me_send):
    """ Dummy client for testing and R&D """

    logger = ss.create_logger('log\\log_part_instance_sim.txt', 'INFO',
                              'dev_mule')
    logger.info('part sim running!')
    time.sleep(20)
    while True:
        t_start = time.perf_counter()
        if pipe_me_recv.poll(0) == True:
            part = pipe_me_recv.recv()
            print(part.instance_id)
            print(part.part_number)
            print('------------------------------------')

        t_stop = time.perf_counter()
        t_duration = t_stop - t_start
        if t_duration < 0.017:
            time.sleep(0.017 - t_duration)
Ejemplo n.º 6
0
    def __init__(self, init_params: ClientParams):

        # create logger
        self.logger = create_logger(init_params.log_fname_const, init_params.log_level, "Taxidermist")

        # path to google drive and pipes
        self.pipe_recv = init_params.pipe_recv
        self.pipe_send = init_params.pipe_send
        self.google_path = init_params.google_path

        # openCV Object detection properties
        self.min_contour_size = 1000                                  # the minimum contour size that will be included in the crop
        self.fg_bg = cv2.createBackgroundSubtractorMOG2()             # setup the background subtractor
        self.fg_learningRate = 0.002                                  # background subtractor learning rate
        self.dilate_kernel = cv2.getStructuringElement(2, (4, 7))     # Dilation kernel
        self.font = cv2.FONT_HERSHEY_SIMPLEX                          # Font for drawing part numbers on camera feed

        # Edge mask for conveyor belt. Used to eliminate detection of the belt edges.
        mask = cv2.imread(init_params.belt_mask, cv2.IMREAD_GRAYSCALE)                  # load image
        belt_mask = cv2.threshold(mask, 127, 255, cv2.THRESH_BINARY)[1]
        self.belt_mask = np.int8(belt_mask)

        # path to video file, if we are not using the camera.
        # TODO: move this to settings.ini
        self.vid_file = self.google_path + "\\assets\\taxidermist\\video\\multi.flv"

        # Setup video feed
        self.video_source = init_params.video_source
        self.view_video = init_params.view_video
        if init_params.video_source == "cam":
            self.logger.info("params.video_source == cam")
            self.video, self.video_shape = configure_webcam()
        elif init_params.video_source == "vid":
            self.logger.info("params.video_source == vid")
            self.video, self.video_shape = self.configure_video_file()
        else:
            self.logger.critical("Invalid 'video_source' in parameter object. Expected 'cam' or 'vid', got {}. Check settings.ini".format(params.video_source))
            exit(2)

        # log that we're finished
        self.logger.debug("taxi params created successfully")
Ejemplo n.º 7
0
def stand_alone(client_params: ClientParams):
    """ Only used for performance testing """

    image_path = client_params.google_path + "mt_mind\\captured_images\\"
    print(image_path)
    logger = ss.create_logger(client_params.log_fname_const,
                              client_params.log_level, 'mtmind')
    logger.info('mtmind running! Log level set to {}'.format(
        client_params.log_level))

    mtmind = load_learner(client_params.model_path, client_params.model_fname)
    image1 = open_image(
        "C:\\Users\Development\\Google Drive\\software_dev\\the_shape_sifter\\assets\\images\\wheels\\172616422709.png"
    )
    image2 = open_image(
        "C:\\Users\Development\\Google Drive\\software_dev\\the_shape_sifter\\assets\\images\\wheels\\172616422709.png"
    )
    image3 = open_image(
        "C:\\Users\Development\\Google Drive\\software_dev\\the_shape_sifter\\assets\\images\\wheels\\172616422709.png"
    )

    ss_classes.PartInstance()

    input("Press Enter to continue...")
    t_start = time.perf_counter()
    result = mtmind.predict(image1)
    t_stop = time.perf_counter()
    print(t_stop - t_start)
    print(result[0])

    input("Press Enter to continue...")
    t_start = time.perf_counter()
    result = mtmind.predict(image2)
    t_stop = time.perf_counter()
    print(t_stop - t_start)
    print(result)

    input("Press Enter to continue...")
    t_start = time.perf_counter()
    result = mtmind.predict(image3)
    t_stop = time.perf_counter()
    print(t_stop - t_start)
    print(result)

    input("Press Enter to continue...")
    t_start = time.perf_counter()
    result = mtmind.predict(image1)
    t_stop = time.perf_counter()
    print(t_stop - t_start)
    print(result)

    input("Press Enter to continue...")
    t_start = time.perf_counter()
    result = mtmind.predict(image2)
    t_stop = time.perf_counter()
    print(t_stop - t_start)
    print(result)

    input("Press Enter to continue...")
    t_start = time.perf_counter()
    result = mtmind.predict(image3)
    t_stop = time.perf_counter()
    print(t_stop - t_start)
    print(result)
Ejemplo n.º 8
0
    def __init__(self):

        # get google drive directory
        self.google_path = self.get_google_drive_path()

        # declarations and initializations. All objects ending with _const are NOT to be modified at run time!
        self.server_config_file_const = self.google_path + '\\settings.ini'
        self.server_log_file_const = self.google_path + '\\log\\log_server.txt'
        self.server_sort_log_file_const = self.google_path + '\\log\\sort_log.txt'
        self.server_db_fname_const = self.google_path + '\\db\\shape_sifter.sqlite'
        self.server_db_template_const = self.google_path + '\\db\\shape_sifter_template.sqlite'
        self.part_log_fname_const = self.google_path + '\\log\\part_log.txt'
        self.active_part_table_const = (
            'active_part_db',
        )  # the f**k is this for? I think it's the name of the DB?
        self.dummy_image = open_image(self.google_path + '\\dummy.png')
        self.prev_id = ''
        self.bb_message_len = 29
        self.pipes = Pipes()

        # create logger, default debug level. Level will be changed once config file is loaded
        self.logger = ss.create_logger(self.server_log_file_const, 'DEBUG')

        # TODO: Move this somewhere else! Make a function out of it along with the next block below
        # if config file doesn't exist, create one. Defaults are in shape_sifter_tools.py
        if not isfile(self.server_config_file_const):
            self.logger.info("config file doesn't exist. Creating...")
            self.create_server_config()

        # load config file and assign values.
        # TODO: Turn this into a function that verifies the settings and returns an object.
        # TODO: It should also handle key exceptions. It should also log it's actions. I should also do some of these TODOs someday.
        self.server_config = self.load_server_config()

        self.global_tick_rate = float(
            self.server_config['server']['global_tick_rate'])

        self.server_log_level = self.server_config['server']['log_level']
        self.server_bb_ack_timeout = self.server_config['server'][
            'bb_ack_timeout']

        self.taxi_log_level = self.server_config['taxi']['log_level']
        self.taxi_belt_mask = self.google_path + "\\assets\\taxidermist\\" + self.server_config[
            'taxi']['belt_mask']
        self.taxi_video_source = self.server_config['taxi']['video_source']
        self.taxi_view_video = self.server_config['taxi']['view_video']

        self.mtm_log_level = self.server_config['mtm']['log_level']
        self.mtm_model_path = self.server_config['mtm']['model_path']
        self.mtm_model_fname = self.server_config['mtm']['model_fname']

        self.cf_log_level = self.server_config['cf']['log_level']

        self.suip_log_level = self.server_config['suip']['log_level']
        self.suip_list_len = int(self.server_config['suip']['list_len'])

        self.bb_com_port = self.server_config['bb']['com_port']
        self.bb_baud_rate = int(self.server_config['bb']['baud_rate'])
        self.bb_skip_handshake = self.server_config['bb']['skip_handshake']
        self.bb_log_level = self.server_config['bb']['log_level']
        self.bb_timeout = self.server_config['bb']['timeout']
        self.bb_test_run = bool(int(self.server_config['bb']['test_run']))

        # replace logger with level set by config file
        self.logger = ss.create_logger(self.server_log_file_const,
                                       self.server_log_level, 'server')
        self.part_log = ss.create_logger(self.part_log_fname_const, 'DEBUG',
                                         'part_log')