def main(): """Parses command line arguments and runs the interactive controller.""" parser = make_parser() args = parser.parse_args() print('Sending commands to ' + args.server + ':' + str(args.port)) if not server_up(args.server, args.port, args.frequency): sys.stderr.write('Unable to contact server; did you start it?\n') sys.exit(1) interactive_control(args.server, args.port, args.frequency)
def main(): """Parses command line arguments and runs the interactive controller.""" parser = make_parser() args = parser.parse_args() with open(args.control_file) as configuration_file: configuration = load_configuration(configuration_file) print('Sending commands to ' + args.server + ':' + str(args.port)) frequency = json.loads(configuration['idle'])[0]['frequency'] if not server_up(args.server, args.port, frequency): print('Server does not appear to be listening for messages, aborting') return interactive_control(args.server, args.port, configuration)
def main(): """Parses command line arguments and runs the simple controller.""" parser = make_parser() args = parser.parse_args() if args.frequency is not None: frequency = dead_frequency(args.frequency) else: frequency = 49.830 if not server_up(args.server, args.port, frequency): print('Server does not appear to be listening for messages, aborting') return command_array = get_command_array(parser) print('Sending commands to ' + args.server + ':' + str(args.port)) send_signal(args.server, args.port, command_array[0])
def main(): """Parses command line arguments and runs the simple controller.""" parser = make_parser() args = parser.parse_args() if args.frequency is not None: frequency = dead_frequency(args.frequency) else: frequency = 49.830 if not server_up(args.server, args.port, frequency): print('Server does not appear to be listening for messages, aborting') return command_array = get_command_array(parser) print('Sending commands to ' + args.server + ':' + str(args.port)) send_signal_repeats(args.server, args.port, command_array)
def main(): """Parses command line arguments and runs the interactive controller.""" parser = make_parser() args = parser.parse_args() atexit.register(terminate) # Remove the default image to make sure that we're not processing images # from a previous run try: os.remove('photo.png') except OSError: pass if not server_up(args.server, args.port, args.frequency): print('Server does not appear to be listening for messages, aborting') return start_image_capture_process() # RC cars in the 27 and 49 MHz spectrum typically operate on one of a # several channels in that frequency, but most toy RC cars that I've # seen only list the major frequency on the car itself. If someone # enters a major frequency, search each channel. if args.frequency == 49: frequencies = CHANNELS_49_MHZ elif args.frequency == 27: frequencies = CHANNELS_27_MHZ else: frequencies = [args.frequency] print('Sending commands to ' + args.server + ':' + str(args.port)) try: search_for_command_codes( args.server, args.port, frequencies, bit_depth=args.bit_depth ) # pylint: disable=broad-except except Exception as exc: print('Caught exception, exiting') print(str(exc))
def main(): """Parses command line arguments and runs the interactive controller.""" parser = make_parser() args = parser.parse_args() atexit.register(terminate) # Remove the default image to make sure that we're not processing images # from a previous run try: os.remove('photo.png') except OSError: pass if not server_up(args.server, args.port, args.frequency): print('Server does not appear to be listening for messages, aborting') return start_image_capture_process() # RC cars in the 27 and 49 MHz spectrum typically operate on one of a # several channels in that frequency, but most toy RC cars that I've # seen only list the major frequency on the car itself. If someone # enters a major frequency, search each channel. if args.frequency == 49: frequencies = CHANNELS_49_MHZ elif args.frequency == 27: frequencies = CHANNELS_27_MHZ else: frequencies = [args.frequency] print('Sending commands to ' + args.server + ':' + str(args.port)) try: search_for_command_codes(args.server, args.port, frequencies, bit_depth=args.bit_depth) # pylint: disable=broad-except except Exception as exc: print('Caught exception, exiting') print(str(exc))
def main(): """Parses command line arguments and runs the interactive controller.""" parser = make_parser() args = parser.parse_args() # Remove the default image to make sure that we're not processing images # from a previous run try: os.remove('photo.png') except OSError: pass if not server_up(args.server, args.port, args.frequency): print('''Server does not appear to be listening for messages, aborting. Did you run pi_pcm?''') return webcam = args.webcam raspi_camera = args.raspi_camera if not args.no_camera: try: import PIL as _ except ImportError: sys.stderr.write( '''Using the camera to detect movement requires the Python PIL libraries. You can install them by running: apt-get install python-imaging Or, you can use the `--no-camera` option and just watch the RC car for movement. When it does, hit <Ctrl> + C and use the last printed values. ''') sys.exit(1) if webcam and raspi_camera: sys.stderr.write( 'You can only specify one of --webcam and --rasberry-pi-camera.' ) sys.exit(1) if not webcam and not raspi_camera: # Find which to use raspi_exists = subprocess.call(('/usr/bin/which', 'raspistill'), stdout=open('/dev/null', 'w')) if raspi_exists == 0: raspi_camera = True else: raspi_camera = False webcam = not raspi_camera # RC cars in the 27 and 49 MHz spectrum typically operate on one of a # several channels in that frequency, but most toy RC cars that I've # seen only list the major frequency on the car itself. If someone # enters a major frequency, search each channel. if args.frequency == 49: frequencies = CHANNELS_49_MHZ elif args.frequency == 27: frequencies = CHANNELS_27_MHZ else: frequencies = [args.frequency] print('Sending commands to ' + args.server + ':' + str(args.port)) picture_thread = None try: if args.no_camera: picture_function = None elif webcam: print('Using images from webcam') picture_thread = PictureWrapper(('streamer', '-f', 'jpeg', '-s', '640x480', '-o', '/dev/stdout')) picture_thread.start() picture_function = picture_thread.get_picture elif raspi_camera: print('Using images from Raspberry Pi camera module') # Use a smaller size here, because computing the % difference # on the Pi is incredibly slow picture_thread = PictureWrapper(('raspistill', '-w', '320', '-h', '240', '-t', '100', '-o', '-')) picture_thread.start() picture_function = picture_thread.get_picture else: print('Not using camera') picture_function = None search_for_command_codes( args.server, args.port, frequencies, get_picture_function=picture_function, bit_depth=args.bit_depth, ) # pylint: disable=broad-except except (KeyboardInterrupt, Exception) as exc: print('Caught exception, exiting') print(str(exc)) if picture_thread is not None: picture_thread.stop() picture_thread.join()
def main(): """Parses command line arguments and runs the interactive controller.""" parser = make_parser() args = parser.parse_args() # Remove the default image to make sure that we're not processing images # from a previous run try: os.remove('photo.png') except OSError: pass if not server_up(args.server, args.port, args.frequency): print( '''Server does not appear to be listening for messages, aborting. Did you run pi_pcm?''' ) return webcam = args.webcam raspi_camera = args.raspi_camera if not args.no_camera: try: import PIL as _ except ImportError: sys.stderr.write( '''Using the camera to detect movement requires the Python PIL libraries. You can install them by running: apt-get install python-imaging Or, you can use the `--no-camera` option and just watch the RC car for movement. When it does, hit <Ctrl> + C and use the last printed values. ''' ) sys.exit(1) if webcam and raspi_camera: sys.stderr.write( 'You can only specify one of --webcam and --rasberry-pi-camera.' ) sys.exit(1) if not webcam and not raspi_camera: # Find which to use raspi_exists = subprocess.call( ('/usr/bin/which', 'raspistill'), stdout=open('/dev/null', 'w') ) if raspi_exists == 0: raspi_camera = True else: raspi_camera = False webcam = not raspi_camera # RC cars in the 27 and 49 MHz spectrum typically operate on one of a # several channels in that frequency, but most toy RC cars that I've # seen only list the major frequency on the car itself. If someone # enters a major frequency, search each channel. if args.frequency == 49: frequencies = CHANNELS_49_MHZ elif args.frequency == 27: frequencies = CHANNELS_27_MHZ else: frequencies = [args.frequency] print('Sending commands to ' + args.server + ':' + str(args.port)) picture_thread = None try: if args.no_camera: picture_function = None elif webcam: print('Using images from webcam') picture_thread = PictureWrapper( ('streamer', '-f', 'jpeg', '-s', '640x480', '-o', '/dev/stdout') ) picture_thread.start() picture_function = picture_thread.get_picture elif raspi_camera: print('Using images from Raspberry Pi camera module') # Use a smaller size here, because computing the % difference # on the Pi is incredibly slow picture_thread = PictureWrapper( ('raspistill', '-w', '320', '-h', '240', '-t', '100', '-o', '-') ) picture_thread.start() picture_function = picture_thread.get_picture else: print('Not using camera') picture_function = None search_for_command_codes( args.server, args.port, frequencies, get_picture_function=picture_function, bit_depth=args.bit_depth, ) # pylint: disable=broad-except except (KeyboardInterrupt, Exception) as exc: print('Caught exception, exiting') print(str(exc)) if picture_thread is not None: picture_thread.stop() picture_thread.join()