def run(): signals = { 'green': False, 'red': False, 'blue': False, 'stop': False, 'metal': False, 'maxTime': False, 'finish': False, 'path': '/home/pi/Filakov/', 'pltCnt': 1, 'imgCnt': 1 } start = time.time() # Make directory for the pictures directory = datetime.datetime.today().strftime('%Y-%m-%d_%H-%M-%S') signals['path'] += directory + '/' try: os.makedirs(signals['path']) except Exception as e: debug_print(str(e)) debug_print('Folder for pictures was not created. Aborting program...') return global output_file output_file = open(signals['path'] + 'log.txt', 'w', encoding='utf-8') C = Controls("/dev/ttyACM0", output_file) if not C.started: debug_print( "Controls of the motors are not started. Aborting program...") output_file.close() return cam = cv2.VideoCapture(0) time.sleep(1) if not cam.isOpened(): debug_print("Camera is not opened. Aborting program...") output_file.close() return # Run the process T_metal = threading.Thread(target=metalCheck, args=( C, signals, )) T_cam = threading.Thread(target=cameraLoop, args=( cam, signals, )) T_metal.start() T_cam.start() # Canvas down C.Move(3, 'M', 250, wait=True) C.Lights(1) # Camera calibration # C.Move(2, 'M', 180, wait = True) # calibrateCamera(C, signals) # if signals['stop']: # stopRoutine(C, signals) # return C.Move(2, 'M', 180, wait=True) # debug_print('Camera calibrated successfully.') # First iteration of plant imaging plantIter(C, cam, '-', signals) if signals['stop']: stopRoutine(C, signals) signals['finish'] = True T_cam.join() T_metal.join() output_file.close() return # Second iteration of plant imaging debug_print('Preparing plant imaging on the other side.') C.Move(2, 'M', -180, wait=True) plantIter(C, cam, '+', signals) if signals['stop']: stopRoutine(C, signals) signals['finish'] = True T_cam.join() T_metal.join() output_file.close() return # Finishing routine debug_print('Vertical motor returning to home position.') C.Move(1, 'H', wait=True) debug_print('Job done: ' + str(time.time() - start) + ' secs') signals['finish'] = True T_cam.join() T_metal.join() C.Lights(0) # Canvas up C.Move(3, 'M', -250, wait=True) C.Close() uploadCloudFolder(signals['path']) output_file.close() sendDoneMail(signals['path'] + 'log.txt')
# -*- coding: utf-8 -*- from controls import Controls # Rucno pokretanje motora C = Controls("/dev/ttyACM0") C.Move(0, 'M', 10) C.Close() # Motor 0: + je prema glavnoj stazi # Motor 1: + je prema gore # Motor 2: + je u smjeru kazaljke na satu # Motor 3: + je prema dolje