I am trying to randomize the pose and rotation of objects spawn in the scene relative to the camera, hence, I used this function
from offline_pose_estimation.py from Isaac Sim Standalone/Replicator examples so that I could apply it on traffic cone.
offline_pose_generation.py
from 6. Offline Pose Estimation Synthetic Data Generation — Omniverse Robotics documentation
and offline_generation.py
from: 3. Offline Dataset Generation — Omniverse Robotics documentation
Here’s variable initialization inside offline_generation.py
:
world = World()
world.reset()
F_X = 768.1605834960938
F_Y = 768.1605834960938
width = 1024
height = 1024
fov_x = 2 * math.atan(width / (2 * F_X))
fov_y = 2 * math.atan(height / (2 * F_Y))
test_translations = [0.15, 0.15, -0.5]
test_rotations = [0.4619398, 0.1913417, 0.4619398, 0.7325378]
object_scale = [1, 1, 1]
train_parts = []
Here’s a sample code:
def randomize_movement_in_view(self, prim):
"""Randomly move and rotate prim such that it stays in view of camera.
Args:
prim (DynamicObject): prim to randomly move and rotate.
"""
if not self.test:
camera_prim = world.stage.GetPrimAtPath(self.camera_path)
rig_prim = world.stage.GetPrimAtPath(self.rig.prim_path)
translation, orientation = get_random_world_pose_in_view(
camera_prim,
0.4, #MIN_DISTANCE
1.4, #MAX_DISTANCE
fov_x,
fov_y,
0.9, #FRACTION_TO_SCREEN_EDGE
rig_prim,
np.array([-180, -90, -180]), #MIN_ROTATION_RANGE
np.array([180, 90, 180]), #MAX_ROTATION_RANGE
)
else:
translation = np.array(test_translations)
orientation = np.array(test_rotations)
prim.set_world_pose(translation, orientation)
and here’s how it’s used:
# # Spawn a new cone at a random pose
cone_prim = prims.create_prim(
prim_path=f"{SCOPE_NAME}/Cone",
position=(random.uniform(-50, -4), random.uniform(-1, 3), 0),
orientation=euler_angles_to_quat([0, 0, random.uniform(0, math.pi)]),
usd_path=prefix_with_isaac_asset_server(CONE_URL),
semantic_label="Cone",
)
# Add the part to train the network on
part_name = "Cone"
ref_path = get_assets_root_path() + CONE_URL
prim_type = f"{part_name}"
# path = "/World/" + prim_type
path = f"{SCOPE_NAME}/Cone"
name = "train_part"
for child_prim in cone_prim.GetChildren():
if child_prim.IsA(UsdGeom.Mesh):
mesh_path = child_prim.GetPath()
print('Cone mesh_path: ', mesh_path)
train_part = DynamicObject(
usd_path=ref_path,
prim_path=path,
mesh_path=mesh_path,
name=name,
position=np.array([0.0, 0.0, 0.0]),
scale=np.array(object_scale),
mass=1.0,
)
train_part.prim.GetAttribute("physics:rigidBodyEnabled").Set(True)
Here’s the error I receive:
(isaac-sim) mona@ard-gpu-01:~/.local/share/ov/pkg/isaac_sim-2022.2.0$ ./python.sh ~/omniverse-sdg/offline_generation.py
7.706s] app ready
[7.794s] RTX ready
[7.794s] RTX ready
[7.877s] Simulation App Startup Complete
Loading Stage /Isaac/Environments/Simple_Warehouse/full_warehouse.usd
2023-02-06 19:48:08 [10,800ms] [Warning] [rtx.neuraylib.plugin] [MDLC:COMPILER] 1.0 MDLC comp warn : omniverse://localhost/NVIDIA/Assets/Isaac/2022.2.0/Isaac/Environments/Simple_Warehouse/Materials/MaterialInstanceDynamic_1220.mdl?watch=00007f1f91860240(61,8): C181 unused variable 'Local15'
2023-02-06 19:48:08 [10,800ms] [Warning] [rtx.neuraylib.plugin] [MDLC:COMPILER] 1.0 MDLC comp warn : omniverse://localhost/NVIDIA/Assets/Isaac/2022.2.0/Isaac/Environments/Simple_Warehouse/Materials/MaterialInstanceDynamic_1220.mdl?watch=00007f1f91860240(61,8): C181 unused variable 'Local15'
2023-02-06 19:48:08 [10,800ms] [Warning] [rtx.neuraylib.plugin] [MDLC:COMPILER] 1.0 MDLC comp warn : omniverse://localhost/NVIDIA/Assets/Isaac/2022.2.0/Isaac/Environments/Simple_Warehouse/Materials/MaterialInstanceDynamic_1220.mdl?watch=00007f1f91860240(61,8): C181 unused variable 'Local15'
2023-02-06 19:48:08 [10,800ms] [Warning] [rtx.neuraylib.plugin] [MDLC:COMPILER] 1.0 MDLC comp warn : omniverse://localhost/NVIDIA/Assets/Isaac/2022.2.0/Isaac/Environments/Simple_Warehouse/Materials/MaterialInstanceDynamic_1220.mdl?watch=00007f1f91860240(61,8): C181 unused variable 'Local15'
2023-02-06 19:48:08 [10,800ms] [Warning] [rtx.neuraylib.plugin] Compiler Core: omniverse://localhost/NVIDIA/Assets/Isaac/2022.2.0/Isaac/Environments/Simple_Warehouse/Materials/MaterialInstanceDynamic_1220.mdl?watch=00007f1f91860240(61,8): C181 unused variable 'Local15'
2023-02-06 19:48:08 [10,800ms] [Warning] [rtx.neuraylib.plugin] Compiler Core: omniverse://localhost/NVIDIA/Assets/Isaac/2022.2.0/Isaac/Environments/Simple_Warehouse/Materials/MaterialInstanceDynamic_1220.mdl?watch=00007f1f91860240(61,8): C181 unused variable 'Local15'
2023-02-06 19:48:09 [11,648ms] [Warning] [omni.isaac.core.simulation_context.simulation_context] A new stage was opened, World or Simulation Object are invalidated and you would need to initialize them again before using them.
Cone mesh_path: /MyScope/Cone/S_TrafficCone
-------------------------------------------------
mesh path: /MyScope/Cone/S_TrafficCone
prim: Usd.Prim(</MyScope/Cone/S_TrafficCone>)
assets root path: omniverse://localhost/NVIDIA/Assets/Isaac/2022.2.0
self.usd_path: omniverse://localhost/NVIDIA/Assets/Isaac/2022.2.0/Isaac/Environments/Simple_Warehouse/Props/S_TrafficCone.usd
type of train_part: <class 'flying_distractors.dynamic_object.DynamicObject'>
2023-02-06 19:48:09 [11,670ms] [Error] [__main__] Exception: randomize_movement_in_view() missing 1 required positional argument: 'prim'
Traceback (most recent call last):
File "/home/mona/omniverse-sdg/offline_generation.py", line 635, in <module>
main()
File "/home/mona/omniverse-sdg/offline_generation.py", line 515, in main
randomize_movement_in_view(train_part)
TypeError: randomize_movement_in_view() missing 1 required positional argument: 'prim'
[11.765s] Simulation App Shutting Down
The randomize_movement_in_view function is coming from offline_pose_generation/offline_pose_generation.py example in Replicator. I also copied its flying_distractor
folder to my code folder:
(base) mona@ard-gpu-01:~/omniverse-sdg$ tree .
.
├── flying_distractors
│ ├── collision_box.py
│ ├── dynamic_asset_set.py
│ ├── dynamic_object.py
│ ├── dynamic_object_set.py
│ ├── dynamic_shape_set.py
│ ├── flying_distractors.py
│ ├── __init__.py
│ └── __pycache__
│ ├── collision_box.cpython-37.pyc
│ ├── dynamic_asset_set.cpython-37.pyc
│ ├── dynamic_object.cpython-37.pyc
│ ├── dynamic_object_set.cpython-37.pyc
│ ├── dynamic_shape_set.cpython-37.pyc
│ ├── flying_distractors.cpython-37.pyc
│ └── __init__.cpython-37.pyc
├── offline_generation.py
├── README.md
└── test_USD.py
2 directories, 17 files
The traffic Cone is from here: