def define_jobs_context(self, context): from pkg_resources import resource_filename # @UnresolvedImport config_dir = resource_filename("yc1304.uzhturtle", "config") GlobalConfig.global_load_dir(config_dir) GlobalConfig.global_load_dir('${DATASET_UZHTURTLE}') rm = context.get_report_manager() rm.set_html_resources_prefix('uzh-turtle-stats') data_central = self.get_data_central() logs = list(self.get_explogs_by_tag('uzhturtle')) agents = ['stats2', 'bdse_e1_ss'] robots = ['uzhturtle_un1_cf1', 'uzhturtle_un1_cf1_third'] for c, id_explog in iterate_context_explogs(context, logs): explog = get_conftools_explogs().instance(id_explog) print id_explog, explog jobs_learn_parallel(context, data_central=data_central, explogs_learn=logs, agents=agents, robots=robots, episodes_per_tranche=2)
def instance_explog(self, id_explog): """ Instances the given explog and checks it is a ExpLogFromYaml """ log = get_conftools_explogs().instance(id_explog) if not isinstance(log, ExpLogFromYaml): self.info('Skipping log %r because not raw log.' % id_explog) return return log
def reconstruct_servo_state_nomap(id_explog, id_robot, out_base, goal_at): """ reconstruct the servo state for navigation logs """ explog = get_conftools_explogs().instance(id_explog) bag = explog.get_bagfile() # get a list of state transitions transitions = reconstruct(bag, topic='/youbot_safety/in_cmd_vel') print(transitions) robot = get_conftools_robots().instance(id_robot) orig_robot = robot.get_inner_components()[-1] if not isinstance(orig_robot, ROSRobot): msg = 'Expected ROSRobot, got %s' % describe_type(robot) raise ValueError(msg) orig_robot.read_from_log(explog) def read_data(): goal = None t0 = None servo_state = STATE_WAIT for obs in iterate_robot_observations(robot, sleep=0): timestamp = obs.timestamp if t0 is None: t0 = timestamp observations = obs.observations if goal is None and timestamp - t0 > goal_at: goal = observations commands = obs.commands # if still have transitions if transitions: next_transition = transitions[0][0] if timestamp > next_transition: servo_state = transitions[0][1] transitions.pop(0) # if np.linalg.norm(commands) == 0: # servo_state = STATE_WAIT # else: # servo_state = STATE_SERVOING # # n = np.sum(commands != 0) # print "%20s" % servo_state + "n: %5s " % n + ",".join('%+10.6f' % s for s in commands) # goal = controller.get_current_goal() yield 'y', timestamp, observations yield 'servo_state', timestamp, servo_state yield 'commands', timestamp, commands if goal is None: yield 'y_goal', timestamp, observations else: yield 'y_goal', timestamp, goal iterator = read_data() pg('read_reconstructed_data', config=dict(iterator=iterator, out_base=out_base))
def create_video_servo_multi(id_explog, out_base): explog = get_conftools_explogs().instance(id_explog) bag = explog.get_bagfile() if os.path.exists(out_base + '.fcpxml'): print('Already exists: %s' % out_base) return pg('video_servo_multi', config=dict(bag=bag, out_base=out_base))
def read_all_events(id_explog): explog = get_conftools_explogs().instance(id_explog) files = explog.get_files() if not "aer" in files: msg = "Could not find aer log (%s)" % files raise ValueError(msg) filename = files["aer"] events = aer_raw_events_from_file_all(filename, limit=None) return events
def define_jobs_context(self, context): data_central = self.get_data_central() all_logs = get_conftools_explogs().keys() explogs_landroid = [x for x in all_logs if 'logger' in x] robots = Exp18.robots agents = Exp18.agents explogs_learn = explogs_landroid explogs_test = Exp18.explogs_test jobs_learnp_and_servo(context, data_central, explogs_learn, explogs_test, agents, robots)
def rp_convert(c, id_robot, id_episode): if my_id_robot is not None and my_id_robot != id_robot: msg = ('I only know how to create %r, not %r.' % (my_id_robot, id_robot)) raise ResourceManager.CannotProvide(msg) id_explog = id_episode library = get_conftools_explogs() if not id_explog in library: msg = 'Log %r not found.' % id_explog raise ResourceManager.CannotProvide(msg) return c.subtask(RS2BConvert2, boot_root=boot_root, id_explog=id_explog, id_robot=id_robot, id_robot_res=id_robot, add_job_prefix='')
def reconstruct_servo_state(id_explog, id_robot, nmap, out_base, navigation_params): """ reconstruct the servo state for navigation logs """ explog = get_conftools_explogs().instance(id_explog) robot = get_conftools_robots().instance(id_robot) orig_robot = robot.get_inner_components()[-1] if not isinstance(orig_robot, ROSRobot): msg = 'Expected ROSRobot, got %s' % describe_type(robot) raise ValueError(msg) orig_robot.read_from_log(explog) controller = NavigationController(nmap, **navigation_params) def read_data(): servo_state = None for obs in iterate_robot_observations(robot, sleep=0): timestamp = obs.timestamp observations = obs.observations commands = obs.commands if servo_state != STATE_SERVOING and np.linalg.norm(commands) == 0: servo_state = STATE_WAIT else: servo_state = STATE_SERVOING controller.process_observations(observations) goal = controller.get_current_goal() yield 'y', timestamp, observations yield 'servo_state', timestamp, servo_state yield 'commands', timestamp, commands yield 'y_goal', timestamp, goal iterator = read_data() pg('read_reconstructed_data', config=dict(iterator=iterator, out_base=out_base))
def get_explogs_by_tag(self, tag): explogs_library = get_conftools_explogs() for id_explog in explogs_library: explog = explogs_library.instance(id_explog) if tag in explog.get_tags(): yield id_explog