-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Adds USD-level randomization to event manager #1165
base: main
Are you sure you want to change the base?
Conversation
32db208
to
d3b0605
Compare
I already spent a day trying to figure out multiple ways to initialize the event manager before the sim starts playing. The scene entity config resolution is impossible until physics parses the scene (since we need the PhysX body and joint ordering). It is rather unfortunate, but that's how it is right now. The functionality still works, so if it makes sense, we can move forward with it. |
Signed-off-by: Mayank Mittal <[email protected]>
@Mayankm96 thanks for the great work. wonder if you have plans to merge these functions into the main branch? |
|
||
.. attention:: | ||
Since this function modifies USD properties, it should only be used before the simulation starts | ||
playing. This corresponds to the event mode named "spawn". Using it at simulation time, may lead to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we add a check for simulation running and throw an error or warning if it's used while simulation is running?
prim_spec = Sdf.CreatePrimInLayer(stage.GetRootLayer(), prim_paths[env_id]) | ||
|
||
# get the attribute to randomize | ||
scale_spec = prim_spec.GetAttributeAtPath(prim_paths[env_id] + ".xformOp:scale") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what happens if xformOp:scale is not on the prim?
prim_spec = Sdf.CreatePrimInLayer(stage.GetRootLayer(), prim_paths[env_id]) | ||
|
||
# get the attribute to randomize | ||
color_spec = prim_spec.GetAttributeAtPath( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would it make sense to also support DisplayColor attribute? primitive shapes might not always have materials assigned.
color_spec = prim_spec.GetAttributeAtPath( | ||
prim_paths[env_id] + "/geometry/material/Shader.inputs:diffuseColor" | ||
) | ||
color_spec.default = Gf.Vec3f(*rand_samples[i]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe we can handle missing attributes more gracefully than just erroring out. I feel like printing a message and continuing might be more user friendly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, LGTM, but I think we can consolidate the apply_randomization method as it looks identical.
Also, would be good to add a unit test for this functionality
@@ -116,6 +116,10 @@ def __init__(self, cfg: ManagerBasedEnvCfg): | |||
self.scene = InteractiveScene(self.cfg.scene) | |||
print("[INFO]: Scene manager: ", self.scene) | |||
|
|||
# randomization at scene level |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a note here why this is needed here for future reference?
applied_scene_randomization = False | ||
# iterate over all event terms | ||
for term_name, term_cfg in self.cfg.events.__dict__.items(): | ||
# check for non config |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# check for non config | |
# check for none config |
@@ -563,6 +568,39 @@ def set_debug_vis(self, debug_vis: bool) -> bool: | |||
Helper functions. | |||
""" | |||
|
|||
def _apply_scene_randomization(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we make this a static helper method so that all 3 implementations can share it? It would need to take in an env
of any of the three types and do the same operation on each
unpredictable behaviors. | ||
|
||
.. note:: | ||
When randomizing the scale of individual assets, please make sure to set |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we just throw an exception if replicate_physics
is True here?
@@ -38,7 +38,8 @@ class EventManager(ManagerBase): | |||
|
|||
For a typical training process, you may want to apply events in the following modes: | |||
|
|||
- "startup": Event is applied once at the beginning of the training. | |||
- "scene": Event is applied once after designing the scene. | |||
- "startup": Event is applied once after the simulation starts playing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Double check that this doesn't need to be updated in any tutorials or how-tos
# check if sim is playing and resolve the entity | ||
# joint and body names are only available once the sim is playing | ||
# hence, we do not resolve the entity if the sim is not playing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When do the entities get resolved if the sim is not playing?
Description
Certain scene-level randomizations (such as randomizing the scale) must happen before the simulation starts playing. To this end, the MR adds a new event mode called "scene," which gets called right after the scene design is complete.
Since the event manager CANNOT be initialized before the simulation starts playing, the current implementation hacks the event mode into the environment constructor directly. This is not ideal but at this point, there is no other way around it.
Type of change
Screenshots
If you execute:
Output:
Checklist
pre-commit
checks with./isaaclab.sh --format
config/extension.toml
fileCONTRIBUTORS.md
or my name already exists there