def setup(robot_config): global StepPinForward global StepPinBackward global StepPinLeft global StepPinRight global sleeptime global rotatetimes sleeptime = robot_config.getfloat('l298n', 'sleeptime') rotatetimes = robot_config.getfloat('l298n', 'rotatetimes') log.debug("GPIO mode : %s", str(GPIO.getmode())) GPIO.setwarnings(False) GPIO.cleanup() if robot_config.getboolean('tts', 'ext_chat'): #ext_chat enabled, add motor commands extended_command.add_command('.set_rotate_time', set_rotate_time) extended_command.add_command('.set_sleep_time', set_sleep_time) # TODO passing these as tuples may be unnecessary, it may accept lists as well. StepPinForward = tuple(map(int, robot_config.get('l298n', 'StepPinForward').split(','))) StepPinBackward = tuple(map(int,robot_config.get('l298n', 'StepPinBackward').split(','))) StepPinLeft = tuple(map(int,robot_config.get('l298n', 'StepPinLeft').split(','))) StepPinRight = tuple(map(int,robot_config.get('l298n', 'StepPinRight').split(','))) GPIO.setmode(GPIO.BOARD) GPIO.setup(StepPinForward, GPIO.OUT) GPIO.setup(StepPinBackward, GPIO.OUT) GPIO.setup(StepPinLeft, GPIO.OUT) GPIO.setup(StepPinRight, GPIO.OUT)
def setup(robot_config): ffmpeg.setup(robot_config) ffmpeg.setup = setupHUD ffmpeg.setup(robot_config) ffmpeg.startVideoCapture = startVideoCapture extended_command.add_command('.hud', HUDChatHandler)
def setup(robot_config): global module global ser module = mod_utils.import_module('hardware', 'serial_board') ser = module.setup(robot_config) if robot_config.getboolean('tts', 'ext_chat'): #ext_chat enabled, add motor commands extended_command.add_command('.set', set_eeprom)
def setup(robot_config, chat_handler): global main_chat_handler # Any chat related setup code goes here # Add a reboot command to the extended chat commands if robot_config.getboolean('tts', 'ext_chat'): import extended_command extended_command.add_command('.reboot', reboot) main_chat_handler = chat_handler
def setup(robot_config): global tempDir global client global voice global hwNum global audio_config global keyFile global languageCode global voicePitch global voiceSpeakingRate global ssmlEnabled global randomVoices global messenger ssmlEnabled = robot_config.getboolean('google_cloud', 'ssml_enabled') voice = robot_config.get('google_cloud', 'voice') keyFile = robot_config.get('google_cloud', 'key_file') languageCode = robot_config.get('google_cloud', 'language_code') voicePitch = robot_config.getfloat('google_cloud', 'voice_pitch') voiceSpeakingRate = robot_config.getfloat( 'google_cloud', 'voice_speaking_rate') messenger = robot_config.getboolean('messenger', 'enable') if robot_config.has_option('google_cloud', 'random_voices'): randomVoices = robot_config.getboolean('google_cloud', 'random_voices') else: randomVoices = False if robot_config.has_option('tts', 'speaker_num'): hwNum = robot_config.get('tts', 'speaker_num') else: hwNum = robot_config.get('tts', 'hw_num') client = texttospeech.TextToSpeechClient( credentials=service_account.Credentials.from_service_account_file( keyFile) ) if randomVoices: import extended_command extended_command.add_command('.new_voice', new_voice) audio_config = texttospeech.types.AudioConfig( audio_encoding=texttospeech.enums.AudioEncoding.LINEAR16, pitch=voicePitch, speaking_rate=voiceSpeakingRate ) tempDir = tempfile.gettempdir()
def setup(robot_config): global client global polly global robot_voice global users global hw_num global random_voice global fallback_tts global messenger owner = robot_config.get('robot', 'owner') owner_voice = robot_config.get('polly', 'owner_voice') robot_voice = robot_config.get('polly', 'robot_voice') random_voice = robot_config.getboolean('polly', 'random_voices') if robot_config.has_option('tts', 'speaker_num'): hw_num = robot_config.get('tts', 'speaker_num') else: hw_num = robot_config.get('tts', 'hw_num') access_key = robot_config.get('polly', 'access_key') secrets_key = robot_config.get('polly', 'secrets_key') region_name = robot_config.get('polly', 'region_name') messenger = robot_config.getboolean('messenger', 'enable') client = boto3.Session(aws_access_key_id=access_key, aws_secret_access_key=secrets_key, region_name=region_name) polly = boto3.client('polly', aws_access_key_id=access_key, aws_secret_access_key=secrets_key, region_name=region_name) users[owner] = owner_voice users['jill'] = 'Amy' if random_voice: # random voices enabled if robot_config.getboolean( 'tts', 'ext_chat'): #ext_chat enabled, add voice command import extended_command extended_command.add_command('.new_voice', new_voice) # Setup the fallback tts fallback_tts = mod_utils.import_module('tts', 'espeak') fallback_tts.setup(robot_config)
def setup(robot_config): global camera_id global infoServer global video_port global annotated global colour camera_id = robot_config.get('robot', 'camera_id') infoServer = robot_config.get('misc', 'info_server') video_port = getVideoPort() cozmo.setup_basic_logging() cozmo.robot.Robot.drive_off_charger_on_connect = False extended_command.add_command('.annotate', set_annotated) extended_command.add_command('.autodock', autodock) extended_command.add_command('.color', set_colour) extended_command.add_command('.colour', set_colour) try: thread.start_new_thread(cozmo.run_program, (run, )) # thread.start_new_thread(cozmo.run_program, (run,), {'use_3d_viewer':True}) except KeyboardInterrupt as e: pass except cozmo.ConnectionError as e: sys.exit("A connection error occurred: %s" % e) while not coz: try: time.sleep(0.5) print("not coz") except (KeyboardInterrupt, SystemExit): sys.exit() if robot_config.has_section('cozmo'): send_online_status = robot_config.getboolean('cozmo', 'send_online_status') annotated = robot_config.getboolean('cozmo', 'annotated') colour = robot_config.getboolean('cozmo', 'colour') else: send_online_status = True if send_online_status: print("Enabling online status") schedule.repeat_task(10, updateServer)
def setup(robot_config): global robotKey global no_mic global no_camera global stream_key global server global x_res global y_res global ffmpeg_location global v4l2_ctl_location global audio_hw_num global audio_device global audio_codec global audio_channels global audio_bitrate global audio_sample_rate global video_codec global video_bitrate global video_filter global video_device global audio_input_format global audio_input_options global audio_output_options global video_input_format global video_input_options global video_output_options global brightness global contrast global saturation robotKey = robot_config.get('robot', 'robot_key') if robot_config.has_option('misc', 'video_server'): server = robot_config.get('misc', 'video_server') else: server = robot_config.get('misc', 'server') no_mic = robot_config.getboolean('camera', 'no_mic') no_camera = robot_config.getboolean('camera', 'no_camera') ffmpeg_location = robot_config.get('ffmpeg', 'ffmpeg_location') v4l2_ctl_location = robot_config.get('ffmpeg', 'v4l2-ctl_location') x_res = robot_config.getint('camera', 'x_res') y_res = robot_config.getint('camera', 'y_res') if not no_camera: if robot_config.has_option('camera', 'brightness'): brightness = robot_config.get('camera', 'brightness') if robot_config.has_option('camera', 'contrast'): contrast = robot_config.get('camera', 'contrast') if robot_config.has_option('camera', 'saturation'): saturation = robot_config.get('camera', 'saturation') video_device = robot_config.get('camera', 'camera_device') video_codec = robot_config.get('ffmpeg', 'video_codec') video_bitrate = robot_config.get('ffmpeg', 'video_bitrate') video_input_format = robot_config.get('ffmpeg', 'video_input_format') video_input_options = robot_config.get('ffmpeg', 'video_input_options') video_output_options = robot_config.get('ffmpeg', 'video_output_options') if robot_config.has_option('ffmpeg', 'video_filter'): video_filter = robot_config.get('ffmpeg', 'video_filter') video_filter = '-vf %s' % video_filter if robot_config.getboolean('tts', 'ext_chat'): extended_command.add_command('.video', videoChatHandler) extended_command.add_command('.brightness', brightnessChatHandler) extended_command.add_command('.contrast', contrastChatHandler) extended_command.add_command('.saturation', saturationChatHandler) if not no_mic: if robot_config.has_option('camera', 'mic_num'): audio_hw_num = robot_config.get('camera', 'mic_num') else: log.warn("controller.conf is out of date. Consider updating.") audio_hw_num = robot_config.get('camera', 'audio_hw_num') if robot_config.has_option('camera', 'mic_device'): audio_device = robot_config.get('camera', 'mic_device') else: audio_device = robot_config.get('camera', 'audio_device') audio_codec = robot_config.get('ffmpeg', 'audio_codec') audio_bitrate = robot_config.get('ffmpeg', 'audio_bitrate') audio_sample_rate = robot_config.get('ffmpeg', 'audio_sample_rate') audio_channels = robot_config.get('ffmpeg', 'audio_channels') audio_input_format = robot_config.get('ffmpeg', 'audio_input_format') audio_input_options = robot_config.get('ffmpeg', 'audio_input_options') audio_output_options = robot_config.get('ffmpeg', 'audio_output_options') if robot_config.getboolean('tts', 'ext_chat'): extended_command.add_command('.audio', audioChatHandler) if audio_input_format == "alsa": extended_command.add_command('.mic', micHandler) # resolve device name to hw num, only with alsa if audio_input_format == "alsa": if audio_device != '': temp_hw_num = audio_util.getMicByName(audio_device.encode('utf-8')) if temp_hw_num != None: audio_hw_num = temp_hw_num # format the device for hw number if using alsa if audio_input_format == 'alsa': audio_device = 'hw:' + str(audio_hw_num)
video_module = importlib.import_module('video.' + commandArgs.video) else: video_module = __import__("video." + commandArgs.video, fromlist=[commandArgs.video]) # Setup the video encoding video_module.setup(robot_config) video_module.start() #load the extended chat commands if ext_chat: log.info("Loading extended chat commands") extended_command.setup(robot_config) extended_command.move_handler = move_handler move_handler = extended_command.move_auth extended_command.add_command('.restart', restart_controller) # Load a custom chat handler if enabled and exists if commandArgs.custom_chat: if os.path.exists('chat_custom.py'): if (sys.version_info > (3, 0)): chat_module = importlib.import_module('chat_custom') else: chat_module = __import__('chat_custom', fromlist=['chat_custom']) chat_module.setup(robot_config, handle_chat_message) else: log.warning("Unable to find chat_custom.py") # add auto wifi task
def setup(robot_config): global forward_speed global turn_speed global coz global volume global charge_high global charge_low global stay_on_dock coz = tts.tts_module.getCozmo() mod_utils.repeat_task(30, check_battery, coz) if robot_config.has_section('cozmo'): forward_speed = robot_config.getint('cozmo', 'forward_speed') turn_speed = robot_config.getint('cozmo', 'turn_speed') volume = robot_config.getint('cozmo', 'volume') charge_high = robot_config.getfloat('cozmo', 'charge_high') charge_low = robot_config.getfloat('cozmo', 'charge_low') stay_on_dock = robot_config.getfloat('cozmo', 'stay_on_dock') if robot_config.getboolean( 'tts', 'ext_chat'): #ext_chat enabled, add motor commands extended_command.add_command('.anim', play_anim) extended_command.add_command('.forward_speed', set_forward_speed) extended_command.add_command('.turn_speed', set_turn_speed) extended_command.add_command('.vol', set_volume) extended_command.add_command('.charge', set_charging) extended_command.add_command('.stay', set_stay_on_dock) coz.set_robot_volume(volume / 100) # set volume
def setup(robot_config): global robotID global no_mic global no_camera global messenger global videoPort global videoHost global audioHost global audioPort global stream_key global x_res global y_res global ffmpeg_location global v4l2_ctl_location global audio_hw_num global audio_device global audio_codec global audio_channels global audio_bitrate global audio_sample_rate global video_codec global video_bitrate global video_filter global video_device global audio_input_format global audio_input_options global audio_output_options global video_input_format global video_input_options global video_output_options global brightness global contrast global saturation global server_override robotID = robot_config.get('robot', 'robot_id') no_mic = robot_config.getboolean('camera', 'no_mic') no_camera = robot_config.getboolean('camera', 'no_camera') messenger = robot_config.getboolean('messenger', 'enable') ffmpeg_location = robot_config.get('ffmpeg', 'ffmpeg_location') v4l2_ctl_location = robot_config.get('ffmpeg', 'v4l2-ctl_location') stream_key = robot_config.get('robot', 'stream_key') x_res = robot_config.get('camera', 'x_res') y_res = robot_config.get('camera', 'y_res') server_override = robot_config.getboolean('misc', 'server_override') log.info("getting websocket relay host") websocketRelayHost = networking.getWebsocketRelayHost() if not no_camera: if robot_config.has_option('camera', 'brightness'): brightness = robot_config.get('camera', 'brightness') if robot_config.has_option('camera', 'contrast'): contrast = robot_config.get('camera', 'contrast') if robot_config.has_option('camera', 'saturation'): saturation = robot_config.get('camera', 'saturation') videoHost = websocketRelayHost['host'] videoPort = networking.videoPort log.debug("Relay host for video: %s:%s" % (videoHost, videoPort)) video_device = robot_config.get('camera', 'camera_device') video_codec = robot_config.get('ffmpeg', 'video_codec') video_bitrate = robot_config.get('ffmpeg', 'video_bitrate') video_input_format = robot_config.get('ffmpeg', 'video_input_format') video_input_options = robot_config.get('ffmpeg', 'video_input_options') video_output_options = robot_config.get('ffmpeg', 'video_output_options') if robot_config.has_option('ffmpeg', 'video_filter'): video_filter = robot_config.get('ffmpeg', 'video_filter') video_filter = '-vf %s' % video_filter if robot_config.getboolean('tts', 'ext_chat'): extended_command.add_command('.video', videoChatHandler) extended_command.add_command('.brightness', brightnessChatHandler) extended_command.add_command('.contrast', contrastChatHandler) extended_command.add_command('.saturation', saturationChatHandler) if not no_mic: audio_hw_num = robot_config.get('camera', 'audio_hw_num') audio_device = robot_config.get('camera', 'audio_device') if audio_device != '': temp_hw_num = audio_util.getMicByName(audio_device.encode('utf-8')) if temp_hw_num != None: audio_hw_num = temp_hw_num audioHost = websocketRelayHost['host'] audioPort = networking.audioPort log.debug("Relay host for audio: %s:%s" % (audioHost, audioPort)) audio_codec = robot_config.get('ffmpeg', 'audio_codec') audio_bitrate = robot_config.get('ffmpeg', 'audio_bitrate') audio_sample_rate = robot_config.get('ffmpeg', 'audio_sample_rate') audio_channels = robot_config.get('ffmpeg', 'audio_channels') audio_input_format = robot_config.get('ffmpeg', 'audio_input_format') audio_input_options = robot_config.get('ffmpeg', 'audio_input_options') audio_output_options = robot_config.get('ffmpeg', 'audio_output_options') if robot_config.getboolean('tts', 'ext_chat'): extended_command.add_command('.audio', audioChatHandler) # format the device for hw number if using alsa if audio_input_format == 'alsa': audio_device = 'hw:' + str(audio_hw_num) # load settings from site if not server_override: refreshFromOnlineSettings() networking.appServerSocketIO.on('command_to_robot', onCommandToRobot) networking.appServerSocketIO.on('robot_settings_changed', onRobotSettingsChanged)
def setup(robot_config): global forward_speed global turn_speed global server global volume global charge_high global charge_low global stay_on_dock global annotated global colour global ffmpeg_location global robotKey robotKey = robot_config.get('robot', 'robot_key') ffmpeg_location = robot_config.get('ffmpeg', 'ffmpeg_location') if robot_config.has_option('misc', 'video_server'): server = robot_config.get('misc', 'video_server') else: server = robot_config.get('misc', 'server') if robot_config.has_section('cozmo'): forward_speed = robot_config.getint('cozmo', 'forward_speed') turn_speed = robot_config.getint('cozmo', 'turn_speed') volume = robot_config.getint('cozmo', 'volume') charge_high = robot_config.getfloat('cozmo', 'charge_high') charge_low = robot_config.getfloat('cozmo', 'charge_low') stay_on_dock = robot_config.getboolean('cozmo', 'stay_on_dock') send_online_status = robot_config.getboolean('cozmo', 'send_online_status') annotated = robot_config.getboolean('cozmo', 'annotated') colour = robot_config.getboolean('cozmo', 'colour') coz.camera.color_image_enabled = colour else: send_online_status = True if robot_config.getboolean( 'tts', 'ext_chat'): #ext_chat enabled, add motor commands extended_command.add_command('.anim', play_anim) extended_command.add_command('.forward_speed', set_forward_speed) extended_command.add_command('.turn_speed', set_turn_speed) extended_command.add_command('.vol', set_volume) extended_command.add_command('.charge', set_charging) extended_command.add_command('.stay', set_stay_on_dock) extended_command.add_command('.annotate', set_annotated) extended_command.add_command('.color', set_colour) extended_command.add_command('.colour', set_colour) # if send_online_status: # print("Enabling online status") # schedule.repeat_task(10, updateServer) coz.set_robot_volume(volume / 100) # set volume
def setup(config): extended_command.add_command('.update', update_handler)