def boot_robot_adapter_main(params): check_parameters(params, required=['robot_spec', 'root'], optional=['maximum_interval', 'sleep']) data_central = DataCentral(params['root']) bo_config = data_central.get_bo_config() sleep = params.get('sleep', 0.0) maximum_interval = params.get('maximum_interval', 2) robot_spec = params['robot_spec'] # check_valid_robot_config(robot_spec) robot = bo_config.robots.instance_spec(robot_spec) # @UndefinedVariable adapter = BootRobotAdapter(id_robot=robot_spec['id'], robot=robot, maximum_interval=maximum_interval, sleep=sleep) adapter.loop()
def boot_agent_adapter_main(params): Global.logger = RospyLogger("agent_adapter") Global.logger.info("My params:\n%s" % pformat(params)) check_parameters(params, required=["agent_spec", "root"], optional=["publish_interval"]) data_central = DataCentral(params["root"]) bo_config = data_central.get_bo_config() publish_interval = params.get("publish_interval", 0) agent_spec = params["agent_spec"] # check_valid_agent_config(agent_spec) agent = bo_config.agents.instance_spec(agent_spec) # @UndefinedVariable id_agent = agent_spec["id"] AgentInterface.logger = RospyLogger(id_agent) agent_adapter = BootAgentAdapter( data_central=data_central, id_agent=id_agent, agent=agent, publish_interval=publish_interval ) agent_adapter.go()
def check_basic_ops(id_agent, agent, id_robot, robot): # @UnusedVariable with create_tmp_dir() as root: os.mkdir(os.path.join(root, 'config')) data_central = DataCentral(root) ds = data_central.get_dir_structure() log_index = data_central.get_log_index() def simulate_some(n): simulate(data_central, id_agent=id_agent, id_robot=id_robot, max_episode_len=2, num_episodes=n, cumulative=False, id_episodes=None, stateful=False, interval_print=None, write_extra=True) assert not log_index.has_streams_for_robot(id_robot) formats = LogsFormat.formats.keys() try: for logs_format in formats: ds.set_log_format(logs_format) simulate_some(2) simulate_some(2) except UnsupportedSpec: return assert not log_index.has_streams_for_robot(id_robot) log_index.reindex() assert log_index.has_streams_for_robot(id_robot) def expect_num(found, num, msg=""): if num == found: return msg += '-- Expected %d logs/streams, found %d. ' % (num, found) msg += '\n' + log_index.debug_summary(ignore_cache=False) raise Exception(msg) expect_num(len(log_index.get_streams_for_robot(id_robot)), 2 * len(formats)) expect_num(len(log_index.get_streams_for(id_robot, id_agent)), 2 * len(formats), "Looking for %r/%r" % (id_robot, id_agent)) log_index.get_robot_spec(id_robot) expect_num(len(log_index.get_episodes_for_robot(id_robot)), 4 * len(formats)) expect_num(len(log_index.get_episodes_for_robot(id_robot, id_agent)), 4 * len(formats)) learn_log(data_central, id_robot=id_robot, id_agent=id_agent) try: task_servo(data_central, id_agent, id_robot, max_episode_len=1, num_episodes=1, displacement=1, id_episodes=None, cumulative=False, interval_print=None, num_episodes_with_robot_state=0) except NotImplementedError: msg = 'Agent does not implement servo' print(msg) try: task_predict(data_central, id_agent=id_agent, id_robot=id_robot) except NotImplementedError: msg = 'Agent does not implement predictor' print(msg)