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

[DO NOT MERGE] Feat/sampling 2024 #609

Draft
wants to merge 236 commits into
base: og-develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
236 commits
Select commit Hold shift + click to select a range
eb3ca76
add sampling script
cremebrule Feb 16, 2024
ad97fd7
Merge branch 'og-develop' into feat/sampling_2024
cremebrule Feb 16, 2024
7c08b87
add validation script
cremebrule Feb 16, 2024
1155d08
do not step physics when playing (no longer necessary)
cremebrule Feb 16, 2024
b3d2d71
add scene sanity checks for sampling
cremebrule Feb 16, 2024
bb78fa9
Merge branch 'og-develop' into feat/sampling_2024
ChengshuLi Feb 17, 2024
5222353
remove cloth covered check
ChengshuLi Feb 17, 2024
98008e7
when exception happen, also write info (user, scene, etc) to spreadsheet
ChengshuLi Feb 17, 2024
8a293b8
print full stack trace during catastrophic crashes
cremebrule Feb 17, 2024
f14e25b
Merge remote-tracking branch 'origin/feat/sampling_2024' into feat/sa…
cremebrule Feb 17, 2024
6132ad2
Merge branch 'og-develop' into feat/sampling_2024
cremebrule Feb 17, 2024
4e6a2d6
add successful shutdown print message in the end
ChengshuLi Feb 17, 2024
6fc79a7
clear Exception logging when task is success, add hack to Contains to…
cremebrule Feb 19, 2024
6a9ec68
Merge remote-tracking branch 'origin/feat/sampling_2024' into feat/sa…
cremebrule Feb 19, 2024
926ba75
refactor Temperature, MaxTemperature, and SlicerActive to be global t…
cremebrule Feb 19, 2024
aa1fd2a
implement physx check_extent_radius_ratio to proprely catch gpu incom…
ChengshuLi Feb 20, 2024
5ecf33d
update validation script
cremebrule Feb 22, 2024
fafb8a8
update sampling script
cremebrule Feb 22, 2024
dd3871d
Merge remote-tracking branch 'origin/feat/sampling_2024' into feat/sa…
cremebrule Feb 22, 2024
058bede
Merge branch 'og-develop' into feat/sampling_2024
cremebrule Feb 22, 2024
d965c97
Merge branch 'og-develop' into feat/sampling_2024
ChengshuLi Feb 22, 2024
a212a64
Merge branch 'feat/sampling_2024' of https://github.com/StanfordVL/iG…
ChengshuLi Feb 22, 2024
253184a
Merge branch 'og-develop' into feat/sampling_2024
ChengshuLi Feb 28, 2024
39e7e7b
no longer accept missing container meta links
ChengshuLi Feb 29, 2024
69a136c
relax uniform scaling for particle modifier with np.is_close
ChengshuLi Feb 29, 2024
24aa3a3
use local file paths for sampling script
ChengshuLi Feb 29, 2024
e539334
Merge branch 'og-develop' into feat/sampling_2024
ChengshuLi Mar 2, 2024
1436518
minor bug in sampling script
ChengshuLi Mar 2, 2024
a140408
update sampling script to lower manaul mass overriding for fluid stab…
cremebrule Mar 2, 2024
d60ca5b
only set mass in sampling script for objects that actually contain sy…
ChengshuLi Mar 2, 2024
b5158e6
update verticaladjacency to be robust to other objects' placements, a…
cremebrule Mar 2, 2024
ef9072e
Merge remote-tracking branch 'origin/feat/sampling_2024' into feat/sa…
cremebrule Mar 2, 2024
12f76fb
fix minor sampling bug
cremebrule Mar 2, 2024
e943722
add unified sampling + validation script
cremebrule Mar 2, 2024
ad6fa02
fix sampling and validation script so that validation doesn't mess up…
cremebrule Mar 2, 2024
f34a9e9
don't run metalink scale sanity check for cloth prims
cremebrule Mar 2, 2024
7461236
add visual_aabb(_center/extent) for ClothPrim
ChengshuLi Mar 2, 2024
b53c745
Merge branch 'feat/sampling_2024' of https://github.com/StanfordVL/iG…
ChengshuLi Mar 2, 2024
ef1b5bd
temporarily disable validation
ChengshuLi Mar 2, 2024
87514cf
make sure vanilla scene initial state gets re-uploaded after a task i…
cremebrule Mar 4, 2024
4139177
fix sampling and validation scripts
ChengshuLi Mar 5, 2024
c272c32
headless should be on for sampling and validation
ChengshuLi Mar 5, 2024
91ee31b
always overwrite existing cached json
cremebrule Mar 5, 2024
cd15610
Merge remote-tracking branch 'origin/feat/sampling_2024' into feat/sa…
cremebrule Mar 5, 2024
a6d5802
cloth prim does not have lin/ang_vel in its state
ChengshuLi Mar 5, 2024
5069026
immediately update object registry after every in_rooms assignment
ChengshuLi Mar 5, 2024
6f1cca6
update object registry in failure mode for in_rooms assignment
ChengshuLi Mar 5, 2024
6165e08
move BOUNDING_CUBE_OBJECTS to scene_base
ChengshuLi Mar 5, 2024
e7281b1
update default number of solver iterations for all objects
cremebrule Mar 5, 2024
7d76105
Merge remote-tracking branch 'origin/feat/sampling_2024' into feat/sa…
cremebrule Mar 5, 2024
7d4a786
add missing dep
cremebrule Mar 5, 2024
671c369
skip cloth system when validating systems
ChengshuLi Mar 6, 2024
db08cd3
make sure vanilla scene initial state gets re-uploaded
cremebrule Mar 6, 2024
e326c38
don't render if headless
cremebrule Mar 6, 2024
6072155
change max samples to int
ChengshuLi Mar 6, 2024
5584193
fix _compute_batch_particles_position_orientation in MacroParticleSystem
ChengshuLi Mar 6, 2024
a952fa1
decrypt USD in-place
ChengshuLi Mar 6, 2024
3d513bc
temporary hack: exclude bad models when sampling
ChengshuLi Mar 6, 2024
f69a24f
add sbatch sampling script
cremebrule Mar 6, 2024
706fa29
decrypt to og_dataset with uuid.usd
ChengshuLi Mar 6, 2024
3896153
Merge branch 'feat/sampling_2024' of https://github.com/StanfordVL/iG…
ChengshuLi Mar 6, 2024
9598e32
assign default density to DatasetObject if the category is missing fr…
ChengshuLi Mar 6, 2024
c2865ec
minor clean up for density and mass
ChengshuLi Mar 6, 2024
798d376
update utils and sampling script to use env variables if arguments ar…
cremebrule Mar 7, 2024
e027605
add csv files
ChengshuLi Mar 7, 2024
136b21d
change file paths for sbatch
ChengshuLi Mar 7, 2024
677652e
add more bad models
ChengshuLi Mar 7, 2024
3d5cad1
update sampling script
cremebrule Mar 7, 2024
f106e2c
allow glass material for macro visual particle templates
ChengshuLi Mar 7, 2024
f8263cb
add ability to randomize sampling / validation order
cremebrule Mar 7, 2024
866a138
add time limit and logging to sbatch script
cremebrule Mar 7, 2024
3a00a1a
fix syntax error
cremebrule Mar 7, 2024
732bfef
mark scene as success when done sampling all activities, use unique t…
cremebrule Mar 7, 2024
3a01dc2
don't check target values for joints
cremebrule Mar 7, 2024
3d7bfde
add meta sampling script
cremebrule Mar 7, 2024
d4b5ddd
add chengshu meta sampling script
ChengshuLi Mar 7, 2024
afbd0a7
record thread id as we're sampling the scene
cremebrule Mar 7, 2024
a7062bc
Merge remote-tracking branch 'origin/feat/sampling_2024' into feat/sa…
cremebrule Mar 7, 2024
dee294d
prune failed runs
cremebrule Mar 7, 2024
b0a1504
double cpu memory request for slurm
ChengshuLi Mar 7, 2024
966965c
wait a random amount of time before querying google sheet
ChengshuLi Mar 7, 2024
cb0123d
relax PIL Image max image pixels
ChengshuLi Mar 8, 2024
21a54f3
use titanrtx
ChengshuLi Mar 8, 2024
e191ec1
update current task for all threads
cremebrule Mar 8, 2024
204728b
fix bash script
ChengshuLi Mar 8, 2024
cd2f35e
Merge branch 'feat/sampling_2024' of https://github.com/StanfordVL/iG…
ChengshuLi Mar 8, 2024
60fd506
update utils and sampling script to use env variables if arguments ar…
cremebrule Mar 8, 2024
b007472
Merge remote-tracking branch 'origin/feat/sampling_2024' into feat/sa…
cremebrule Mar 8, 2024
8875bd3
minor bug in bash script
ChengshuLi Mar 8, 2024
36439e2
update cremebrule sbatch script
cremebrule Mar 8, 2024
b354b23
Merge remote-tracking branch 'origin/feat/sampling_2024' into feat/sa…
cremebrule Mar 8, 2024
d52d11f
increase time limit to 24h
ChengshuLi Mar 8, 2024
96aba98
fix current task bug
ChengshuLi Mar 8, 2024
b0ab3fe
exclude svl8
ChengshuLi Mar 8, 2024
ff7c828
debug current task
ChengshuLi Mar 8, 2024
8fc1057
fix current task
ChengshuLi Mar 8, 2024
d1a9820
do not explictly track_n_particles for micro particle system, just qu…
ChengshuLi Mar 9, 2024
f7d0236
properly increase mass for container post sampling
ChengshuLi Mar 9, 2024
8c7d7b9
increase default hit proportion for kinematic sampling during ray cas…
ChengshuLi Mar 9, 2024
8dd4d8a
fix bug for _sync_particle_prototype_ids
ChengshuLi Mar 9, 2024
fb343f7
fix building structure
cremebrule Mar 9, 2024
eb87fe9
fix offline sampling bug
ChengshuLi Mar 9, 2024
b043a7e
make clothification more robust
cremebrule Mar 10, 2024
8244cd5
increase cloth remeshing max iterations
cremebrule Mar 10, 2024
804e78e
allow for skipping of remeshing, leverage blacklist to determine whic…
cremebrule Mar 11, 2024
06b2c11
Merge branch 'og-develop' into feat/sampling_2024
ChengshuLi Mar 11, 2024
891a306
fix micro particle system load/dump state
ChengshuLi Mar 11, 2024
bb75a0d
only fail object category sampling if ALL objects are missing valid m…
cremebrule Mar 11, 2024
783c6fc
make max samples None by default for particle sampling
cremebrule Mar 11, 2024
a2db907
update bad cloth models
cremebrule Mar 11, 2024
35b9525
add minimum threshold for micro / macro physical particle sizes
cremebrule Mar 11, 2024
800a702
Merge branch 'og-develop' into feat/sampling_2024
ChengshuLi Mar 11, 2024
42678c4
minor whitespace changes for formatting
ChengshuLi Mar 11, 2024
7ed89c5
add entity prim reset, add flag for resetting objects before sampling…
cremebrule Mar 12, 2024
1b3be8f
Merge remote-tracking branch 'origin/feat/sampling_2024' into feat/sa…
cremebrule Mar 12, 2024
ac7a1bd
reduce distance for sampling fluid particles to minimize compression
cremebrule Mar 12, 2024
3f2ed01
add additional helper functions for sampling
cremebrule Mar 12, 2024
a345f40
make sure rigid objects are sampled before cloth objects per group of…
cremebrule Mar 12, 2024
ed81ae6
treat particles as cubes for the purpose of evaluating filled and har…
cremebrule Mar 12, 2024
bb27042
increase max gpu patch count
cremebrule Mar 12, 2024
4307a4d
Merge branch 'og-develop' into feat/sampling_2024
ChengshuLi Mar 12, 2024
70c06f8
minor sampling script changes
ChengshuLi Mar 12, 2024
d78106b
use fallback for Folded state to avoid crashes
cremebrule Mar 12, 2024
f112908
add sampling script for creating stable json
cremebrule Mar 12, 2024
cf3b83b
update bad models
cremebrule Mar 12, 2024
9d60f18
add script for creating stable scene on the cluster
cremebrule Mar 12, 2024
9b17b8e
update create_stable_scene scripts
cremebrule Mar 12, 2024
4973efe
fix typo
cremebrule Mar 12, 2024
733beb6
exclude svl18 for sc jobs
cremebrule Mar 12, 2024
d579f1b
update stable scenes sh script
cremebrule Mar 12, 2024
8f782aa
update create stable scene sh script
cremebrule Mar 12, 2024
73634be
relax resource constraints for stable scene sc script
cremebrule Mar 12, 2024
24ae72e
during check_extent_radius_ratio, also check for min extent in world …
ChengshuLi Mar 12, 2024
e6d9c9f
whitelist belt (change to non-cloth) and t-shirt (correct size now)
ChengshuLi Mar 12, 2024
a2f2ee4
update create stable scene scripts
cremebrule Mar 12, 2024
a8215de
Merge remote-tracking branch 'origin/feat/sampling_2024' into feat/sa…
cremebrule Mar 12, 2024
c5e0572
fix comments
ChengshuLi Mar 12, 2024
41335be
update scenes, synsets, tasks.csv
ChengshuLi Mar 12, 2024
0151d24
increase threshold for enforcing bounding box approximation
cremebrule Mar 13, 2024
86ae5e9
add sanity check script
cremebrule Mar 13, 2024
6cf1b7c
fix typo
cremebrule Mar 13, 2024
fffc33c
fix sanity check script
cremebrule Mar 13, 2024
74ef2f6
only sanity check pos
cremebrule Mar 13, 2024
42eac24
make sure values are sorted when running sanity check
cremebrule Mar 13, 2024
a5eac10
update create stable scene
cremebrule Mar 13, 2024
bc2fc71
remove --exclude flag because the bad nodes have been cleared
ChengshuLi Mar 13, 2024
13cdbc3
record feedback True for create_stable_scene_json
ChengshuLi Mar 13, 2024
b404717
update cremebrule sbatch task sampling script
cremebrule Mar 13, 2024
74cc078
add retry mechanism to google sheet requests
ChengshuLi Mar 13, 2024
388c9d4
Merge branch 'feat/sampling_2024' of https://github.com/StanfordVL/iG…
ChengshuLi Mar 13, 2024
489bd11
increase retries
ChengshuLi Mar 13, 2024
8f7d452
also skip sampling if goal conditions have non-supported predicates
ChengshuLi Mar 13, 2024
d31ae4d
fix typos
ChengshuLi Mar 13, 2024
c1f5ff2
further robustify google sheet request
ChengshuLi Mar 13, 2024
7abd5cf
revert gpu max patch count to avoid crashes
cremebrule Mar 13, 2024
e8672e0
Merge remote-tracking branch 'origin/feat/sampling_2024' into feat/sa…
cremebrule Mar 13, 2024
a7b6253
hide all lights if running headless during sampling
cremebrule Mar 14, 2024
2e22c04
update current round of runs for cremebrule cluster sampling
cremebrule Mar 14, 2024
cca8708
terminate early if sampling is already completed for a given task
cremebrule Mar 14, 2024
71ee0e0
fix typo
cremebrule Mar 14, 2024
c8780ce
remove any particles that are below the floor plane
cremebrule Mar 14, 2024
329dec4
revert fix for sanity checking deleting a prim
cremebrule Mar 14, 2024
18404bd
up max rigid patch count
cremebrule Mar 14, 2024
8e3bb2b
update cremebrule sampling runs
cremebrule Mar 14, 2024
4b80662
set robot to be in space by default during sampling to avoid collisio…
cremebrule Mar 14, 2024
dfebac2
add gpu max rigid contact count macro and increase default max rigid …
cremebrule Mar 14, 2024
103a5e6
update cremebrule sampling
cremebrule Mar 14, 2024
ba5448e
update cremebrule runs
cremebrule Mar 14, 2024
fff7873
update cremebrule runs
cremebrule Mar 14, 2024
1f8a6fa
finish initial draft of attached state sampling
ChengshuLi Mar 14, 2024
b30c8d4
Merge branch 'feat/sampling_2024' into attached_sampling
ChengshuLi Mar 14, 2024
dd16511
minor fixes
ChengshuLi Mar 14, 2024
58a46aa
use leaf synset for abilities when checking get_all_object_category_m…
ChengshuLi Mar 14, 2024
50533e1
Merge pull request #651 from StanfordVL/attached_sampling
ChengshuLi Mar 14, 2024
74b2896
fix comments in attached
ChengshuLi Mar 14, 2024
c16ca6f
exclude hot_tub from toggleable machine transition rules
ChengshuLi Mar 14, 2024
77aec12
make orientation check more robust to quaternion convention
cremebrule Mar 14, 2024
24da7c2
Merge remote-tracking branch 'origin/feat/sampling_2024' into feat/sa…
cremebrule Mar 14, 2024
e5c2c4d
fix quat bug
cremebrule Mar 14, 2024
82fa742
pop callback if exists
ChengshuLi Mar 15, 2024
bce2ac4
clip system's max velocities during sampling
cremebrule Mar 15, 2024
e705c4b
Merge remote-tracking branch 'origin/feat/sampling_2024' into feat/sa…
cremebrule Mar 15, 2024
7e0c10a
update cremebrule sampling
cremebrule Mar 15, 2024
bdc8c07
disable collision between attached objects and add TODOs to make Atta…
ChengshuLi Mar 15, 2024
4660b94
Merge branch 'feat/sampling_2024' of https://github.com/StanfordVL/iG…
ChengshuLi Mar 15, 2024
37a618d
raise soft warning in load state of attached
ChengshuLi Mar 15, 2024
4c0c4bb
if an object inst is a parent of an attachment, it should have at lea…
ChengshuLi Mar 15, 2024
25fb942
add on_fire to supported predicates
ChengshuLi Mar 15, 2024
15c72e7
update cremebrule sampling
cremebrule Mar 15, 2024
2a37029
Merge remote-tracking branch 'origin/feat/sampling_2024' into feat/sa…
cremebrule Mar 15, 2024
c3003a7
do not scale objects when sampling attached, attached load state bypa…
ChengshuLi Mar 15, 2024
68ccf04
Merge branch 'feat/sampling_2024' of https://github.com/StanfordVL/iG…
ChengshuLi Mar 15, 2024
ab38b93
add missing import
ChengshuLi Mar 15, 2024
5a0d545
add whitelisting of models during sampling
cremebrule Mar 15, 2024
e241fc7
Merge remote-tracking branch 'origin/feat/sampling_2024' into feat/sa…
cremebrule Mar 15, 2024
73522b4
move cardigan to bad models
ChengshuLi Mar 15, 2024
c79d0bc
attached: do not disable collision again if already done so
ChengshuLi Mar 15, 2024
c3e30d2
Merge branch 'feat/sampling_2024' of https://github.com/StanfordVL/iG…
ChengshuLi Mar 15, 2024
a5eb7bf
add whitelist bounding boxes for sampling
cremebrule Mar 15, 2024
bb71c32
Merge remote-tracking branch 'origin/feat/sampling_2024' into feat/sa…
cremebrule Mar 15, 2024
50de278
disable gravity for attached child object if parent is kinematic only…
ChengshuLi Mar 16, 2024
471a72d
fix validation script for particles
ChengshuLi Mar 16, 2024
52f7858
move non_remeshing models to bad models because they explode
ChengshuLi Mar 16, 2024
3a32959
Merge branch 'feat/sampling_2024' of https://github.com/StanfordVL/iG…
ChengshuLi Mar 16, 2024
60be5cf
update bad models
ChengshuLi Mar 16, 2024
ad3ccbc
only sample from unsuccessful list
cremebrule Mar 16, 2024
c9ac145
update whitelisted models
cremebrule Mar 16, 2024
86be7db
Merge remote-tracking branch 'origin/feat/sampling_2024' into feat/sa…
cremebrule Mar 16, 2024
eb43ceb
update whitelisted models for sampling
cremebrule Mar 16, 2024
a4661ce
update cremebrule sampling
cremebrule Mar 16, 2024
523d3b5
only check for completion if not randomizing
cremebrule Mar 16, 2024
cc5955f
attached: disable collision between child and walls/floors only if pa…
ChengshuLi Mar 16, 2024
243f5f6
remove attached objects collision group
ChengshuLi Mar 16, 2024
f52f11f
add good curtain
ChengshuLi Mar 16, 2024
b60eec9
Merge branch 'feat/sampling_2024' of https://github.com/StanfordVL/iG…
ChengshuLi Mar 16, 2024
be8ebe8
update cremebrule runs
cremebrule Mar 16, 2024
17f23dc
Merge remote-tracking branch 'origin/feat/sampling_2024' into feat/sa…
cremebrule Mar 16, 2024
4d66b26
add interactive task sampler
cremebrule Mar 16, 2024
c6aba02
update interactive sampler
cremebrule Mar 16, 2024
4df2535
create flag to ignore in progress
cremebrule Mar 16, 2024
3b07595
add ignore in progress flag to sbatch script
cremebrule Mar 16, 2024
8543dbb
update cremebrule sampling script
cremebrule Mar 16, 2024
55a9397
add successful_activity_to_scene
ChengshuLi Mar 16, 2024
c5f3761
Merge branch 'feat/sampling_2024' of https://github.com/StanfordVL/iG…
ChengshuLi Mar 16, 2024
e749bd9
add interactive sampler ability to batch teleport objects to valid room
cremebrule Mar 16, 2024
1b48979
Merge branch 'feat/sampling_2024' of https://github.com/StanfordVL/iG…
ChengshuLi Mar 16, 2024
d455573
make orientation
cremebrule Mar 16, 2024
8b0bd24
Merge remote-tracking branch 'origin/feat/sampling_2024' into feat/sa…
cremebrule Mar 16, 2024
ad8aaaa
make sure agent is always part of object scope
cremebrule Mar 16, 2024
f9ff38b
add sanity check for importing sampleable objects
cremebrule Mar 16, 2024
2135128
Update bddl bad object and task sampling py
wensi-ai Mar 16, 2024
e85c16f
Remove key
wensi-ai Mar 16, 2024
52f6f5b
add ability to synchronize cloth scales
cremebrule Mar 17, 2024
a3ec1e4
Merge remote-tracking branch 'origin/feat/sampling_2024' into feat/sa…
cremebrule Mar 17, 2024
ec80b70
update cloth synhronization code
cremebrule Mar 17, 2024
9375c88
update bddl whitelists
cremebrule Mar 17, 2024
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
6 changes: 6 additions & 0 deletions omnigibson/macros.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@
# Maximum particle contacts allowed
gm.GPU_MAX_PARTICLE_CONTACTS = 1024 * 1024

