Skip to content

Commit

Permalink
change composite controller keyword body_parts_controller_configs -> …
Browse files Browse the repository at this point in the history
…body_parts (#558)
  • Loading branch information
snasiriany authored Nov 14, 2024
1 parent 9c77528 commit f8a9de1
Show file tree
Hide file tree
Showing 23 changed files with 32 additions and 36 deletions.
2 changes: 1 addition & 1 deletion docs/modules/controllers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ An example of the controller config file is shown below (many parameters are omi
{
"type": "BASIC",
"body_parts_controller_configs": {
"body_parts": {
"arms": {
"right": {
"type": "OSC_POSE",
Expand Down
18 changes: 9 additions & 9 deletions robosuite/controllers/composite/composite_controller_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

def validate_composite_controller_config(config: dict):
# Check top-level keys
required_keys = ["type", "body_parts_controller_configs"]
required_keys = ["type", "body_parts"]
for key in required_keys:
if key not in config:
ROBOSUITE_DEFAULT_LOGGER.error(f"Missing top-level key: {key}")
Expand All @@ -32,7 +32,7 @@ def is_part_controller_config(config: Dict):
"""

PART_CONTROLLER_TYPES = ["JOINT_VELOCITY", "JOINT_TORQUE", "JOINT_POSITION", "OSC_POSITION", "OSC_POSE", "IK_POSE"]
if "body_parts_controller_configs" not in config and "type" in config:
if "body_parts" not in config and "type" in config:
return config["type"] in PART_CONTROLLER_TYPES
return False

Expand Down Expand Up @@ -62,11 +62,11 @@ def refactor_composite_controller_config(controller_config, robot_type, arms):
else:
new_controller_config = {}
new_controller_config["type"] = "BASIC"
new_controller_config["body_parts_controller_configs"] = {}
new_controller_config["body_parts"] = {}

for arm in arms:
new_controller_config["body_parts_controller_configs"][arm] = copy.deepcopy(controller_config)
new_controller_config["body_parts_controller_configs"][arm]["gripper"] = {"type": "GRIP"}
new_controller_config["body_parts"][arm] = copy.deepcopy(controller_config)
new_controller_config["body_parts"][arm]["gripper"] = {"type": "GRIP"}
return new_controller_config


Expand Down Expand Up @@ -126,14 +126,14 @@ def load_composite_controller_config(controller: Optional[str] = None, robot: Op
raise

validate_composite_controller_config(composite_controller_config)
body_parts_controller_configs = composite_controller_config.pop("body_parts_controller_configs", {})
composite_controller_config["body_parts_controller_configs"] = {}
body_parts_controller_configs = composite_controller_config.pop("body_parts", {})
composite_controller_config["body_parts"] = {}
for part_name, part_config in body_parts_controller_configs.items():
if part_name == "arms":
for arm_name, arm_config in part_config.items():
composite_controller_config["body_parts_controller_configs"][arm_name] = arm_config
composite_controller_config["body_parts"][arm_name] = arm_config
else:
composite_controller_config["body_parts_controller_configs"][part_name] = part_config
composite_controller_config["body_parts"][part_name] = part_config

return composite_controller_config

Expand Down
2 changes: 1 addition & 1 deletion robosuite/controllers/config/default/composite/basic.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"type": "BASIC",
"body_parts_controller_configs": {
"body_parts": {
"arms": {
"right": {
"type": "OSC_POSE",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"type": "HYBRID_MOBILE_BASE",
"body_parts_controller_configs": {
"body_parts": {
"arms": {
"right": {
"type": "OSC_POSE",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"ik_input_rotation_repr": "axis_angle",
"verbose": false
},
"body_parts_controller_configs": {
"body_parts": {
"arms": {
"right": {
"type" : "JOINT_POSITION",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"ik_hand_ori_cost": 0.5,
"use_joint_angle_action_input": false
},
"body_parts_controller_configs": {
"body_parts": {
"arms": {
"right": {
"type" : "JOINT_POSITION",
Expand Down
2 changes: 1 addition & 1 deletion robosuite/controllers/config/robots/default_baxter.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"type": "BASIC",
"body_parts_controller_configs": {
"body_parts": {
"arms": {
"right": {
"type": "OSC_POSE",
Expand Down
2 changes: 1 addition & 1 deletion robosuite/controllers/config/robots/default_gr1.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"ik_input_rotation_repr": "axis_angle",
"ik_verbose": true
},
"body_parts_controller_configs": {
"body_parts": {
"arms": {
"right": {
"type" : "JOINT_POSITION",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"ik_hand_ori_cost": 0.5,
"use_joint_angle_action_input": false
},
"body_parts_controller_configs": {
"body_parts": {
"arms": {
"right": {
"type" : "JOINT_POSITION",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"type": "HYBRID_MOBILE_BASE",
"body_parts_controller_configs": {
"body_parts": {
"arms": {
"right": {
"type": "OSC_POSE",
Expand Down
2 changes: 1 addition & 1 deletion robosuite/controllers/config/robots/default_iiwa.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"type": "BASIC",
"body_parts_controller_configs": {
"body_parts": {
"arms": {
"right": {
"type": "OSC_POSE",
Expand Down
2 changes: 1 addition & 1 deletion robosuite/controllers/config/robots/default_kinova3.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"type": "BASIC",
"body_parts_controller_configs": {
"body_parts": {
"arms": {
"right": {
"type": "OSC_POSE",
Expand Down
2 changes: 1 addition & 1 deletion robosuite/controllers/config/robots/default_panda.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"type": "BASIC",
"body_parts_controller_configs": {
"body_parts": {
"arms": {
"right": {
"type": "OSC_POSE",
Expand Down
2 changes: 1 addition & 1 deletion robosuite/controllers/config/robots/default_panda_dex.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"type": "BASIC",
"body_parts_controller_configs": {
"body_parts": {
"arms": {
"right": {
"type": "OSC_POSE",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"type": "HYBRID_MOBILE_BASE",
"body_parts_controller_configs": {
"body_parts": {
"arms": {
"right": {
"type": "OSC_POSE",
Expand Down
2 changes: 1 addition & 1 deletion robosuite/controllers/config/robots/default_sawyer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"type": "BASIC",
"body_parts_controller_configs": {
"body_parts": {
"arms": {
"right": {
"type": "OSC_POSE",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"type": "BASIC",
"body_parts_controller_configs": {
"body_parts": {
"arms": {
"right": {
"type": "OSC_POSE",
Expand Down
2 changes: 1 addition & 1 deletion robosuite/controllers/config/robots/default_tiago.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"ik_input_rotation_repr": "axis_angle",
"verbose": false
},
"body_parts_controller_configs": {
"body_parts": {
"arms": {
"right": {
"type": "OSC_POSE",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"ik_input_rotation_repr": "axis_angle",
"verbose": false
},
"body_parts_controller_configs": {
"body_parts": {
"arms": {
"right": {
"type" : "JOINT_POSITION",
Expand Down
2 changes: 1 addition & 1 deletion robosuite/controllers/config/robots/default_ur5e.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"type": "BASIC",
"body_parts_controller_configs": {
"body_parts": {
"arms": {
"right": {
"type": "OSC_POSE",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"ik_hand_ori_cost": 0.5,
"use_joint_angle_action_input": false
},
"body_parts_controller_configs": {
"body_parts": {
"arms": {
"right": {
"type" : "JOINT_POSITION",
Expand Down
8 changes: 2 additions & 6 deletions robosuite/robots/robot.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@ def __init__(
else:
self.composite_controller_config = load_composite_controller_config(robot=robot_type)

self.part_controller_config = copy.deepcopy(
self.composite_controller_config.get("body_parts_controller_configs", {})
)
self.part_controller_config = copy.deepcopy(self.composite_controller_config.get("body_parts", {}))

self.gripper = self._input2dict(None)
self.gripper_type = self._input2dict(gripper_type)
Expand Down Expand Up @@ -148,9 +146,7 @@ def _postprocess_part_controller_config(self):
Remove unused parts that are not in the controller.
Called by _load_controller() function
"""
for part_name, controller_config in self.composite_controller_config.get(
"body_parts_controller_configs", {}
).items():
for part_name, controller_config in self.composite_controller_config.get("body_parts", {}).items():
if not self.has_part(part_name):
ROBOSUITE_DEFAULT_LOGGER.warn(
f'The config has defined for the controller "{part_name}", '
Expand Down
2 changes: 1 addition & 1 deletion tests/test_controllers/test_variable_impedance.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def test_variable_impedance():
np.random.seed(3)

composite_controller_config = load_composite_controller_config(controller=None, robot="Sawyer")
controller_config = composite_controller_config["body_parts_controller_configs"]["right"]
controller_config = composite_controller_config["body_parts"]["right"]
controller_config["type"] = controller_name
# Manually edit impedance settings
controller_config["impedance_mode"] = "variable"
Expand Down

0 comments on commit f8a9de1

Please sign in to comment.