当前位置: 首页>>代码示例>>Python>>正文


Python Motor.find_home方法代码示例

本文整理汇总了Python中motor.Motor.find_home方法的典型用法代码示例。如果您正苦于以下问题:Python Motor.find_home方法的具体用法?Python Motor.find_home怎么用?Python Motor.find_home使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在motor.Motor的用法示例。


在下文中一共展示了Motor.find_home方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from motor import Motor [as 别名]
# 或者: from motor.Motor import find_home [as 别名]

#.........这里部分代码省略.........
                                           0.15,
                                           10,
                                           self.__io_manager,
                                           verbose)

        self.__io_manager.protect_pin(MOTOR_PINS['item_movement_control'])
        self.__io_manager.protect_pin(MOTOR_PINS['item_movement_direction'])
        self.__io_manager.protect_pin(MOTOR_PINS['item_movement_limit_switch'])

        self.__tray_movement_motor = Motor(MOTOR_PINS['tray_movement_control'],
                                           MOTOR_PINS['tray_movement_direction'],
                                           TRAY_MOVEMENT_CONVEYOR_STEP_INTERVAL,
                                           None,
                                           MOTOR_PINS['tray_movement_limit_switch'],
                                           0.15,
                                           10,
                                           0.15,
                                           10,
                                           self.__io_manager,
                                           verbose)

        self.__io_manager.protect_pin(MOTOR_PINS['tray_movement_control'])
        self.__io_manager.protect_pin(MOTOR_PINS['tray_movement_direction'])
        self.__io_manager.protect_pin(MOTOR_PINS['tray_movement_limit_switch'])

	self.current_loop_done = 1
	self.__calibrate_motors()

    def main_cycle(self):
        self.__wait_for_closed_door()
        if not self.current_loop_done:
            self.__io_manager.output('lock_door', IOManager.HIGH)  # Lock door
            item_list = self.__generate_item_list()
            if not item_list:
                self.__log('No item detected.')
                return
            translated_item_list = self.__translate_item_list(item_list)
            if not self.__packager.next_item_will_fit_row(translated_item_list):
                self.__log('Starting new row')
                self.__push_item(translated_item_list)
                if not self.__packager.next_row_will_fit_tray():
                    self.__log('Requesting new tray')
                    self.__load_new_tray()
            else:
                self.__make_room_for_next_item(translated_item_list)
            self.__io_manager.output('lock_door', IOManager.LOW)  # Unlock door
            self.current_loop_done = 1

    def __wait_for_closed_door(self):
        while not self.__io_manager.input('door_is_closed'):  # Wait while door is open
            self.current_loop_done = 0
            time.sleep(0.1)
        return

    def __generate_item_list(self):
        new_frame = self.__capture_manager.current_frame
        self.__image_analyzer.update(new_frame)
        return self.__image_analyzer.analyze_image()

    def __translate_item_list(self, item_list):
        return [self.__coordinates_translator.translate_values(item) for item in item_list]

    def __make_room_for_next_item(self, translated_item_list):
        target_position = self.__packager.item_size[0] + PADDING[0]
        current_position = translated_item_list[0][0]
        horizontal_distance_to_move = target_position - current_position
        self.__item_movement_motor.move(horizontal_distance_to_move * ITEM_MOVEMENT_CONVEYOR_STEPS_PER_CENTIMETER, True)

    def __push_item(self, translated_item_list):
        target_position = BUFFER_WIDTH
        current_position = translated_item_list[0][0]
        horizontal_distance_to_move = target_position - current_position
        vertical_distance_to_move = self.__packager.item_size[1] + PADDING[1]
        self.__item_movement_motor.move_to(horizontal_distance_to_move * ITEM_MOVEMENT_CONVEYOR_STEPS_PER_CENTIMETER, True)
        self.__io_manager.output('push_items', IOManager.HIGH)  # Request piston push from PLC
        time.sleep(TRAY_MOVEMENT_CONVEYOR_DELAY_DURING_PUSH)
        self.__io_manager.output('push_items', IOManager.LOW)
        self.__tray_movement_motor.move(vertical_distance_to_move * TRAY_MOVEMENT_CONVEYOR_STEPS_PER_CENTIMETER)
        while not self.__io_manager.input('push_completed'):  # Wait while piston operates
            time.sleep(0.1)
        self.__item_movement_motor.move_to(ITEM_MOVEMENT_CONVEYOR_REST_POSITION, True)
        return

    def __load_new_tray(self):
        self.__tray_movement_motor.loop_back_home()
        self.__io_manager.output('load_new_tray', IOManager.HIGH)  # Request a new tray from the loader
        time.sleep(0.5)
        self.__io_manager.output('load_new_tray', IOManager.LOW)
        while not self.__io_manager.input('load_completed'):  # Wait while the
            time.sleep(0.1)
        self.__tray_movement_motor.move(STEPS_FROM_LOADER_TO_ITEM_CONVEYOR)
        return

    def __calibrate_motors(self):
        self.__item_movement_motor.find_home()
        self.__tray_movement_motor.find_home(True)

    def __log(self, message):
        if self.verbose:
            print(message)
开发者ID:willGuimont,项目名称:Depowdering,代码行数:104,代码来源:depowdering.py


注:本文中的motor.Motor.find_home方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。