def __init__(self, port: int = 1071, all_flex_objects=True, use_cloth=False, use_squishy=False, use_fluid=False, step_physics=False, middle_scale_range=0.5, **kwargs): Dominoes.__init__(self, port=port, **kwargs) self._clear_flex_data() self.all_flex_objects = all_flex_objects self._set_add_physics_object() self.step_physics = step_physics self.use_cloth = use_cloth self.use_squishy = use_squishy self.use_fluid = use_fluid self.middle_scale_range = middle_scale_range print("MIDDLE SCALE RANGE", self.middle_scale_range) if self.use_fluid: self.ft_selection = random.choice(self.FLUID_TYPES.fluid_type_names)
def clear_static_data(self) -> None: Dominoes.clear_static_data(self) self.tower_height = 0.0 self.target_link_idx = None self.base = None self.attachment = None
def _write_static_data(self, static_group: h5py.Group) -> None: Dominoes._write_static_data(self, static_group) static_group.create_dataset("base_id", data=self.base_id) static_group.create_dataset("use_base", data=self.use_base) static_group.create_dataset("base_type", data=self.base_type) static_group.create_dataset("attachment_id", data=self.attachment_id) static_group.create_dataset("attachent_type", data=self.attachment_type) static_group.create_dataset("use_attachment", data=self.use_attachment) static_group.create_dataset("link_type", data=self.middle_type) static_group.create_dataset("num_links", data=self.num_links) static_group.create_dataset("target_link_idx", data=self.target_link_idx) static_group.create_dataset("attachment_fixed", data=self.attachment_fixed_to_base) static_group.create_dataset("use_cap", data=self.use_cap)
def get_scene_initialization_commands(self) -> List[dict]: commands = Dominoes.get_scene_initialization_commands(self) commands[0].update({'convexify': True}) create_container = { "$type": "create_flex_container", # "collision_distance": 0.001, "collision_distance": 0.025, # "collision_distance": 0.1, "static_friction": 1.0, "dynamic_friction": 1.0, "radius": 0.1875, 'max_particles': 50000} # 'max_particles': 250000} if self.use_fluid: create_container.update({ 'viscosity': self.FLUID_TYPES.fluid_types[self.ft_selection].viscosity, 'adhesion': self.FLUID_TYPES.fluid_types[self.ft_selection].adhesion, 'cohesion': self.FLUID_TYPES.fluid_types[self.ft_selection].cohesion, 'fluid_rest': 0.05, 'damping': 0.01, 'subsetp_count': 5, 'iteration_count': 8, 'buoyancy': 1.0}) commands.append(create_container) if self.use_fluid: commands.append({"$type": "set_time_step", "time_step": 0.005}) return commands
def _place_ramp_under_probe(self) -> List[dict]: cmds = Dominoes._place_ramp_under_probe(self) self.non_flex_objects.append(self.ramp_id) if self.ramp_base_height >= 0.01: self.non_flex_objects.append(self.ramp_base_id) return cmds
def __init__(self, port: int = 1071, all_flex_objects=True, use_cloth=False, use_squishy=False, use_fluid=False, step_physics=False, tether_stiffness_range = [0.0, 1.0], bend_stiffness_range = [0.0, 1.0],#[0.0, 1.0], stretch_stiffness_range = [0.0, 1.0], min_distance_ratio = 0.5, max_distance_ratio = 0.5, min_anchorloc = -0.4, max_anchorloc = 0.4, anchor_height = 0.5, anchor_jitter = 0.2,#0.2, height_jitter = 0.2,#0.3, collision_label_threshold=0.1, **kwargs): Dominoes.__init__(self, port=port, **kwargs) self._clear_flex_data() self.all_flex_objects = all_flex_objects self._set_add_physics_object() self.step_physics = step_physics self.use_cloth = use_cloth self.use_squishy = use_squishy self.use_fluid = use_fluid if self.use_fluid: self.ft_selection = random.choice(self.FLUID_TYPES.fluid_type_names) self.tether_stiffness_range = tether_stiffness_range self.bend_stiffness_range = bend_stiffness_range self.stretch_stiffness_range = stretch_stiffness_range self.min_distance_ratio = min_distance_ratio self.max_distance_ratio = max_distance_ratio self.min_anchorloc = min_anchorloc self.max_anchorloc = max_anchorloc self.anchor_height = anchor_height self.anchor_jitter = anchor_jitter self.height_jitter = height_jitter # for detecting collisions self.collision_label_thresh = collision_label_threshold
def _write_frame_labels( self, frame_grp: h5py.Group, resp: List[bytes], frame_num: int, sleeping: bool) -> Tuple[h5py.Group, List[bytes], int, bool]: labels, resp, frame_num, done = Dominoes._write_frame_labels( self, frame_grp, resp, frame_num, sleeping) return labels, resp, frame_num, done
def _get_push_cmd(self, o_id, position_or_particle=None): if not self.all_flex_objects: return Dominoes._get_push_cmd(self, o_id, position_or_particle) cmd = {"$type": "apply_force_to_flex_object", "force": self.push_force, "id": o_id, "particle": -1} print("PUSH CMD FLEX") print(cmd) return cmd
def __init__(self, port: int = 1071, middle_scale_range=1.0, middle_color=None, middle_material=None, middle_friction=0.1, remove_middle=False, **kwargs): Dominoes.__init__(self, port=port, **kwargs) # always use a ramp for probe self.use_ramp = True # middle self.middle_color = middle_color self.middle_material = middle_material self.middle_friction = middle_friction self.middle_objects = [] self.remove_middle = remove_middle
def get_controller_label_funcs(classname="Tower"): funcs = Dominoes.get_controller_label_funcs(classname) def num_middle_objects(f): try: return int(np.array(f['static']['num_blocks'])) except KeyError: return int(len(f['static']['mass'] - 3)) def did_tower_fall(f): return is_trial_valid(f, valid_key='did_fall') funcs += [num_middle_objects, did_tower_fall] return funcs
def add_rigid_physics_object(self, *args, **kwargs): """ Make sure controller knows to treat probe, zone, target, etc. as non-flex objects """ o_id = kwargs.get('o_id', None) if o_id is None: o_id: int = self.get_unique_id() kwargs['o_id'] = o_id commands = Dominoes.add_physics_object(self, *args, **kwargs) self.non_flex_objects.append(o_id) print("Add rigid physics object", o_id) return commands
def clear_static_data(self) -> None: Dominoes.clear_static_data(self)
def get_controller_label_funcs(classname = "Linking"): funcs = Dominoes.get_controller_label_funcs(classname) return funcs
def get_controller_label_funcs(classname = "Barrier"): funcs = Dominoes.get_controller_label_funcs(classname) return funcs
def get_trial_initialization_commands(self) -> List[dict]: # clear the flex data FlexDataset.get_trial_initialization_commands(self) return Dominoes.get_trial_initialization_commands(self)
def _get_send_data_commands(self) -> List[dict]: commands = Dominoes._get_send_data_commands(self) commands.extend(FlexDataset._get_send_data_commands(self)) return commands
def _write_static_data(self, static_group: h5py.Group) -> None: Dominoes._write_static_data(self, static_group) static_group.create_dataset("bridge_height", data=self.bridge_height)
def _write_static_data(self, static_group: h5py.Group) -> None: Dominoes._write_static_data(self, static_group) self.middle_type = type(self).__name__ static_group.create_dataset("middle_type", data=self.middle_type)
def _write_static_data(self, static_group: h5py.Group) -> None: Dominoes._write_static_data(self, static_group)
def _place_target_object(self) -> List[dict]: self._fixed_target = True return Dominoes._place_target_object( self, size_range=self.target_scale_range)
def get_controller_label_funcs(classname="Containment"): funcs = Dominoes.get_controller_label_funcs(classname) return funcs
def _place_and_push_probe_object(self) -> List[dict]: return Dominoes._place_and_push_probe_object( self, size_range=self.probe_scale_range)
def get_per_frame_commands(self, resp: List[bytes], frame: int) -> List[dict]: cmds = Dominoes.get_per_frame_commands(self, resp=resp, frame=frame) return cmds
def get_controller_label_funcs(classname="Collision"): funcs = Dominoes.get_controller_label_funcs(classname) return funcs
def get_controller_label_funcs(classname = "Rolling_Sliding"): funcs = Dominoes.get_controller_label_funcs(classname) return funcs