#!/bin/env/python3 #TODO: store location in a file, sort images import time from datetime import datetime #from picamera import PiCamera import threading, queue #import cv2 import os #from orbit import ISS #from skyfield.api import load #initialising globally useful variables path = str(os.path.dirname(os.path.realpath(__file__))+"/") #example code ''' from orbit import ISS from skyfield.api import load # Obtain the current time `t` t = load.timescale().now() # Compute where the ISS is at time `t` position = ISS.at(t) # Compute the coordinates of the Earth location directly beneath the ISS location = position.subpoint() print(location) ''' ''' #function for thread, saves images to non volatile storage def save_image_thread(): i = 0 image_capture = cv2.VideoCapture(0) #loop checking for task in queue while True: task = q.get() if task == 1: #save image return_value, image = image_capture.read() if return_value: cv2.imwrite(path+"capture"+str(i)+".jpg", image) else: print("No image returned") i += 1 if task == "stop": #exit thread image_capture.release() break time.sleep(1) ''' ''' def save_image_thread(): i = 0 camera = PiCamera() #loop checking for task in queue while True: task = q.get() if task == 1: #save image t= load.timescale().now() camera.capture(path+"capture"+str(i)+".jpg") position = ISS.coordinates() i += 1 if task == "stop": #exit thread image_capture.release() break time.sleep(1) ''' #initialising threads and queues for communication q = queue.Queue() #possible states 1, "stop", used in save_image_thread() threading.Thread(target = save_image_thread, daemon=True).start() #basic loop, sends tasks to threads every ~60s perf_counter_current = time.perf_counter() perf_counter_last = perf_counter_current perf_counter_next = perf_counter_last + 60 end_time = perf_counter_last + 10500 while perf_counter_current < end_time: perf_counter_current = time.perf_counter() if perf_counter_current >= perf_counter_next: perf_counter_last = perf_counter_current q.put(1) perf_counter_next = perf_counter_last + 60 time.sleep(1) q.put("stop")