def test_list_overwrite_entry(self, key, lists): first_values, second_values = lists db = GodMap() db.set_data([key], first_values) for i, v in enumerate(first_values): self.assertEqual(db.get_data([key, i]), v) db.set_data([key, i], second_values[i]) for i, v in enumerate(second_values): self.assertEqual(db.get_data([key, i]), v)
def test_clear_cache(self): db = GodMap() d = {'b': 'c'} db.set_data(['a'], d) self.assertEqual('c', db.get_data(['a', 'b'])) db.clear_cache() class C(object): b = 'c' db.set_data(['a'], C()) self.assertEqual('c', db.get_data(['a', 'b']))
def test_function4(self, key1, key2, key3, key4, key5): db = GodMap() class MUH(object): def __call__(self, next_member, next_next_member): return [key5] a = MUH() d = {key2: a} db.set_data([key1], d) self.assertEqual(key5, db.get_data([key1, key2, (key3, key4), 0])) self.assertEqual(key5, db.get_data([key1, key2, (key3, key4), 0])) self.assertEqual(key5, db.get_data([key1, key2, (key3, key4), 0]))
def test_class1(self, key, class_name, key_values): c = type(str(class_name), (object,), {})() for k, v in zip(*key_values): setattr(c, k, None) db = GodMap() db.set_data([key], c) for k, v in zip(*key_values): self.assertEqual(db.get_data([key, k]), None) for k, v in zip(*key_values): db.set_data([key, k], v) for k, v in zip(*key_values): self.assertEqual(db.get_data([key, k]), v)
def test_function3(self, key1, key2, key3, key4, key5): db = GodMap() class MUH(object): def __call__(self, next_member): return [key5] a = MUH() d = {key2: a} db.set_data([key1], d) try: db.get_data([key1, key2, (key3, key4), 0]) assert False except TypeError: assert True
def test_list_double_index(self): key = 'asdf' value = np.array([[0, 1], [2, 3]]) db = GodMap() db.set_data([key], value) for i in range(value.shape[0]): for j in range(value.shape[1]): self.assertEqual(db.get_data([key, i, j]), value[i, j])
def test_dict2(self, key, key_values): d = {} db = GodMap() db.set_data([key], d) for k, v in zip(*key_values): db.set_data([key, k], v) for k, v in zip(*key_values): self.assertEqual(db.get_data([key, k]), v)
def test_class3(self, class_names): db = GodMap() for i, name in enumerate(class_names): c = type(str(name), (object,), {})() db.set_data(class_names[:i + 1], c) for i, name in enumerate(class_names): c = db.get_data(class_names[:i + 1]) self.assertEqual(type(c).__name__, name)
def test_function_2param_call(self, key1, key2, key3, key4): db = GodMap() class MUH(object): def __call__(self, next_member, next_next_member): return next_next_member a = MUH() d = {key2: a} db.set_data([key1], d) self.assertEqual(db.get_data([key1, key2, (key3, key4)]), key4)
def test_function2(self, key, dict_key, return_value): db = GodMap() class MUH(object): def __call__(self, god_map): return return_value a = MUH() d = {dict_key: a} db.set_data([key], d) self.assertEqual(db.get_data([key, dict_key]), return_value)
def test_function_no_param(self, key1, key2, key3): db = GodMap() class MUH(object): def __call__(self): return [key3] a = MUH() d = {key2: a} db.set_data([key1], d) self.assertEqual(key3, db.get_data([key1, key2, tuple(), 0]))
def test_god_map_with_world(self): gm = GodMap() w = World() r = WorldObject(pr2_urdf()) w.add_robot(robot=r, base_pose=PoseStamped(), controlled_joints=[], ignored_pairs=set(), added_pairs=set()) gm.set_data([u'world'], w) gm_robot = gm.get_data(identifier.robot) assert 'pr2' == gm_robot.get_name()
def test_function1(self, key, value): # TODO not clean that i try to call every function db = GodMap() f = lambda gm: value db.set_data([key], f) self.assertEqual(db.get_data([key]), value)
def initialize_god_map(): god_map = GodMap() blackboard = Blackboard blackboard.god_map = god_map load_config_file() god_map.set_data(identifier.rosparam, rospy.get_param(rospy.get_name())) god_map.set_data(identifier.robot_description, rospy.get_param(u'robot_description')) path_to_data_folder = god_map.get_data(identifier.data_folder) # fix path to data folder if not path_to_data_folder.endswith(u'/'): path_to_data_folder += u'/' god_map.set_data(identifier.data_folder, path_to_data_folder) # fix nWSR nWSR = god_map.get_data(identifier.nWSR) if nWSR == u'None': nWSR = None god_map.set_data(identifier.nWSR, nWSR) pbw.start_pybullet(god_map.get_data(identifier.gui)) while not rospy.is_shutdown(): try: controlled_joints = rospy.wait_for_message(u'/whole_body_controller/state', JointTrajectoryControllerState, timeout=5.0).joint_names except ROSException as e: logging.logerr(u'state topic not available') logging.logerr(str(e)) else: break rospy.sleep(0.5) joint_weight_symbols = process_joint_specific_params(identifier.joint_weight, identifier.joint_weight_default, identifier.joint_weight_override, god_map) process_joint_specific_params(identifier.self_collision_avoidance_distance, identifier.self_collision_avoidance_default_threshold, identifier.self_collision_avoidance_default_override, god_map) process_joint_specific_params(identifier.external_collision_avoidance_distance, identifier.external_collision_avoidance_default_threshold, identifier.external_collision_avoidance_default_override, god_map) # TODO add checks to test if joints listed as linear are actually linear joint_velocity_linear_limit_symbols = process_joint_specific_params(identifier.joint_velocity_linear_limit, identifier.joint_velocity_linear_limit_default, identifier.joint_velocity_linear_limit_override, god_map) joint_velocity_angular_limit_symbols = process_joint_specific_params(identifier.joint_velocity_angular_limit, identifier.joint_velocity_angular_limit_default, identifier.joint_velocity_angular_limit_override, god_map) joint_acceleration_linear_limit_symbols = process_joint_specific_params(identifier.joint_acceleration_linear_limit, identifier.joint_acceleration_linear_limit_default, identifier.joint_acceleration_linear_limit_override, god_map) joint_acceleration_angular_limit_symbols = process_joint_specific_params( identifier.joint_acceleration_angular_limit, identifier.joint_acceleration_angular_limit_default, identifier.joint_acceleration_angular_limit_override, god_map) world = PyBulletWorld(False, blackboard.god_map.get_data(identifier.data_folder)) god_map.set_data(identifier.world, world) robot = WorldObject(god_map.get_data(identifier.robot_description), None, controlled_joints) world.add_robot(robot, None, controlled_joints, ignored_pairs=god_map.get_data(identifier.ignored_self_collisions), added_pairs=god_map.get_data(identifier.added_self_collisions)) joint_position_symbols = JointStatesInput(blackboard.god_map.to_symbol, world.robot.get_movable_joints(), identifier.joint_states, suffix=[u'position']) joint_vel_symbols = JointStatesInput(blackboard.god_map.to_symbol, world.robot.get_movable_joints(), identifier.joint_states, suffix=[u'velocity']) world.robot.update_joint_symbols(joint_position_symbols.joint_map, joint_vel_symbols.joint_map, joint_weight_symbols, joint_velocity_linear_limit_symbols, joint_velocity_angular_limit_symbols, joint_acceleration_linear_limit_symbols, joint_acceleration_angular_limit_symbols) world.robot.init_self_collision_matrix() return god_map
def test_namedtuple(self, key, tuple_name, key_values): Frame = namedtuple(tuple_name, key_values[0]) db = GodMap() db.set_data([key], Frame(*key_values[1])) for k, v in zip(*key_values): self.assertEqual(db.get_data([key, k]), v)
def test_set_get_float(self, key, number): db = GodMap() db.set_data([key], number) db.set_data([key], number) self.assertEqual(db.get_data([key]), number)
def test_set_get_integer2(self, key, number): db = GodMap() db.set_data([key], number) self.assertEqual(db.get_data([key]), number, msg=u'key={}, number={}'.format(key, number)) self.assertEqual(db.get_data([key]), number, msg=u'key={}, number={}'.format(key, number))
def test_attribute_error(self): db = GodMap() class C(object): asdf = 1 db.unsafe_set_data(['c'], C()) self.assertEqual(db.get_data(['c', 'a']), db.default_value)
def test_god_map_key_error(self, key, wrong_key, number, default_value): assume(key != wrong_key) db = GodMap(default_value) db.set_data([key], number) self.assertEqual(db.get_data([wrong_key]), default_value, msg=u'key={}, number={}'.format(key, number))
def test_index_error(self): db = GodMap() db.unsafe_set_data(['l'], [1, 2, 3]) self.assertEqual(db.get_data(['l', '5']), db.default_value)
def test_dict3(self, key, tuple_key, value): tuple_key = tuple(tuple_key) d = {tuple_key: value} db = GodMap() db.set_data([key], d) self.assertEqual(db.get_data([key, tuple_key]), value)
def test_function_1param_lambda(self, key, key2): db = GodMap() f = lambda x: x db.set_data([key], f) self.assertEqual(db.get_data([key, (key2,)]), key2)
def test_list_negative_index(self, key, l): db = GodMap() db.set_data([key], l) for i in range(len(l)): self.assertEqual(db.get_data([key, -i]), l[-i])
def test_tuple1(self, key, value): value = tuple(value) db = GodMap() db.set_data([key], value) for i, v in enumerate(value): self.assertEqual(db.get_data([key, i]), v)