# Maximum rigid contacts -- 524288 is default value from omni, but increasing too much can sometimes lead to crashes
gm.GPU_MAX_RIGID_CONTACT_COUNT = 524288 * 4

# Maximum rigid patches -- 81920 is default value from omni, but increasing too much can sometimes lead to crashes
gm.GPU_MAX_RIGID_PATCH_COUNT = 81920 * 4

# Whether to enable object state logic or not
gm.ENABLE_OBJECT_STATES = True

Expand Down
178 changes: 140 additions & 38 deletions omnigibson/object_states/attached_to.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from omnigibson.utils.usd_utils import create_joint
from omnigibson.utils.ui_utils import create_module_logger
from omnigibson.utils.python_utils import classproperty
from omnigibson.utils.usd_utils import CollisionAPI

# Create module logger
log = create_module_logger(module_name=__name__)
Expand All @@ -30,7 +31,15 @@
m.DEFAULT_BREAK_FORCE = 10000 # Newton
m.DEFAULT_BREAK_TORQUE = 10000 # Newton-Meter


# TODO: Make AttachedTo into a global state that manages all the attachments in the scene.
# When an attachment of a child and a parent is about to happen:
# 1. stop the sim
# 2. remove all existing attachment joints (and save information to restore later)
# 3. disable collision between the child and the parent
# 4. play the sim
# 5. reload the state
# 6. restore all existing attachment joints
# 7. create the joint
class AttachedTo(RelativeObjectState, BooleanStateMixin, ContactSubscribedStateMixin, JointBreakSubscribedStateMixin, LinkBasedStateMixin):
"""
Handles attachment between two rigid objects, by creating a fixed/spherical joint between self.obj (child) and
Expand All @@ -43,6 +52,20 @@ class AttachedTo(RelativeObjectState, BooleanStateMixin, ContactSubscribedStateM
on_contact function attempts to attach self.obj to other when a CONTACT_FOUND event happens
on_joint_break function breaks the current attachment
"""
# This is to force the __init__ args to be "self" and "obj" only.
# Otherwise, it will inherit from LinkBasedStateMixin and the __init__ args will be "self", "args", "kwargs".
def __init__(self, obj):
# Run super method
super().__init__(obj=obj)

