File size: 10,672 Bytes
e1328f2 | 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 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 | import os
import re
import numpy as np
from dataclasses import dataclass
from robosuite.models.objects import MujocoXMLObject
from easydict import EasyDict
import pathlib
absolute_path = pathlib.Path(__file__).parent.parent.parent.absolute()
from liberopro.liberopro.envs.base_object import (
register_visual_change_object,
register_object,
)
class ArticulatedObject(MujocoXMLObject):
def __init__(self, name, obj_name, joints=[dict(type="free", damping="0.0005")]):
super().__init__(
os.path.join(
str(absolute_path), f"assets/articulated_objects/{obj_name}.xml"
),
name=name,
joints=joints,
obj_type="all",
duplicate_collision_geoms=False,
)
self.category_name = "_".join(
re.sub(r"([A-Z])", r" \1", self.__class__.__name__).split()
).lower()
self.rotation = (np.pi / 4, np.pi / 2)
self.rotation_axis = "x"
articulation_object_properties = {
"default_open_ranges": [],
"default_close_ranges": [],
}
self.object_properties = {
"articulation": articulation_object_properties,
"vis_site_names": {},
}
def is_open(self, qpos):
raise NotImplementedError
def is_close(self, qpos):
raise NotImplementedError
@register_object
class Microwave(ArticulatedObject):
def __init__(
self,
name="microwave",
obj_name="microwave",
joints=[dict(type="free", damping="0.0005")],
):
super().__init__(name, obj_name, joints)
self.object_properties["articulation"]["default_open_ranges"] = [-2.094, -1.3]
self.object_properties["articulation"]["default_close_ranges"] = [-0.005, 0.0]
def is_open(self, qpos):
if qpos < max(self.object_properties["articulation"]["default_open_ranges"]):
return True
else:
return False
def is_close(self, qpos):
if qpos > min(self.object_properties["articulation"]["default_close_ranges"]):
return True
else:
return False
@register_object
class SlideCabinet(ArticulatedObject):
def __init__(
self,
name="slide_cabinet",
obj_name="slide_cabinet",
joints=[dict(type="free", damping="0.0005")],
):
super().__init__(name, obj_name, joints)
@register_object
class Window(ArticulatedObject):
def __init__(
self,
name="window",
obj_name="window",
joints=[dict(type="free", damping="0.0005")],
):
super().__init__(name, obj_name, joints)
self.z_on_table = 0.13
@register_object
class Faucet(ArticulatedObject):
def __init__(
self,
name="faucet",
obj_name="faucet",
joints=[dict(type="free", damping="0.0005")],
):
super().__init__(name, obj_name, joints)
@register_object
class BasinFaucet(ArticulatedObject):
def __init__(self, name="basin_faucet", obj_name="basin_faucet", joints=None):
super().__init__(name, obj_name, joints)
@register_object
class ShortCabinet(ArticulatedObject):
def __init__(
self,
name="short_cabinet",
obj_name="short_cabinet",
joints=[dict(type="free", damping="0.0005")],
):
super().__init__(name, obj_name, joints)
self.object_properties["articulation"]["default_open_ranges"] = [0.10, 0.16]
self.object_properties["articulation"]["default_close_ranges"] = [-0.005, 0.0]
def is_open(self, qpos):
if qpos > min(self.object_properties["articulation"]["default_open_ranges"]):
return True
else:
return False
def is_close(self, qpos):
if qpos < max(self.object_properties["articulation"]["default_close_ranges"]):
return True
else:
return False
@register_object
class ShortFridge(ArticulatedObject):
def __init__(
self,
name="short_fridge",
obj_name="short_fridge",
joints=[dict(type="free", damping="0.0005")],
):
super().__init__(name, obj_name, joints)
self.object_properties["articulation"]["default_open_ranges"] = [2.0, 2.7]
self.object_properties["articulation"]["default_close_ranges"] = [-0.005, 0.0]
def is_open(self, qpos):
if qpos > min(self.object_properties["articulation"]["default_open_ranges"]):
return True
else:
return False
def is_close(self, qpos):
if qpos < max(self.object_properties["articulation"]["default_close_ranges"]):
return True
else:
return False
# Sample initial joint positions for random door open or door closed
@register_object
class WoodenCabinet(ArticulatedObject):
def __init__(
self,
name="wooden_cabinet",
obj_name="wooden_cabinet",
joints=[dict(type="free", damping="0.0005")],
):
super().__init__(name, obj_name, joints)
self.object_properties["articulation"]["default_open_ranges"] = [-0.16, -0.14]
self.object_properties["articulation"]["default_close_ranges"] = [0.0, 0.005]
def is_open(self, qpos):
if qpos < max(self.object_properties["articulation"]["default_open_ranges"]):
return True
else:
return False
def is_close(self, qpos):
if qpos > min(self.object_properties["articulation"]["default_close_ranges"]):
return True
else:
return False
@register_object
class WhiteCabinet(ArticulatedObject):
def __init__(
self,
name="white_cabinet",
obj_name="white_cabinet",
joints=[dict(type="free", damping="0.0005")],
):
super().__init__(name, obj_name, joints)
self.object_properties["articulation"]["default_open_ranges"] = [-0.16, -0.14]
self.object_properties["articulation"]["default_close_ranges"] = [0.0, 0.005]
def is_open(self, qpos):
if qpos < max(self.object_properties["articulation"]["default_open_ranges"]):
return True
else:
return False
def is_close(self, qpos):
if qpos > min(self.object_properties["articulation"]["default_close_ranges"]):
return True
else:
return False
@register_object
@register_visual_change_object
class FlatStove(ArticulatedObject):
def __init__(
self,
name="flat_stove",
obj_name="flat_stove",
joints=[dict(type="free", damping="0.0005")],
):
super().__init__(name, obj_name, joints)
self.rotation = (0, 0)
self.rotation_axis = "y"
tracking_sites_dict = {}
tracking_sites_dict["burner"] = (self.naming_prefix + "burner", False)
self.object_properties["vis_site_names"].update(tracking_sites_dict)
self.object_properties["articulation"]["default_turnon_ranges"] = [0.5, 2.1]
self.object_properties["articulation"]["default_turnoff_ranges"] = [-0.005, 0.0]
def turn_on(self, qpos):
if qpos >= min(self.object_properties["articulation"]["default_turnon_ranges"]):
# TODO: Set visualization sites to be true
self.object_properties["vis_site_names"]["burner"] = (
self.naming_prefix + "burner",
True,
)
return True
else:
self.object_properties["vis_site_names"]["burner"] = (
self.naming_prefix + "burner",
False,
)
return False
def turn_off(self, qpos):
if qpos < max(self.object_properties["articulation"]["default_turnoff_ranges"]):
self.object_properties["vis_site_names"]["burner"] = (
self.naming_prefix + "burner",
False,
)
return True
else:
self.object_properties["vis_site_names"]["burner"] = (
self.naming_prefix + "burner",
True,
)
return False
@register_object
class YellowCabinet(ArticulatedObject):
def __init__(
self,
name="yellow_cabinet",
obj_name="yellow_cabinet",
joints=[dict(type="free", damping="0.0005")],
):
super().__init__(name, obj_name, joints)
self.object_properties["articulation"]["default_open_ranges"] = [-0.16, -0.14]
self.object_properties["articulation"]["default_close_ranges"] = [0.0, 0.005]
def is_open(self, qpos):
if qpos < max(self.object_properties["articulation"]["default_open_ranges"]):
return True
else:
return False
def is_close(self, qpos):
if qpos > min(self.object_properties["articulation"]["default_close_ranges"]):
return True
else:
return False
@register_object
@register_visual_change_object
class YellowStove(ArticulatedObject):
def __init__(
self,
name="yellow_stove",
obj_name="yellow_stove",
joints=[dict(type="free", damping="0.0005")],
):
super().__init__(name, obj_name, joints)
self.rotation = (0, 0)
self.rotation_axis = "y"
tracking_sites_dict = {}
tracking_sites_dict["burner"] = (self.naming_prefix + "burner", False)
self.object_properties["vis_site_names"].update(tracking_sites_dict)
self.object_properties["articulation"]["default_turnon_ranges"] = [0.5, 2.1]
self.object_properties["articulation"]["default_turnoff_ranges"] = [-0.005, 0.0]
def turn_on(self, qpos):
if qpos >= min(self.object_properties["articulation"]["default_turnon_ranges"]):
# TODO: Set visualization sites to be true
self.object_properties["vis_site_names"]["burner"] = (
self.naming_prefix + "burner",
True,
)
return True
else:
self.object_properties["vis_site_names"]["burner"] = (
self.naming_prefix + "burner",
False,
)
return False
def turn_off(self, qpos):
if qpos < max(self.object_properties["articulation"]["default_turnoff_ranges"]):
self.object_properties["vis_site_names"]["burner"] = (
self.naming_prefix + "burner",
False,
)
return True
else:
self.object_properties["vis_site_names"]["burner"] = (
self.naming_prefix + "burner",
True,
)
return False |