def action( self, obj: hsim.SceneNode, action_name: str, actuation_spec: ActuationSpec, apply_filter: bool = True, ): r"""Performs the action specified by :py:attr:`action_name` on the object Args: obj (hsim.SceneNode): SceneNode to perform the action on action_name (str): Name of the action. Used to index the move_func_map to retrieve the function which implements this action actuation_spec (ActuationSpec): Specifies the parameters needed by the function apply_filter (bool): Whether or not to apply the move_filter_fn after the action """ assert ( action_name in move_func_map), f"No action named {action_name} in the move map" start_pos = obj.absolute_position() move_func_map[action_name](obj, actuation_spec) end_pos = obj.absolute_position() if apply_filter: filter_end = self.move_filter_fn(start_pos, end_pos) obj.translate(filter_end - end_pos)
def action( self, obj: hsim.SceneNode, action_name: str, actuation_spec: ActuationSpec, apply_filter: bool = True, ) -> bool: r"""Performs the action specified by :py:attr:`action_name` on the object Args: obj (hsim.SceneNode): SceneNode to perform the action on action_name (str): Name of the action. Used to index the move_func_map to retrieve the function which implements this action actuation_spec (ActuationSpec): Specifies the parameters needed by the function apply_filter (bool): Whether or not to apply the move_filter_fn after the action Returns: bool: Whether or not the action taken resulted in a collision """ assert ( action_name in move_func_map), f"No action named {action_name} in the move map" start_pos = obj.absolute_translation move_func_map[action_name](obj, actuation_spec) end_pos = obj.absolute_translation collided = False if apply_filter: filter_end = self.move_filter_fn(start_pos, end_pos) # Update the position to respect the filter obj.translate(filter_end - end_pos) dist_moved_before_filter = (end_pos - start_pos).dot() dist_moved_after_filter = (filter_end - start_pos).dot() # NB: There are some cases where ||filter_end - end_pos|| > 0 when a # collision _didn't_ happen. One such case is going up stairs. Instead, # we check to see if the the amount moved after the application of the filter # is _less_ the the amount moved before the application of the filter collided = (dist_moved_after_filter + EPS) < dist_moved_before_filter return collided
def action( self, obj: hsim.SceneNode, action_name: str, actuation_spec: ActuationSpec, apply_filter: bool = True, ) -> bool: r"""Performs the action specified by :p:`action_name` on the object :param obj: `scene.SceneNode` to perform the action on :param action_name: Name of the action. Used to query the `registry` to retrieve the function which implements this action :param actuation_spec: Specifies the parameters needed by the function :param apply_filter: Whether or not to apply the `move_filter_fn` after the action :return: Whether or not the action taken resulted in a collision """ start_pos = obj.absolute_translation move_fn = registry.get_move_fn(action_name) assert move_fn is not None, f"No move_fn for action '{action_name}'" move_fn(obj, actuation_spec) end_pos = obj.absolute_translation collided = False if apply_filter: filter_end = self.move_filter_fn(start_pos, end_pos) # Update the position to respect the filter obj.translate(filter_end - end_pos) dist_moved_before_filter = (end_pos - start_pos).dot() dist_moved_after_filter = (filter_end - start_pos).dot() # NB: There are some cases where ||filter_end - end_pos|| > 0 when a # collision _didn't_ happen. One such case is going up stairs. Instead, # we check to see if the the amount moved after the application of the filter # is _less_ the the amount moved before the application of the filter collided = (dist_moved_after_filter + EPS) < dist_moved_before_filter return collided