def initialize(self):
super().initialize()
og.sim.add_callback_on_stop(name=f"{self.obj.name}_detach", callback=self._detach)
self.parents_disabled_collisions = set()

def remove(self):
super().remove()
og.sim.remove_callback_on_stop(name=f"{self.obj.name}_detach")

@classproperty
def metalink_prefix(cls):
Expand Down Expand Up @@ -89,24 +112,54 @@ def on_contact(self, other, contact_headers, contact_data):
if self.set_value(other, True):
break

def _set_value(self, other, new_value, bypass_alignment_checking=False):
def _set_value(self, other, new_value, bypass_alignment_checking=False, check_physics_stability=False, can_joint_break=True):
"""
Args:
other (DatasetObject): parent object to attach to.
new_value (bool): whether to attach or detach.
bypass_alignment_checking (bool): whether to bypass alignment checking when finding attachment links.
Normally when finding attachment links, we check if the child and parent links have aligned positions
or poses. This flag allows users to bypass this check and find attachment links solely based on the
attachment meta link types. Default is False.
check_physics_stability (bool): whether to check if the attachment is stable after attachment.
If True, it will check if the child object is not colliding with other objects except the parent object.
If False, it will not check the stability and simply attach the child to the parent.
Default is False.
can_joint_break (bool): whether the joint can break or not.

Returns:
bool: whether the attachment setting was successful or not.
"""
# Attempt to attach
if new_value:
if self.parent == other:
# Already attached to this object. Do nothing.
return True
elif self.parent is None:
# Find attachment links that satisfy the proximity requirements
child_link, parent_link = self._find_attachment_links(other, bypass_alignment_checking)
if child_link is not None:
self._attach(other, child_link, parent_link)
return True
else:
return False
else:
elif self.parent is not None:
log.debug(f"Trying to attach object {self.obj.name} to object {other.name},"
f"but it is already attached to object {self.parent.name}. Try detaching first.")
return False
else:
# Find attachment links that satisfy the proximity requirements
child_link, parent_link = self._find_attachment_links(other, bypass_alignment_checking)
if child_link is None:
return False
else:
if check_physics_stability:
state = og.sim.dump_state()
self._attach(other, child_link, parent_link, can_joint_break=can_joint_break)
if not check_physics_stability:
return True
else:
og.sim.step_physics()
# self.obj should not collide with other objects except the parent
success = len(self.obj.states[ContactBodies].get_value(ignore_objs=(other,))) == 0
if success:
return True
else:
self._detach()
og.sim.load_state(state)
return False

