def go(self): options = self.get_options() rate = options.rate boot_config = get_boot_config() rs2b_config = get_rs2b_config() for c in options.config: boot_config.load(c) rs2b_config.load(c) id_robot = options.robot robot = boot_config.robots.instance(id_robot) rest = robot.get_spec().get_commands().get_default_value() robot.set_commands(rest, 'rest') try: for key in getKeys(timeout=0): if key == 'q': break if key in moveBindings.keys(): u = np.array(moveBindings[key]) else: u = rest robot.set_commands(u, 'teleop') time.sleep(rate) # except Exception as e: # # print str(e) finally: robot.set_commands(rest, 'rest')
def define_jobs_context(self, context): options = self.get_options() boot_root = options.boot_root rs2b_config = get_rs2b_config() boot_config = get_boot_config() data_central = DataCentral(boot_root) id_robot = options.id_robot id_robot_res = options.id_robot_res id_explog = options.id_explog id_stream = '%s%s' % (options.id_episode_prefix, id_explog) id_episode = id_stream id_agent = None # make sure we have them boot_config.robots[id_robot] rs2b_config.explogs[id_explog] ds = data_central.get_dir_structure() filename = ds.get_explog_filename(id_robot=id_robot_res, id_agent=id_agent, id_stream=id_stream) return context.comp_config(do_convert_job2, id_robot=id_robot, id_robot_res=id_robot_res, id_explog=id_explog, id_stream=id_stream, id_episode=id_episode, filename=filename)
def do_convert_job2(id_robot, id_robot_res, id_explog, id_stream, id_episode, filename): rs2b_config = get_rs2b_config() boot_config = get_boot_config() """ id_robot: original robot must be a ROSRobot """ if os.path.exists(filename): msg = 'Output file exists: %s\n' % friendly_path(filename) msg += 'Delete to force recreating the log.' logger.info(msg) return explog = rs2b_config.explogs.instance(id_explog) robot = boot_config.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) id_environment = explog.get_id_environment() write_robot_observations(id_stream, filename, id_robot_res, robot, id_episode, id_environment)
def init_iterator(self): id_robot = self.config.id_robot bagfile = self.config.file boot_config = get_boot_config() robot = boot_config.robots.instance(id_robot) warnings.warn('Make this more general') if isinstance(robot, EquivRobot): orig_robot = robot.get_original_robot() else: orig_robot = robot if not isinstance(orig_robot, ROSRobot): msg = 'Expected ROSRobot, got %s' % describe_type(robot) raise ValueError(msg) orig_robot.read_from_bag(bagfile) bd_seq = bd_sequence_from_robot(id_robot, robot, sleep_wait=0, id_episode='xxx', id_environment='xxx', check_valid_values=False) def make_boot_iterator(): for bd in bd_seq: yield 0, bd['timestamp'].item(), bd return make_boot_iterator()
def print_configuration(directory, outdir): from reprep import Report bo_config = get_boot_config() bo_config.load(directory) def write_report(r): out = os.path.join(outdir, '%s.html' % r.id) rd = os.path.join(outdir, 'images') logger.info('Writing to %r' % out) r.to_html(out, resources_dir=rd) # tasks = BootOlympicsConfig.tasks # r = Report('tasks') # create_generic_table(r, 'configuration', tasks, ['desc', 'code']) # write_report(r) agents = bo_config.agents r = Report('agents') create_generic_table(r, 'configuration', agents, ['desc', 'code']) write_report(r) robots = bo_config.robots r = Report('robots') create_generic_table(r, 'configuration', robots, ['desc', 'ros-node']) write_report(r) nuisances = bo_config.nuisances r = Report('nuisances') create_generic_table(r, 'configuration', nuisances, ['desc', 'code']) write_report(r)
def get_comptests(): # get testing configuration directory from pkg_resources import resource_filename # @UnresolvedImport dirname = resource_filename("diffeo2dds_sim", "configs") tests = [] import bootstrapping_olympics bootstrapping_olympics.get_boot_config().load(dirname) tests.extend(bootstrapping_olympics.get_comptests()) import diffeo2dds_learn diffeo2dds_learn.get_diffeo2ddslearn_config().load(dirname) tests.extend(diffeo2dds_learn.get_comptests()) return tests
def main(self): rospy.init_node('servo_demo', disable_signals=True) self.info('Started.') contracts.disable_all() boot_root = rospy.get_param('~boot_root') boot_root = expand_environment(boot_root) config_dir = rospy.get_param('~config_dir') id_robot_learned = rospy.get_param('~id_robot_learn') self.info('loading %r' % config_dir) GlobalConfig.global_load_dir(config_dir) id_agent = rospy.get_param('~id_agent') self.id_robot = rospy.get_param('~id_robot') self.sleep = rospy.get_param('~sleep', 0.005) self.info('sleep: %s' % self.sleep) self.error_threshold = float(rospy.get_param('~error_threshold')) raise_if_no_state = rospy.get_param('~raise_if_no_state', True) data_central = DataCentral(boot_root) ag_st = load_agent_state(data_central, id_agent, id_robot_learned, reset_state=False, raise_if_no_state=raise_if_no_state) self.agent, state = ag_st self.info('Loaded state: %s' % state) self.servo_agent = self.agent.get_servo() bo_config = get_boot_config() self.robot = bo_config.robots.instance(self.id_robot) self.boot_spec = self.robot.get_spec() self.publish_info_init() self.y = None self.y_goal = None self.started_now = False self.stopped_now = False self.e0 = 1 self.e = 1 self.last_boot_data = None self.state = STATE_WAIT self.info('Defining services') rospy.Service('set_goal', Empty, self.srv_set_goal) rospy.Service('start_servo', Empty, self.srv_start_servo) rospy.Service('stop_servo', Empty, self.srv_stop_servo) self.info('Finished initialization') self.count = 0 self.go()
def define_jobs_context(self, context): boot_config = get_boot_config() boot_config.agents.instance(Exp20.agents[0]) boot_root = self.get_boot_root() data_central = self.get_data_central() recipe_episodeready_by_convert2(context, boot_root, id_robot=Exp20.id_robot) recipe_agentlearn_by_parallel(context, data_central, Exp20.explogs_learn) jobs_publish_learning(context, Exp20.agents, id_robot=Exp20.id_robot)
def __init__(self, robot, obs_nuisance=[], cmd_nuisance=[]): self.inner_robot_name = robot boot_config = get_boot_config() id_robot, self.robot = boot_config.robots.instance_smarter(robot) if not isinstance(self.robot, RobotInterface): msg = 'Expected RobotInterface, got %s' % describe_type(self.robot) raise ValueError(msg) warnings.warn('handle the case better') self.desc = ('EquivRobot(%s,obs:%s,cmd:%s)' % (id_robot, obs_nuisance, cmd_nuisance)) # convert to (possibly empty) list of strings if isinstance(obs_nuisance, str): obs_nuisance = [obs_nuisance] if isinstance(cmd_nuisance, str): cmd_nuisance = [cmd_nuisance] instance = lambda y: boot_config.nuisances.instance_smarter(y)[1] self.obs_nuisances = [instance(x) for x in obs_nuisance] self.cmd_nuisances = [instance(x) for x in cmd_nuisance] # No - we should not call inverse() before transform_spec() obs_spec = self.robot.get_spec().get_observations() for n in self.obs_nuisances: obs_spec = n.transform_spec(obs_spec) cmd_spec = self.robot.get_spec().get_commands() for n in self.cmd_nuisances: cmd_spec = n.transform_spec(cmd_spec) # We don't really need to compute this... try: self.cmd_nuisances_inv = [x.inverse() for x in self.cmd_nuisances] # now initialize in reverse cmd_spec_i = cmd_spec for n in reversed(self.cmd_nuisances_inv): cmd_spec_i = n.transform_spec(cmd_spec_i) StreamSpec.check_same_spec(cmd_spec_i, self.robot.get_spec().get_commands()) # TODO: why do we do this for commands, not for osbservations? except Exception as e: logger.warning('It seems that this chain of nuisances is not ' 'exact, but it could be OK to continue. ' ' The chain is %s; the error is:\n%s' % (cmd_nuisance, indent(str(e).strip(), '> '))) self.spec = BootSpec(obs_spec=obs_spec, cmd_spec=cmd_spec) self.obs_nuisances_id = obs_nuisance self.cmd_nuisances_id = cmd_nuisance
def __init__(self, robot, agent, obs_per_episode): """ """ boot_config = get_boot_config() self.id_robot, self.robot = boot_config.robots.instance_smarter(robot) self.id_agent, self.agent = boot_config.agents.instance_smarter(agent) if self.id_robot is None: self.id_robot = 'robot' if self.id_agent is None: self.id_agent = 'agent' self.obs_per_episode = obs_per_episode
def get_comptests(): # get testing configuration directory from pkg_resources import resource_filename # @UnresolvedImport dirname = resource_filename("boot_agents", "configs") # load into bootstrapping_olympics from comptests import get_comptests_app from bootstrapping_olympics import get_boot_config boot_config = get_boot_config() boot_config.load(dirname) # Our tests are its tests with our configuration import bootstrapping_olympics return bootstrapping_olympics.get_comptests()
def get_bo_config(self): if self.bo_config is None: self.bo_config = get_boot_config() dirs = self.dir_structure.get_config_directories() for dirname in dirs: if not os.path.exists(dirname): msg = ('Warning, the config dir %r does not exist ' % friendly_path(dirname)) logger.info(msg) else: GlobalConfig.global_load_dir(dirname) # self.bo_config.load(dirname) return self.bo_config
def main(): from vehicles_cairo import (cairo_ref_frame, cairo_rototranslate, vehicles_cairo_display_png) # Instance robot object id_robot = 'r_cam_A' filename = 'test.png' resolution = 0.5 config = get_boot_config() cd1 = '/Users/andrea/scm/boot11_env/src/vehicles/src/vehicles/configs' cd2 = '/Users/andrea/scm/boot11_env/src/bvapps/bo_app1/config' GlobalConfig.global_load_dir('default') GlobalConfig.global_load_dir(cd1) GlobalConfig.global_load_dir(cd2) robot = config.robots.instance(id_robot) # @UndefinedVariable robot.new_episode() locations = get_grid(robot=robot, debug=True, world=robot.world, vehicle=robot.vehicle, resolution=resolution) poses = [f['pose'] for f in locations] # poses = elastic(poses, alpha=0.1, num_iterations=20) print('Converting to yaml...') robot.vehicle.set_pose(poses[0]) state = robot.to_yaml() pprint(state) print(yaml_dump(state)) def extra_draw_world(cr): for pose in poses: with cairo_rototranslate(cr, SE2_from_SE3(pose)): cairo_ref_frame(cr, l=0.5, x_color=[0, 0, 0], y_color=[0, 0, 0]) plotting_params = {} plotting_params['extra_draw_world'] = extra_draw_world print('Writing to: %r' % filename) vehicles_cairo_display_png(filename, width=800, height=800, sim_state=state, **plotting_params) print('... done')
def __init__(self, explorer, servo, estimator, skip=1, change_fraction=0.0): """ :param explorer: ID of the explorer agent. :param servo: extra parameters for servo; if string, the ID of an agent. :param skip: only used one every skip observations. """ boot_config = get_boot_config() _, self.explorer = boot_config.agents.instance_smarter(explorer) # @UndefinedVariable self.skip = skip self.change_fraction = change_fraction self.servo = servo self.estimator_spec = estimator
def get_comptests(): # get testing configuration directory from pkg_resources import resource_filename # @UnresolvedImport dirname = resource_filename("vehicles_boot", "configs") from vehicles import get_vehicles_config get_vehicles_config().load('default') # load into bootstrapping_olympics from comptests import get_comptests_app from bootstrapping_olympics import get_boot_config boot_config = get_boot_config() boot_config.load(dirname) # Our tests are its tests with our configuration import bootstrapping_olympics return bootstrapping_olympics.get_comptests()
def init(self, boot_spec): shape = boot_spec.get_observations().shape() is_2D = len(shape) == 2 is_RGB = len(shape) == 3 and shape[2] == 3 if not(is_2D or is_RGB): msg = 'This agent can only work with image-like signals. ' msg = 'Found shape: %r' % str(shape) raise UnsupportedSpec(msg) estimators = get_diffeo2ddslearn_config().diffeosystem_estimators _, self.diffeosystem_estimator = estimators.instance_smarter(self.estimator_spec) self.log_add_child('dds_est', self.diffeosystem_estimator) self.diffeosystem_estimator.set_max_displ(self.max_displ) # initialize explorer agents = get_boot_config().agents _, self.explorer = agents.instance_smarter(self.explorer_spec) self.explorer.init(boot_spec)
def init(self, boot_spec): shape = boot_spec.get_observations().shape() is_2D = len(shape) == 2 is_RGB = len(shape) == 3 and shape[2] == 3 if not (is_2D or is_RGB): msg = 'This agent can only work with image-like signals. ' msg = 'Found shape: %r' % str(shape) raise UnsupportedSpec(msg) estimators = get_diffeo2ddslearn_config().diffeosystem_estimators _, self.diffeosystem_estimator = estimators.instance_smarter( self.estimator_spec) self.log_add_child('dds_est', self.diffeosystem_estimator) self.diffeosystem_estimator.set_max_displ(self.max_displ) # initialize explorer agents = get_boot_config().agents _, self.explorer = agents.instance_smarter(self.explorer_spec) self.explorer.init(boot_spec)
def from_yaml(robot, nuisance): boot_config = get_boot_config() _, robot = boot_config.robots.instance_smarter(robot) _, nuisance = boot_config.nuisances_causal.instance_smarter(nuisance) return EquivRobotCausal(robot=robot, nuisance=nuisance)
def get_config_directories(self): bo_config = get_boot_config() dirs = [] dirs.append(bo_config.get_default_dir()) dirs.append(os.path.join(self.root, DirectoryStructure.DIR_CONFIG)) return dirs