Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

migrate to robot_descriptions #2

Merged
merged 1 commit into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ default_configurations:

arm:
_target_: mujoco_robot_environments.models.arms.franka_emika.FER
mjcf_path: "../mujoco_pkgs/mujoco_menagerie/franka_emika_panda/panda_nohand.xml"
actuator_config: ${robots.arm.actuator_config}
sensor_config: ${robots.arm.sensor_config}
controller_config: ${robots.arm.controller_config}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ defaults:

end_effector:
_target_: mujoco_robot_environments.models.end_effectors.robotiq_2f85.Robotiq2F85
mjcf_path: "../mujoco_pkgs/mujoco_menagerie/robotiq_2f85/2f85.xml"
actuator_config: ${robots.end_effector.actuator_config}
sensor_config: ${robots.end_effector.sensor_config}
controller_config: ${robots.end_effector.controller_config}
26 changes: 23 additions & 3 deletions mujoco_robot_environments/models/arms/franka_emika.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
"""Franka Emika Panda Robot Arm."""

import os
import numpy as np

from dm_control import mjcf
from robot_descriptions import panda_mj_description
from mujoco_controllers.models.arms.robot_arm import RobotArm

PANDA_MJCF_PATH = os.path.join(panda_mj_description.PACKAGE_PATH, 'panda_nohand.xml')

class FER(RobotArm):
"""Franka Emika Panda Robot Arm."""

def __init__(self, mjcf_path: str, actuator_config: dict, sensor_config: dict=None, controller_config: dict=None, configuration_config: dict=None):
def __init__(
self,
mjcf_path: str = PANDA_MJCF_PATH,
actuator_config: dict = None,
sensor_config: dict = None,
controller_config: dict = None,
configuration_config: dict = None
):
"""Initialize the robot arm."""
self.mjcf_path = mjcf_path
self.actuator_config = actuator_config
Expand All @@ -20,19 +30,29 @@ def __init__(self, mjcf_path: str, actuator_config: dict, sensor_config: dict=No
super().__init__()

def _build(self):
self._fer_root = mjcf.from_path(self.mjcf_path)
self._fer_root = mjcf.from_path(self.mjcf_path, escape_separators=True)
for keyframe in self._fer_root.find_all('key'):
keyframe.remove()

# assign joints
self._joints = self._fer_root.find_all("joint")

# add sensors and actuators
self._add_actuators()
self._add_sensors()
self._actuators = self._fer_root.find_all("actuator")
self._add_sensors()

# define attachment and wrist sites
self._attachment_site = self._fer_root.find("site", "attachment_site")
self._wrist_site = self._attachment_site

# TODO: Refactor this
def _add_actuators(self):
"""Override the actuator model by config."""
# remove default actuator models from mjcf
for actuator in self._fer_root.find_all('actuator'):
actuator.remove()

if self.actuator_config["type"] == "motor":
for idx, (joint, joint_type) in enumerate(self.actuator_config["joint_actuator_mapping"].items()):
print("Adding actuator for joint: {}".format(joint))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@
from typing import List, Tuple, Optional

from dm_control import mjcf
from robot_descriptions import robotiq_2f85_mj_description
from mujoco_controllers.models.end_effectors.robot_hand import RobotHand
import numpy as np

ROBOTIQ_MJCF_PATH = robotiq_2f85_mj_description.MJCF_PATH

class Robotiq2F85(RobotHand):
"""Robotiq 2-finger 85 adaptive gripper."""

def __init__(self,
mjcf_path: str,
mjcf_path: str = ROBOTIQ_MJCF_PATH,
actuator_config: dict = None, # for now we don't alter default actuator config
sensor_config: dict = None,
controller_config: dict = None,
Expand Down Expand Up @@ -41,8 +44,6 @@ def _build(self):
self._actuators = self.robotiq_root.find_all('actuator')
self._tool_center_point = self.robotiq_root.find('site', 'pinch')

# consider adding tcp site

@property
def joints(self):
"""List of joint elements belonging to the hand."""
Expand Down
2 changes: 0 additions & 2 deletions mujoco_robot_environments/tasks/rearrangement.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ def __init__(
"""Initializes the simulation environment from config."""
# ensure mjcf paths are relative to this file
file_path = Path(__file__).parent.absolute()
cfg.robots.arm.arm.mjcf_path = str(file_path / cfg.robots.arm.arm.mjcf_path)
cfg.robots.end_effector.end_effector.mjcf_path = str(file_path / cfg.robots.end_effector.end_effector.mjcf_path)
self._cfg = cfg

# check if viewer is requested in input args, otherwise use config
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ dm-reverb = {version="0.13.0", markers = "sys_platform == 'linux'"}
tensorflow-cpu = {version="^2.14.0", markers = "sys_platform == 'linux'"}
envlogger = {extras = ["tfds"], version = "^1.2", markers = "sys_platform == 'linux'"}
rlds = {version="^0.1.7", markers = "sys_platform == 'linux'"}
robot-descriptions = "^1.10.0"

[tool.black]
line-length = 120
Expand Down
Loading