Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feat/controller-dependencies' in…
Browse files Browse the repository at this point in the history
…to feat/controller-dependencies
  • Loading branch information
cremebrule committed Oct 18, 2024
2 parents 7034557 + e51d82c commit c6e89fc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
31 changes: 21 additions & 10 deletions omnigibson/objects/controllable_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ def _load_controllers(self):
self._controllers = dict()
# Keep track of any controllers that are dependencies of other controllers
# We will not instantiate dependent controllers
controller_dependencies = dict() # Maps independent controller name to list of dependencies
controller_dependencies = dict() # Maps independent controller name to list of dependencies
dependent_names = set()
for name in self._raw_controller_order:
# Make sure we have the valid controller name specified
Expand All @@ -243,15 +243,18 @@ def _load_controllers(self):
# If this controller has dependencies, it cannot be a dependency for another controller
# (i.e.: we don't allow nested / cyclical dependencies)
if len(dependencies) > 0:
assert name not in dependent_names, \
f"Controller {name} has dependencies, and therefore cannot be a dependency for another controller!"
assert (
name not in dependent_names
), f"Controller {name} has dependencies, and therefore cannot be a dependency for another controller!"
controller_dependencies[name] = dependencies
for dependent_name in dependencies:
# Make sure it doesn't already exist -- a controller should only be the dependency of up to one other
assert dependent_name not in dependent_names, \
f"Controller {dependent_name} cannot be a dependency of more than one other controller!"
assert dependent_name not in controller_dependencies, \
f"Controller {name} has dependencies, and therefore cannot be a dependency for another controller!"
assert (
dependent_name not in dependent_names
), f"Controller {dependent_name} cannot be a dependency of more than one other controller!"
assert (
dependent_name not in controller_dependencies
), f"Controller {name} has dependencies, and therefore cannot be a dependency for another controller!"
dependent_names.add(dependent_name)

# Loop over all controllers, in the order corresponding to @action dim
Expand Down Expand Up @@ -664,11 +667,19 @@ def _add_task_frame_control_dict(self, fcns, task_name, link_name):
task_name (str): name to assign for this task_frame. It will be prepended to all fcns generated
link_name (str): the corresponding link name from this controllable object that @task_name is referencing
"""
fcns[f"_{task_name}_pos_quat_relative"] = lambda: ControllableObjectViewAPI.get_link_relative_position_orientation(self.articulation_root_path, link_name)
fcns[f"_{task_name}_pos_quat_relative"] = (
lambda: ControllableObjectViewAPI.get_link_relative_position_orientation(
self.articulation_root_path, link_name
)
)
fcns[f"{task_name}_pos_relative"] = lambda: fcns[f"_{task_name}_pos_quat_relative"][0]
fcns[f"{task_name}_quat_relative"] = lambda: fcns[f"_{task_name}_pos_quat_relative"][1]
fcns[f"{task_name}_lin_vel_relative"] = lambda: ControllableObjectViewAPI.get_link_relative_linear_velocity(self.articulation_root_path, link_name)
fcns[f"{task_name}_ang_vel_relative"] = lambda: ControllableObjectViewAPI.get_link_relative_angular_velocity(self.articulation_root_path, link_name)
fcns[f"{task_name}_lin_vel_relative"] = lambda: ControllableObjectViewAPI.get_link_relative_linear_velocity(
self.articulation_root_path, link_name
)
fcns[f"{task_name}_ang_vel_relative"] = lambda: ControllableObjectViewAPI.get_link_relative_angular_velocity(
self.articulation_root_path, link_name
)
# -n_joints because there may be an additional 6 entries at the beginning of the array, if this robot does
# not have a fixed base (i.e.: the 6DOF --> "floating" joint)
# see self.get_relative_jacobian() for more info
Expand Down
4 changes: 3 additions & 1 deletion omnigibson/robots/articulated_trunk_robot.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ def get_control_dict(self):
fcns = super().get_control_dict()

# Add relevant trunk values
self._add_task_frame_control_dict(fcns=fcns, task_name="trunk", link_name=self.joints[self.trunk_joint_names[-1]].body1.split("/")[-1])
self._add_task_frame_control_dict(
fcns=fcns, task_name="trunk", link_name=self.joints[self.trunk_joint_names[-1]].body1.split("/")[-1]
)

return fcns

Expand Down

0 comments on commit c6e89fc

Please sign in to comment.