# Attempt to detach
else:
Expand Down Expand Up @@ -190,7 +243,7 @@ def _get_parent_candidates(self, other):
def attachment_joint_prim_path(self):
return f"{self.parent_link.prim_path}/{self.obj.name}_attachment_joint" if self.parent_link is not None else None

def _attach(self, other, child_link, parent_link, joint_type=m.DEFAULT_JOINT_TYPE, break_force=m.DEFAULT_BREAK_FORCE, break_torque=m.DEFAULT_BREAK_TORQUE):
def _attach(self, other, child_link, parent_link, joint_type=m.DEFAULT_JOINT_TYPE, can_joint_break=True):
"""
Creates a fixed or spherical joint between a male meta link of self.obj (@child_link) and a female meta link of
@other (@parent_link) with a given @joint_type, @break_force and @break_torque
Expand All @@ -200,16 +253,9 @@ def _attach(self, other, child_link, parent_link, joint_type=m.DEFAULT_JOINT_TYP
child_link (RigidPrim): male meta link of @self.obj.
parent_link (RigidPrim): female meta link of @other.
joint_type (JointType): joint type of the attachment, {JointType.JOINT_FIXED, JointType.JOINT_SPHERICAL}
break_force (float or None): break force for linear dofs, unit is Newton.
break_torque (float or None): break torque for angular dofs, unit is Newton-meter.
can_joint_break (bool): whether the joint can break or not.
"""
assert joint_type in {JointType.JOINT_FIXED, JointType.JOINT_SPHERICAL}, f"Unsupported joint type {joint_type}"
# Set the parent references
self.parent = other
self.parent_link = parent_link

