-
Notifications
You must be signed in to change notification settings - Fork 0
Randomizer no longer randomize on each frame if cosmos is enabled #1
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
Open
BarceloChristian
wants to merge
1
commit into
main
Choose a base branch
from
cbarcelo/fix_cosmos
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,27 +30,61 @@ | |
|
|
||
| import pathlib | ||
|
|
||
| import numpy as np | ||
| import omni.replicator.core as rep | ||
| import omni.timeline | ||
| from omni.replicator.core.functional.create import reference as f_reference | ||
|
|
||
| ROBOT_PATH = pathlib.Path(__file__).parent.parent.parent / "assets" / "ur10e" / "pick_animation" / "playback.usda" | ||
| FIRST_MOVING_FRAME = 80 | ||
| NUM_FRAMES = 642 # Animation frames | ||
|
|
||
|
|
||
| class RobotRandomizer: | ||
| """Randomizer for robot animation and pose.""" | ||
|
|
||
| def __init__(self) -> None: | ||
| """Initialize the robot randomizer with animation and pose randomization.""" | ||
| # Spawn robot pick animation | ||
| self.robot = rep.create.from_usd(str(ROBOT_PATH), semantics={"class": "robot"}) | ||
| def __init__(self, randomize_all_frames: bool = True) -> None: | ||
| """Initialize the robot randomizer with animation and pose randomization. | ||
| def randomize_robot_pose() -> None: | ||
| """Randomize robot animation frame and rotation.""" | ||
| with self.robot: | ||
| rep.modify.timeline(rep.distribution.uniform(lower=0, upper=NUM_FRAMES), modify_type="frame") | ||
| rep.modify.pose(rotation_z=rep.distribution.uniform(0.0, 360.0)) | ||
| Args: | ||
| ---- | ||
| randomize_all_frames: If True, randomizes animation frame and rotation on every trigger. | ||
| If False, incrementally advances through animation frames. | ||
| rep.randomizer.register(randomize_robot_pose) | ||
| """ | ||
| self.randomize_all_frames = randomize_all_frames | ||
| self.timeline_iface = omni.timeline.acquire_timeline_interface() | ||
| self.current_frame = FIRST_MOVING_FRAME | ||
|
|
||
| with rep.trigger.on_frame(): | ||
| randomize_robot_pose() | ||
| if self.randomize_all_frames: | ||
| # Spawn robot pick animation | ||
| self.robot = rep.create.from_usd(str(ROBOT_PATH), semantics={"class": "robot"}) | ||
|
|
||
| def randomize_robot_pose() -> None: | ||
| """Randomize robot animation frame and rotation.""" | ||
| with self.robot: | ||
| rep.modify.timeline(rep.distribution.uniform(lower=0, upper=NUM_FRAMES), modify_type="frame") | ||
| rep.modify.pose(rotation_z=rep.distribution.uniform(0.0, 360.0)) | ||
|
|
||
| rep.randomizer.register(randomize_robot_pose) | ||
|
|
||
| with rep.trigger.on_frame(): | ||
| randomize_robot_pose() | ||
| else: | ||
| random_rotation = np.random.uniform(0.0, 360.0) | ||
| f_reference( | ||
| usd_path=str(ROBOT_PATH), | ||
| position=(0, 0, 0), | ||
| rotation=(0, 0, random_rotation), | ||
| semantics={"class": "robot"}, | ||
| ) | ||
|
|
||
| def randomize(self) -> None: | ||
| """Apply randomization to the robot.""" | ||
| if self.randomize_all_frames: | ||
| return | ||
| fps = float(self.timeline_iface.get_time_codes_per_seconds()) | ||
| self.timeline_iface.set_current_time(self.current_frame / fps) | ||
| self.current_frame += 1 | ||
| if self.current_frame >= NUM_FRAMES: | ||
| self.current_frame = FIRST_MOVING_FRAME | ||
|
Comment on lines
+82
to
+90
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This method loops over the animation sequentially? |
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Is it a necessity that the registered functions need to receive no params? Otherwise, for consistency and to reduce nesting, I'd suggest define the randomization method we're registering as a class method and just register it when
randomize_all_framesis set for all randomizers that use replication.