本文整理匯總了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)