# Set the child reference for @other
other.states[AttachedTo].children[parent_link.body_name] = self.obj

# Set pose for self.obj so that child_link and parent_link align (6dof alignment for FixedJoint and 3dof alignment for SphericalJoint)
parent_pos, parent_quat = parent_link.get_position_orientation()
Expand All @@ -229,6 +275,7 @@ def _attach(self, other, child_link, parent_link, joint_type=m.DEFAULT_JOINT_TYP
# Actually move the object and also keep it still for stability purposes.
self.obj.set_position_orientation(new_child_root_pos, new_child_root_quat)
self.obj.keep_still()
other.keep_still()

if joint_type == JointType.JOINT_FIXED:
# FixedJoint: the parent link, the child link and the joint frame all align.
Expand All @@ -238,6 +285,18 @@ def _attach(self, other, child_link, parent_link, joint_type=m.DEFAULT_JOINT_TYP
# The child link and the joint frame still align.
_, parent_local_quat = T.relative_pose_transform([0, 0, 0], child_quat, [0, 0, 0], parent_quat)

# Disable collision between the parent and child objects
self._disable_collision_between_child_and_parent(child=self.obj, parent=other)

# Set the parent references
self.parent = other
self.parent_link = parent_link

# Set the child reference for @other
other.states[AttachedTo].children[parent_link.body_name] = self.obj

kwargs = {"break_force": m.DEFAULT_BREAK_FORCE, "break_torque": m.DEFAULT_BREAK_TORQUE} if can_joint_break else dict()

# Create the joint
create_joint(
prim_path=self.attachment_joint_prim_path,
Expand All @@ -248,23 +307,61 @@ def _attach(self, other, child_link, parent_link, joint_type=m.DEFAULT_JOINT_TYP
joint_frame_in_parent_frame_quat=parent_local_quat,
joint_frame_in_child_frame_pos=np.zeros(3),
joint_frame_in_child_frame_quat=np.array([0.0, 0.0, 0.0, 1.0]),
break_force=break_force,
break_torque=break_torque,
**kwargs
)

def _disable_collision_between_child_and_parent(self, child, parent):
"""
Disables collision between the child and parent objects
"""
if parent in self.parents_disabled_collisions:
return
self.parents_disabled_collisions.add(parent)

was_playing = og.sim.is_playing()
if was_playing:
state = og.sim.dump_state()
og.sim.stop()

for child_link in child.links.values():
for parent_link in parent.links.values():
child_link.add_filtered_collision_pair(parent_link)

if parent.category == "wall_nail":
# Temporary hack to disable collision between the attached child object and all walls/floors so that objects
# attached to the wall_nails do not collide with the walls/floors.
for wall in og.sim.scene.object_registry("category", "walls", set()):
for wall_link in wall.links.values():
for child_link in child.links.values():
child_link.add_filtered_collision_pair(wall_link)
for wall in og.sim.scene.object_registry("category", "floors", set()):
for floor_link in wall.links.values():
for child_link in child.links.values():
child_link.add_filtered_collision_pair(floor_link)

# Temporary hack to disable gravity for the attached child object if the parent is kinematic_only
# Otherwise, the parent metalink will oscillate due to the gravity force of the child.
if parent.kinematic_only:
child.disable_gravity()

if was_playing:
og.sim.play()
og.sim.load_state(state)

def _detach(self):
"""
Removes the current attachment joint
"""
# Remove the attachment joint prim from the stage
og.sim.stage.RemovePrim(self.attachment_joint_prim_path)
if self.parent_link is not None:
# Remove the attachment joint prim from the stage
og.sim.stage.RemovePrim(self.attachment_joint_prim_path)

# Remove child reference from the parent object
self.parent.states[AttachedTo].children[self.parent_link.body_name] = None
# Remove child reference from the parent object
self.parent.states[AttachedTo].children[self.parent_link.body_name] = None

# Remove reference to the parent object and link
self.parent = None
self.parent_link = None
# Remove reference to the parent object and link
self.parent = None
self.parent_link = None

@property
def settable(self):
Expand All @@ -285,15 +382,20 @@ def _load_state(self, state):
attached_obj = og.sim.scene.object_registry("uuid", uuid)
assert attached_obj is not None, "attached_obj_uuid does not match any object in the scene."

# If it's currently attached to something, detach.
if self.parent is not None:
self.set_value(self.parent, False)
assert self.parent is None, "parent reference is not cleared after detachment"

# If the loaded state requires attachment, attach.
if attached_obj is not None:
self.set_value(attached_obj, True)
assert self.parent == attached_obj, "parent reference is not updated after attachment"
if self.parent != attached_obj:
# If it's currently attached to something else, detach.
if self.parent is not None:
self.set_value(self.parent, False)
# assert self.parent is None, "parent reference is not cleared after detachment"
if self.parent is not None:
log.warning(f"parent reference is not cleared after detachment")

# If the loaded state requires attachment, attach.
if attached_obj is not None:
self.set_value(attached_obj, True, bypass_alignment_checking=True, check_physics_stability=False, can_joint_break=True)
# assert self.parent == attached_obj, "parent reference is not updated after attachment"
if self.parent != attached_obj:
log.warning(f"parent reference is not updated after attachment")

def _serialize(self, state):
return np.array([state["attached_obj_uuid"]], dtype=float)
Expand Down
5 changes: 5 additions & 0 deletions omnigibson/object_states/contains.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ def volume(self):
"""
return self._volume

# @classmethod
# def is_compatible_asset(cls, prim, **kwargs):
# # TODO HACKY SAMPLING FIX: Override this method -- it will be reverted once the assets are updated to include fillables properly
# return True, None


class Contains(RelativeObjectState, BooleanStateMixin):
def _get_value(self, system):
Expand Down
8 changes: 7 additions & 1 deletion omnigibson/object_states/filled.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
from omnigibson.object_states.contains import ContainedParticles
from omnigibson.object_states.object_state_base import RelativeObjectState, BooleanStateMixin
from omnigibson.systems.system_base import PhysicalParticleSystem, is_physical_particle_system
from omnigibson.systems.macro_particle_system import MacroParticleSystem

# Create settings for this module
m = create_module_macros(module_path=__file__)

# Proportion of object's volume that must be filled for object to be considered filled
m.VOLUME_FILL_PROPORTION = 0.2
m.N_MAX_MACRO_PARTICLE_SAMPLES = 500
m.N_MAX_MICRO_PARTICLE_SAMPLES = 100000


class Filled(RelativeObjectState, BooleanStateMixin):
Expand All @@ -20,7 +23,8 @@ def _get_value(self, system):

# Check what volume is filled
if system.n_particles > 0:
particle_volume = 4 / 3 * np.pi * (system.particle_radius ** 3)
# Treat particles as cubes
particle_volume = (system.particle_radius * 2) ** 3
n_particles = self.obj.states[ContainedParticles].get_value(system).n_in_volume
prop_filled = particle_volume * n_particles / self.obj.states[ContainedParticles].volume
# If greater than threshold, then the volume is filled
Expand Down Expand Up @@ -50,6 +54,8 @@ def _set_value(self, system, new_value):
obj=self.obj,
link=contained_particles_state.link,
check_contact=True,
max_samples=m.N_MAX_MACRO_PARTICLE_SAMPLES
if issubclass(system, MacroParticleSystem) else m.N_MAX_MICRO_PARTICLE_SAMPLES
)
else:
# Cannot set False
Expand Down
8 changes: 6 additions & 2 deletions omnigibson/object_states/folded.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import numpy as np
from collections import namedtuple
from scipy.spatial import ConvexHull, distance_matrix
from scipy.spatial import ConvexHull, distance_matrix, QhullError

from omnigibson.macros import create_module_macros
from omnigibson.object_states.object_state_base import BooleanStateMixin, AbsoluteObjectState
Expand Down Expand Up @@ -98,7 +98,11 @@ def calculate_projection_area_and_diagonal(self, dims):
"""
cloth = self.obj.root_link
points = cloth.keypoint_particle_positions[:, dims]
hull = ConvexHull(points)
try:
hull = ConvexHull(points)
except QhullError:
# This is a degenerate hull, so return 0 area and diagonal
return 0.0, 0.0

# When input points are 2-dimensional, this is the area of the convex hull.
# Ref: https://docs.scipy.org/doc/scipy/reference/generated/scipy.spatial.ConvexHull.html
Expand Down
6 changes: 5 additions & 1 deletion omnigibson/object_states/inside.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def get_dependencies(cls):
deps.update({AABB, HorizontalAdjacency, VerticalAdjacency})
return deps

def _set_value(self, other, new_value):
def _set_value(self, other, new_value, reset_before_sampling=False):
if not new_value:
raise NotImplementedError("Inside does not support set_value(False)")

Expand All @@ -25,6 +25,10 @@ def _set_value(self, other, new_value):

state = og.sim.dump_state(serialized=False)

# Possibly reset this object if requested
if reset_before_sampling:
self.obj.reset()

for _ in range(os_m.DEFAULT_HIGH_LEVEL_SAMPLING_ATTEMPTS):
if sample_kinematics("inside", self.obj, other) and self.get_value(other):
return True
Expand Down
6 changes: 5 additions & 1 deletion omnigibson/object_states/on_top.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def get_dependencies(cls):
deps.update({Touching, VerticalAdjacency})
return deps

def _set_value(self, other, new_value):
def _set_value(self, other, new_value, reset_before_sampling=False):
if not new_value:
raise NotImplementedError("OnTop does not support set_value(False)")

Expand All @@ -25,6 +25,10 @@ def _set_value(self, other, new_value):

state = og.sim.dump_state(serialized=False)

# Possibly reset this object if requested
if reset_before_sampling:
self.obj.reset()

for _ in range(os_m.DEFAULT_HIGH_LEVEL_SAMPLING_ATTEMPTS):
if sample_kinematics("onTop", self.obj, other) and self.get_value(other):
return True
Expand Down
Loading
Loading