def part_two(args, input_lines): "Process part two of the puzzle" # 1. Create the astroids map a_map = asteroids.Asteroids(text=input_lines, verbose=args.verbose) # 2. Get the maximum number of asteroids viewable from one station solution = a_map.maximum() if not solution: print("Unable to determine maximum number of asteroids") return False print("Maximum asteroids can be detected = %d at (%d,%d)" % (solution[0], solution[1][0], solution[1][1])) # 3. Put a laser there mylaser = laser.Laser(center=solution[1], text=input_lines) # 4. Go shoot 'em up loc = mylaser.shoot_until(number=args.maxtime, verbose=args.verbose) # 5. Announce the result if loc is not None: solution = 100 * loc[0] + loc[1] print("Shot the %d asteroid at %s, solution is %d" % (args.maxtime, loc, solution)) else: solution = None # 6. Return result return solution is not None
def pcmain(self, clientsocket): cap = cv2.VideoCapture(0) laserobject = laser.Laser(clientsocket) while True: ret, self.frame = cap.read() x, y, w, h, state = self.laserposition(200) laserobject.container(x, y, w, h, state)
def __init__(self, yCOM = 'COM10', xCOM = 'COM9', objCOM = None, pumpACOM = None, pumpBCOM = None, fpgaCOM = ['COM12','COM15'], laser1COM = 'COM13', laser2COM = 'COM14'): self.y = ystage.Ystage(yCOM) self.f = fpga.FPGA(fpgaCOM[0], fpgaCOM[1]) self.x = xstage.Xstage(xCOM) self.l1 = laser.Laser(laser1COM) self.l2 = laser.Laser(laser2COM) self.z = zstage.Zstage(self.f.serial_port) self.obj = objstage.OBJstage(self.f.serial_port) self.optics = optics.Optics(self.f.serial_port) self.cam1 = None self.cam2 = None self.image_path = 'C:\\Users\\Public\\Documents\\PySeq2500\\Images\\'
def connect_to_laser(): if port == 'exit': return port try: global trig, laser_on, laser laser = ls.Laser(port, debug_flag=False) trig = laser.get_trig() laser_on = laser.is_pumping_on() return True except: return False
def lasermain(self, clientsocket): """This function opens the camera, sets the framerate, corrects the exposure, calls laserposition() method to get the coordinates of laser spot and passed to removejerks() method. And then sent to container class Laser() Args: clientsocket This socket arg is passed to the container class Laser which interprets the laser coordinates and motions and sends to the server. """ with picamera.PiCamera() as camera: camera.resolution = (640, 480) camera.framerate = 24 stream = io.BytesIO() laserobject = laser.Laser(clientsocket) while True: camera.capture(stream, format="jpeg", use_video_port=True) frame = np.fromstring(stream.getvalue(), dtype=np.uint8) stream.seek(0) self.frame = cv2.imdecode(frame, 1) hsv = cv2.cvtColor(self.frame, cv2.COLOR_BGR2HSV) h, s, v = cv2.split(hsv) average = np.average(v) if average > AIV_threshold: print "correction" temporary = camera.exposure_compensation temporary -= int((average - AIV_threshold) / 10) try: if temporary < -25: camera.exposure_compensation = -25 elif temporary > 25: camera.exposure_compensation = 25 else: camera.exposure_compensation = temporary except picamera.PiCameraValueError as error: print error x, y, w, h, laserstate = self.laserposition() print "xs", x, y, w, h, laserstate x, y, w, h = self.removejerks(x, y, w, h) laserobject.container(x, y, w, h, laserstate)
def lasermain(self, clientsocket): """This function opens the camera, sets the framerate, corrects the exposure, calls laserposition() method to get the coordinates of laser spot and passed to removejerks() method. And then sent to container class Laser() Args: clientsocket This socket arg is passed to the container class Laser which interprets the laser coordinates and motions and sends to the server. """ import time import picamera import picamera.array with picamera.PiCamera() as camera: camera.resolution = (640, 480) camera.framerate = 24 time.sleep(0.1) laserobject = laser.Laser(clientsocket) global AIV_threshold global VALUE_THRESHOLD while True: key = cv2.waitKey(1000 / 24) if key is ord('a'): AIV_threshold += 5 elif key is ord('z'): AIV_threshold -= 5 elif key is ord('s'): VALUE_THRESHOLD += 5 elif key is ord('x'): VALUE_THRESHOLD -= 5 elif key is ord('q'): sys.exit(0) print "A", AIV_threshold, "V", VALUE_THRESHOLD with picamera.array.PiRGBArray(camera) as stream: camera.capture(stream, format='bgr', use_video_port=True) self.frame = stream.array # cv2.imshow("FRAME", self.frame) # key = cv2.waitKey(1000/24) # if key is ord('a'): # AIV_threshold += 5 # elif key is ord('z'): # AIV_threshold -= 5 hsv = cv2.cvtColor(stream.array, cv2.COLOR_BGR2HSV) h, s, v = cv2.split(hsv) average = int(np.average(v)) temporary = camera.exposure_compensation if average > AIV_threshold+10: temporary -= 5 #int((average - AIV_threshold)/10) elif average < AIV_threshold-10: temporary += 5 if temporary != camera.exposure_compensation: print "C", camera.exposure_compensation, "T", temporary try: if temporary < -25: camera.exposure_compensation = -25 elif temporary > 25: camera.exposure_compensation = 25 else: camera.exposure_compensation = temporary except picamera.PiCameraValueError as error: print error else: x, y, w, h, laserstate = self.laserposition(VALUE_THRESHOLD) print "x\'s", x, y, w, h, laserstate x, y, w, h = self.removejerks(x, y, w, h) laserobject.container(x, y, w, h, laserstate)
def shoot(self): if self.cool_down_counter == 0: bullet = laser.Laser(self.x - 20, self.y, self.bullets_img) self.bullets.append(bullet) self.cool_down_counter = 1
def firing_my_laser(self): my_laser = laser.Laser() self.laser_sprite.add(my_laser)
import yamaha import laser import keyboard as key import time base = yamaha.Yamaha() laser = laser.Laser() def main(): global base, laser if not (base_init() and laser_init()): return False laser.laser.draw_rect() laser.laser.start_list(True) laser.laser.enable_laser(True) laser.laser.laser_on(True) for i in range(500): laser.laser.delay_one_ms() laser.laser.laser_on(False) laser.laser.enable_laser(False) laser.laser.start_list(False) laser.laser.exec_list(True) time.sleep(5) laser.laser.exec_list(False) ''' en_on = [False, False] while True: if key.is_pressed('e'): en_on[0] = True
# machine is disabled - skip continue shared_folder = os.path.join("//", machine['ip'], machine['shared_folder']) local_folder = os.path.join("/", "mnt", "my_drive", machine['name']) # handle shared folders mount_logs_folder(shared_folder, local_folder, machine['user_name'], machine['domain'], machine['password']) # verify "lc.log" exists in the mounted folder log_file = os.path.join(local_folder, "lc.log") if os.path.exists(log_file): # init laser object laser.Laser(log, machine, log_file) else: log.error( f"failed to activate laser {machine['name']} check IP {machine['ip']}" ) log.error(f"file not found in {log_file}") SLEEP_TIME_SEC = 1 LAST_N_HOURS = 120 sleep_counter = 0 while True: # update operation table once in a minute if ((sleep_counter * SLEEP_TIME_SEC) % 60) == 0: dbmanager.update_operation_of_last_hours(LAST_N_HOURS) log.info(
import laser import time l = laser.Laser() l.off() for i in range(5): time.sleep(0.5) l.on() time.sleep(0.5) l.off()
def __init__(self): super(SearchStateMachine, self).__init__() self.__vision = vision.Vision() self.__laser = laser.Laser() self.__objectLoc = [] self.__start = time.time()
def lasermain(self): outf = open('output2.csv', 'w') with picamera.PiCamera() as camera: # camera.resolution = (320, 240) camera.resolution = (640, 320) camera.framerate = 24 camera.start_recording('timed.h264') stream = io.BytesIO() framecount = 0 laserobject = laser.Laser() while True: framecount += 1 camera.capture(stream, format="jpeg", use_video_port=True) frame = np.fromstring(stream.getvalue(), dtype=np.uint8) stream.seek(0) self.frame = cv2.imdecode(frame, 1) cv2.imshow("images", self.frame) cv2.waitKey(1000 / 24) starttime = time.time() x, y, w, h, laserstate = self.laserposition() print "xs", x, y, w, h, laserstate outf.write("x" + str(x) + "y" + str(y) + "w" + str(w) + "h" + str(h) + "laserstate" + str(laserstate) + "\n") laserobject.add(x, y, w, h, laserstate) if self.previoustate != laserstate: self.previoustate = laserstate if laserobject.transition % TRANSITIONS == 0: laserobject.transitionscount += 1 self.actionx, self.actiony = laserobject.actioncoordinate( ) clickornot = laserobject.boundaryevaluate() if clickornot: print "within----right or left click" print "transitions counter", laserobject.transitionscount #if drag is active, even if laserobject is seen as within the boundary, it will be ignored if laserobject.transitionscount <= 3 and not self.dragging: self.leftclick = True print "left click set" if laserobject.transitionscount > 3 and not self.dragging: self.rightclick = True self.leftclick = False print "right click set" laserobject.clear() #possible drag else: print "outside----dragging" print "transitions counter", laserobject.transitionscount if laserobject.transitionscount > 3: self.dragging = True self.rightclick = False self.leftclick = False print "dragging from:", self.actionx, self.actiony laserobject.clear() if x != 0: try: currentarea = w * h if currentarea < 40: outf.write("currentarea" + str(currentarea) + "\n") laser.Laser.area.append(currentarea) diff = laserobject.difference(laser.Laser.area) outf.write("diff" + str(diff) + "\n") if len(laser.Laser.area) > 15: for i in xrange(0, 10): laser.Laser.area.pop(0) if currentarea <= 16: print "blinked at:", self.actionx, self.actiony except BaseException as error: print "error", error # as soon as the transitions stop(continual beam arrives)--do a right or left click as per the flag if self.previoustate == laserstate: print "continual beam arrived" if self.leftclick: print "left click at:", self.actionx, self.actiony self.leftclick = False if self.rightclick: print "right click at:", self.actionx, self.actiony self.rightclick = False if self.dragging: print "stop drag" self.dragging = False # print "simple mouse movements", x, y, w, h #clear the last 7 transitions laserobject.clear() #clear the count of a single 7 transitions laserobject.transitionscount = 0