forked from gzz2000/robolite
-
Notifications
You must be signed in to change notification settings - Fork 1
/
robot.py
62 lines (46 loc) · 1.81 KB
/
robot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
from collections import OrderedDict
from robosuite.models.base import MujocoXML
from robosuite.utils import XMLError
class Robot(MujocoXML):
"""Base class for all robot models."""
def __init__(self, fname):
"""Initializes from file @fname."""
super().__init__(fname)
# key: gripper name and value: gripper model
self.grippers = OrderedDict()
def add_gripper(self, arm_name, gripper):
"""
Mounts gripper to arm.
Throws error if robot already has a gripper or gripper type is incorrect.
Args:
arm_name (str): name of arm mount
gripper (MujocoGripper instance): gripper MJCF model
"""
if arm_name in self.grippers:
raise ValueError("Attempts to add multiple grippers to one body")
arm_subtree = self.worldbody.find(".//body[@name='{}']".format(arm_name))
for actuator in gripper.actuator:
if actuator.get("name") is None:
raise XMLError("Actuator has no name")
if not actuator.get("name").startswith("gripper"):
raise XMLError(
"Actuator name {} does not have prefix 'gripper'".format(
actuator.get("name")
)
)
for body in gripper.worldbody:
arm_subtree.append(body)
self.merge(gripper, merge_body=False)
self.grippers[arm_name] = gripper
@property
def dof(self):
"""Returns the number of DOF of the robot, not including gripper."""
raise NotImplementedError
@property
def joints(self):
"""Returns a list of joint names of the robot."""
raise NotImplementedError
@property
def init_qpos(self):
"""Returns default qpos."""
raise NotImplementedError