def __init__(self, map="lab"): ShowBase.__init__(self) pman.shim.init(self) self.accept('escape', sys.exit) #self.render.setShaderAuto() self.set_frame_rate_meter(True) self.accept('tilde', self.debug) self.environment = Environment(self, map) self.bullet_debug() self.accept("b", self.toggle_bullet_debug) self.vehicles = [] vehicle_files = [ 'Ricardeaut_Magnesium', 'Ricardeaut_Himony', #'Psyoni_Culture', #'Texopec_Nako', #'Texopec_Reaal', # 'Doby_Phalix', ] for vehicle_file in vehicle_files: vehicle = Vehicle( self, vehicle_file, ) self.vehicles.append(vehicle) spawn_points = self.environment.get_spawn_points() for vehicle, spawn_point in zip(self.vehicles, spawn_points): vehicle.place(spawn_point) self.controller_listener = DeviceListener() self.player_vehicle_idx = 0 self.player_controller = VehicleController( self, self.vehicles[self.player_vehicle_idx], self.controller_listener, ) self.player_camera = CameraController( base.cam, self.vehicles[self.player_vehicle_idx], self.player_controller, ) base.task_mgr.add( self.game_loop_pre_render, "game_loop_pre_render", sort=45, ) base.task_mgr.add( self.game_loop_post_render, "game_loop_post_render", sort=55, )
def initialize(self): formatter = logging.Formatter( '%(asctime)s - %(name)s - %(levelname)s - %(message)s') file_handler = RotatingFileHandler(getattr(config, 'cfg').get( 'box', 'log_file'), maxBytes=5242880, backupCount=4) file_handler.setLevel(logging.INFO) file_handler.setFormatter(formatter) root_logger = logging.getLogger() root_logger.addHandler(file_handler) init(autoreset=True) photo_count = getattr(config, 'cfg').getint('box', 'photo_count') led_controller = LedController() led_controller.initialize() led_controller.blink_green(1) led_controller.blink_blue(1) scanner = CodeScanner() camera_controller = CameraController() camera_controller.initialize() motor_controller = MotorController() motor_controller.initialize() base_address = getattr(config, 'cfg').get('server', 'base_address') auth_address = '{}{}'.format( base_address, getattr(config, 'cfg').get('server', 'auth_endpoint')) reauth_address = '{}{}'.format( base_address, getattr(config, 'cfg').get('server', 'reauth_endpoint')) auth = TokenAuth(auth_address, reauth_address, username=getattr(config, 'cfg').get('credentials', 'username'), password=getattr(config, 'cfg').get('credentials', 'password')) image_handler = ImageHandler(photo_count=photo_count, auth=auth) image_handler.setDaemon(True) image_handler.start() phenobox_machine = PhenoboxMachine(camera_controller, scanner, motor_controller, led_controller, image_handler, auth, photo_count) phenobox_machine.initialize() return (phenobox_machine, motor_controller, led_controller, camera_controller, image_handler)
def main(): config.load_config('{}/{}'.format('config', 'test_config.ini')) formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') file_handler = RotatingFileHandler(getattr(config, 'cfg').get('box', 'log_file'), maxBytes=5242880, backupCount=4) file_handler.setLevel(logging.DEBUG) file_handler.setFormatter(formatter) root_logger = logging.getLogger() root_logger.addHandler(file_handler) root_logger.setLevel(logging.DEBUG) try: camera = CameraController() camera.initialize() camera.capture_and_download('test1') code_scanner = CodeScanner() code_information = code_scanner.scan_image('/home/pi/pictures/test1.jpg') if code_information is not None: print('Decoded from QRCode: "{}"'.format(code_information.decode('utf8'))) else: print('No decodable QRCode found') camera.close() except ConnectionError as e: print('Connection Error "%s"' % e) except CaptureError as e: print('Capture Error "%s"' % e)
def initialize(self): formatter = logging.Formatter( '%(asctime)s - %(name)s - %(levelname)s - %(message)s') file_handler = RotatingFileHandler(getattr(config, 'cfg').get( 'box', 'log_file'), maxBytes=5242880, backupCount=4) file_handler.setLevel(logging.INFO) file_handler.setFormatter(formatter) root_logger = logging.getLogger() root_logger.addHandler(file_handler) init(autoreset=True) photo_count = getattr(config, 'cfg').getint('box', 'photo_count') self.illumination = Illumination( 13) # use GPIO pin 13 for illumination PWM control self.led_controller = LedController() self.led_controller.initialize() self.led_controller.blink_green(1) self.led_controller.blink_blue(1) self.scanner = CodeScanner() self.camera_controller = CameraController() self.camera_controller.initialize() self.motor_controller = MotorController() self.motor_controller.initialize() self.image_handler = ImageHandler(photo_count=photo_count) self.image_handler.setDaemon(True) self.image_handler.start() self.phenobox_statemachine = PhenoboxStateMachine( self.camera_controller, self.scanner, self.motor_controller, self.led_controller, self.image_handler, self.illumination, photo_count) self.phenobox_statemachine.initialize() self.input_controller = InputController() self.input_controller.initialize(self.door_state_changed, self.start_pressed) signal.signal(signal.SIGUSR1, sigUSR1_handler)
class GameApp(ShowBase): def __init__(self, map="lab"): ShowBase.__init__(self) pman.shim.init(self) self.audio3d = Audio3DManager( base.sfxManagerList[0], base.cam, ) self.accept('escape', sys.exit) #self.render.setShaderAuto() self.set_frame_rate_meter(True) self.accept('f12', self.debug) self.environment = Environment(self, map) self.bullet_debug() self.accept("f1", self.toggle_bullet_debug) self.vehicles = [] vehicle_files = [ 'Ricardeaut_Magnesium', 'Ricardeaut_Himony', #'Psyoni_Culture', #'Texopec_Nako', #'Texopec_Reaal', # 'Doby_Phalix', ] for vehicle_file in vehicle_files: vehicle = Vehicle( self, vehicle_file, ) self.vehicles.append(vehicle) spawn_points = self.environment.get_spawn_points() for vehicle, spawn_point in zip(self.vehicles, spawn_points): vehicle.place(spawn_point) self.controller_listener = DeviceListener() self.player_vehicle_idx = 0 self.player_controller = VehicleController( self, self.vehicles[self.player_vehicle_idx], self.controller_listener, ) self.player_camera = CameraController( base.cam, self.vehicles[self.player_vehicle_idx], self.player_controller, ) base.task_mgr.add( self.game_loop_pre_render, "game_loop_pre_render", sort=45, ) base.task_mgr.add( self.game_loop_post_render, "game_loop_post_render", sort=55, ) def game_loop_pre_render(self, task): self.player_controller.gather_inputs() for vehicle in self.vehicles: vehicle.game_loop() self.player_camera.update() return task.cont def game_loop_post_render(self, task): self.environment.update_physics() return task.cont def next_vehicle(self): num_vehicles = len(self.vehicles) self.player_vehicle_idx = (self.player_vehicle_idx + 1) % num_vehicles new_vehicle = self.vehicles[self.player_vehicle_idx] self.player_camera.set_vehicle(new_vehicle) self.player_controller.set_vehicle(new_vehicle) def bullet_debug(self): debug_node = BulletDebugNode('Debug') debug_node.show_wireframe(True) debug_node.show_constraints(True) debug_node.show_bounding_boxes(False) debug_node.show_normals(False) self.debug_np = self.render.attach_new_node(debug_node) self.environment.physics_world.set_debug_node(debug_node) def toggle_bullet_debug(self): if self.debug_np.is_hidden(): self.debug_np.show() else: self.debug_np.hide() def debug(self): import pdb pdb.set_trace()
def go_through_states(): global count print("Button is pushed count is", count) ble.setValue(count) count += 1 if count == 3: count = 0 def button_callback(channel): global last_time cur_time = int(time.time()) if (cur_time - last_time) > 1: # print("button pressed") take_picture_classify_on_cloud_send_rotate_signal() last_time = int(time.time()) if __name__ == '__main__': if with_ble: ble = BleController(3) cam = CameraController(rotation=180) GPIO.setwarnings(False) GPIO.setmode(GPIO.BOARD) GPIO.setup(10, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) GPIO.add_event_detect(10, GPIO.RISING, callback=button_callback) print("setup complete") message = input("Press enter to quit\n\n") GPIO.cleanup()
class Phenobox(): def __init__(self): self.initialize() self.eventQueue = Queue() self._logger = logging.getLogger(__name__) self._logger.setLevel(logging.INFO) self.door_state = self.input_controller.get_door_state() def door_state_changed(self, state): """ If it is opened while the box is not in the IDLE or ERROR state it will transition to the ERROR state :param state: The current/new DoorState :return: None """ self.door_state = state if state == DoorState.OPEN: if not self.phenobox_statemachine.is_IDLE( ) and not self.phenobox_statemachine.is_ERROR(): self._logger.info('Door Opened while running') self.phenobox_statemachine.door_opened(error_code=3) def start_pressed(self, press): if press == ButtonPress.SHORT: print(Fore.CYAN + "State: " + self.phenobox_statemachine.state) if self.phenobox_statemachine.is_IDLE( ) or self.phenobox_statemachine.is_ERROR(): if press == ButtonPress.LONG: print(Fore.MAGENTA + "Shutdown Requested") self._logger.info('Shutdown action placed') self.eventQueue.put(UserEvent.SHUTDOWN) else: if self.door_state == DoorState.CLOSED: print(Fore.BLUE + "Start") if self.phenobox_statemachine.is_IDLE(): self._logger.info('Start action placed') self.eventQueue.put(UserEvent.START) else: self._logger.info('Restart action placed') self.eventQueue.put(UserEvent.RESTART) else: print(Fore.RED + "Please close the door before starting!") def initialize(self): formatter = logging.Formatter( '%(asctime)s - %(name)s - %(levelname)s - %(message)s') file_handler = RotatingFileHandler(getattr(config, 'cfg').get( 'box', 'log_file'), maxBytes=5242880, backupCount=4) file_handler.setLevel(logging.INFO) file_handler.setFormatter(formatter) root_logger = logging.getLogger() root_logger.addHandler(file_handler) init(autoreset=True) photo_count = getattr(config, 'cfg').getint('box', 'photo_count') self.illumination = Illumination( 13) # use GPIO pin 13 for illumination PWM control self.led_controller = LedController() self.led_controller.initialize() self.led_controller.blink_green(1) self.led_controller.blink_blue(1) self.scanner = CodeScanner() self.camera_controller = CameraController() self.camera_controller.initialize() self.motor_controller = MotorController() self.motor_controller.initialize() self.image_handler = ImageHandler(photo_count=photo_count) self.image_handler.setDaemon(True) self.image_handler.start() self.phenobox_statemachine = PhenoboxStateMachine( self.camera_controller, self.scanner, self.motor_controller, self.led_controller, self.image_handler, self.illumination, photo_count) self.phenobox_statemachine.initialize() self.input_controller = InputController() self.input_controller.initialize(self.door_state_changed, self.start_pressed) signal.signal(signal.SIGUSR1, sigUSR1_handler) def _terminate(self): self.led_controller.clear_all() self.camera_controller.close() self.led_controller.blink_green(interval=1) self.led_controller.blink_blue(interval=1) self.image_handler.stop() self.image_handler.join() self.led_controller.clear_all() gpio.clean() def run(self): shutdown = False try: while True: try: event = self.eventQueue.get(True, 0.1) except Empty: continue if event == UserEvent.START: self.phenobox_statemachine.start() if event == UserEvent.RESTART: self.phenobox_statemachine.restart() if event == UserEvent.SHUTDOWN: shutdown = True break except KeyboardInterrupt: print("keyboard interrupt") print(Fore.MAGENTA + 'Shutdown initiated') self._terminate() if shutdown: subprocess.call( ['sudo shutdown -h now "System halted by GPIO action" &'], shell=True)
from camera import CameraController # from refree import RefreeController # from robot import RobotController camera = CameraController() while camera.cap.isOpened(): camera.main_loop() # refree = RefreeController() # robot = RobotController() # refree.whatsUp() # robot.start()
if not alarm: logging.info('Camera: motion detection!') alarm = True # main try: # init motion sensor motion_sensor = gpio.EdgeMonitor(PIN_MOTION_SENSOR, gpio.FALLING, callback_motion_sensor) motion_sensor.start() logging.info('Make sure the motion sensor is connected to GPIO pin ' + str(PIN_MOTION_SENSOR) + '.') # init camera cam = CameraController(path=args.recordings, motion_callback=callback_motion_camera) logging.debug('Alarm system starts.') # do the stuff to do while True: # save image for mjpg-streamer cam.capture(args.stream) # save video and image to server if motion detected if alarm: cam.capture() # make/save single image cam.wait(0.5) # wait 50% of video length cam.write_video() logging.info('Capturing done.') alarm = False
from camera import CameraController import time from refree import RefreeController from settings import ROBOT_ID, FIELD_ID # from robot import RobotController # def get_rf_signal(): camera = CameraController() #camera.robot_state = "stop" while not camera.communication.board.is_open: time.sleep(1) # camera.refree = RefreeController(camera) while camera.cap.isOpened(): camera.main_loop() if camera.robot_state == "stop": time.sleep(1) if camera.communication.board.readable(): time.sleep(0.01) tdata = camera.communication.board.read() data_left = camera.communication.board.inWaiting( ) # Get the number of characters ready to be read tdata += camera.communication.board.read( data_left) # Do the read and combine it with the first character if tdata: