Skip to content

deprecated_utils

A set of utility functions slated to be deprecated once Omniverse bugs are fixed

ArticulationView

Bases: Articulation

ArticulationView with some additional functionality implemented.

Source code in OmniGibson/omnigibson/utils/deprecated_utils.py
 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
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
class ArticulationView(_ArticulationView):
    """ArticulationView with some additional functionality implemented."""

    def set_joint_limits(
        self,
        values: Union[np.ndarray, torch.Tensor],
        indices: Optional[Union[np.ndarray, List, torch.Tensor, wp.array]] = None,
        joint_indices: Optional[Union[np.ndarray, List, torch.Tensor, wp.array]] = None,
    ) -> None:
        """Sets joint limits for articulation joints in the view.

        Args:
            values (Union[np.ndarray, torch.Tensor, wp.array]): joint limits for articulations in the view. shape (M, K, 2).
            indices (Optional[Union[np.ndarray, List, torch.Tensor, wp.array]], optional): indicies to specify which prims
                                                                                 to manipulate. Shape (M,).
                                                                                 Where M <= size of the encapsulated prims in the view.
                                                                                 Defaults to None (i.e: all prims in the view).
            joint_indices (Optional[Union[np.ndarray, List, torch.Tensor, wp.array]], optional): joint indicies to specify which joints
                                                                                 to manipulate. Shape (K,).
                                                                                 Where K <= num of dofs.
                                                                                 Defaults to None (i.e: all dofs).
        """
        if not self._is_initialized:
            carb.log_warn("ArticulationView needs to be initialized.")
            return
        if not omni.timeline.get_timeline_interface().is_stopped() and self._physics_view is not None:
            indices = self._backend_utils.resolve_indices(indices, self.count, "cpu")
            joint_indices = self._backend_utils.resolve_indices(joint_indices, self.num_dof, "cpu")
            new_values = self._physics_view.get_dof_limits()
            values = self._backend_utils.move_data(values, device="cpu")
            new_values = self._backend_utils.assign(
                values,
                new_values,
                [self._backend_utils.expand_dims(indices, 1) if self._backend != "warp" else indices, joint_indices],
            )
            self._physics_view.set_dof_limits(new_values, indices)
        else:
            indices = self._backend_utils.to_list(
                self._backend_utils.resolve_indices(indices, self.count, self._device)
            )
            dof_types = self._backend_utils.to_list(self.get_dof_types())
            joint_indices = self._backend_utils.to_list(
                self._backend_utils.resolve_indices(joint_indices, self.num_dof, self._device)
            )
            values = self._backend_utils.to_list(values)
            articulation_read_idx = 0
            for i in indices:
                dof_read_idx = 0
                for dof_index in joint_indices:
                    dof_val = values[articulation_read_idx][dof_read_idx]
                    if dof_types[dof_index] == omni.physics.tensors.DofType.Rotation:
                        dof_val /= DEG2RAD
                    prim = get_prim_at_path(self._dof_paths[i][dof_index])
                    prim.GetAttribute("physics:lowerLimit").Set(dof_val[0])
                    prim.GetAttribute("physics:upperLimit").Set(dof_val[1])
                    dof_read_idx += 1
                articulation_read_idx += 1
        return

    def get_joint_limits(
        self,
        indices: Optional[Union[np.ndarray, List, torch.Tensor, wp.array]] = None,
        joint_indices: Optional[Union[np.ndarray, List, torch.Tensor, wp.array]] = None,
        clone: bool = True,
    ) -> Union[np.ndarray, torch.Tensor, wp.array]:
        """Gets joint limits for articulation in the view.

        Args:
            indices (Optional[Union[np.ndarray, List, torch.Tensor, wp.array]], optional): indicies to specify which prims
                                                                                 to query. Shape (M,).
                                                                                 Where M <= size of the encapsulated prims in the view.
                                                                                 Defaults to None (i.e: all prims in the view).
            joint_indices (Optional[Union[np.ndarray, List, torch.Tensor, wp.array]], optional): joint indicies to specify which joints
                                                                                 to query. Shape (K,).
                                                                                 Where K <= num of dofs.
                                                                                 Defaults to None (i.e: all dofs).
            clone (Optional[bool]): True to return a clone of the internal buffer. Otherwise False. Defaults to True.

        Returns:
            Union[np.ndarray, torch.Tensor, wp.indexedarray]: joint limits for articulations in the view. shape (M, K).
        """
        if not self._is_initialized:
            carb.log_warn("ArticulationView needs to be initialized.")
            return None
        if not omni.timeline.get_timeline_interface().is_stopped() and self._physics_view is not None:
            indices = self._backend_utils.resolve_indices(indices, self.count, self._device)
            joint_indices = self._backend_utils.resolve_indices(joint_indices, self.num_dof, self._device)
            values = self._backend_utils.move_data(self._physics_view.get_dof_limits(), self._device)
            if clone:
                values = self._backend_utils.clone_tensor(values, device=self._device)
            result = values[
                self._backend_utils.expand_dims(indices, 1) if self._backend != "warp" else indices, joint_indices
            ]
            return result
        else:
            indices = self._backend_utils.resolve_indices(indices, self.count, self._device)
            dof_types = self._backend_utils.to_list(self.get_dof_types())
            joint_indices = self._backend_utils.resolve_indices(joint_indices, self.num_dof, self._device)
            values = np.zeros(shape=(indices.shape[0], joint_indices.shape[0], 2), dtype="float32")
            articulation_write_idx = 0
            indices = self._backend_utils.to_list(indices)
            joint_indices = self._backend_utils.to_list(joint_indices)
            for i in indices:
                dof_write_idx = 0
                for dof_index in joint_indices:
                    prim = get_prim_at_path(self._dof_paths[i][dof_index])
                    values[articulation_write_idx][dof_write_idx][0] = prim.GetAttribute("physics:lowerLimit").Get()
                    values[articulation_write_idx][dof_write_idx][1] = prim.GetAttribute("physics:upperLimit").Get()
                    if dof_types[dof_index] == omni.physics.tensors.DofType.Rotation:
                        values[articulation_write_idx][dof_write_idx] = (
                            values[articulation_write_idx][dof_write_idx] * DEG2RAD
                        )
                    dof_write_idx += 1
                articulation_write_idx += 1
            values = self._backend_utils.convert(values, dtype="float32", device=self._device, indexed=True)
            return values

    def get_joint_position_targets(
        self,
        indices: Optional[Union[np.ndarray, List, torch.Tensor, wp.array]] = None,
        joint_indices: Optional[Union[np.ndarray, List, torch.Tensor, wp.array]] = None,
        clone: bool = True,
    ) -> Union[np.ndarray, torch.Tensor, wp.indexedarray]:
        """Get the joint position targets of articulations in the view

        Args:
            indices (Optional[Union[np.ndarray, List, torch.Tensor, wp.array]], optional): indices to specify which prims
                                                                                 to query. Shape (M,).
                                                                                 Where M <= size of the encapsulated prims in the view.
                                                                                 Defaults to None (i.e: all prims in the view).
            joint_indices (Optional[Union[np.ndarray, List, torch.Tensor, wp.array]], optional): joint indices to specify which joints
                                                                                 to query. Shape (K,).
                                                                                 Where K <= num of dofs.
                                                                                 Defaults to None (i.e: all dofs).
            clone (bool, optional): True to return a clone of the internal buffer. Otherwise False. Defaults to True.

        Returns:
            Union[np.ndarray, torch.Tensor, wp.indexedarray]: joint positions of articulations in the view.
            Shape is (M, K).
        """
        if not self._is_initialized:
            carb.log_warn("ArticulationView needs to be initialized.")
            return None
        if not omni.timeline.get_timeline_interface().is_stopped() and self._physics_view is not None:
            indices = self._backend_utils.resolve_indices(indices, self.count, self._device)
            joint_indices = self._backend_utils.resolve_indices(joint_indices, self.num_dof, self._device)
            current_joint_positions = self._physics_view.get_dof_position_targets()
            if clone:
                current_joint_positions = self._backend_utils.clone_tensor(current_joint_positions, device=self._device)
            result = current_joint_positions[
                self._backend_utils.expand_dims(indices, 1) if self._backend != "warp" else indices, joint_indices
            ]
            return result
        else:
            carb.log_warn("Physics Simulation View is not created yet in order to use get_joint_position_targets")
            return None

    def get_joint_velocity_targets(
        self,
        indices: Optional[Union[np.ndarray, List, torch.Tensor, wp.array]] = None,
        joint_indices: Optional[Union[np.ndarray, List, torch.Tensor, wp.array]] = None,
        clone: bool = True,
    ) -> Union[np.ndarray, torch.Tensor, wp.indexedarray]:
        """Get the joint velocity targets of articulations in the view

        Args:
            indices (Optional[Union[np.ndarray, List, torch.Tensor, wp.array]], optional): indices to specify which prims
                                                                                 to query. Shape (M,).
                                                                                 Where M <= size of the encapsulated prims in the view.
                                                                                 Defaults to None (i.e: all prims in the view).
            joint_indices (Optional[Union[np.ndarray, List, torch.Tensor, wp.array]], optional): joint indices to specify which joints
                                                                                 to query. Shape (K,).
                                                                                 Where K <= num of dofs.
                                                                                 Defaults to None (i.e: all dofs).
            clone (bool, optional): True to return a clone of the internal buffer. Otherwise False. Defaults to True.

        Returns:
            Union[np.ndarray, torch.Tensor, wp.indexedarray]: joint velocities of articulations in the view.
            Shape is (M, K).
        """
        if not self._is_initialized:
            carb.log_warn("ArticulationView needs to be initialized.")
            return None
        if not omni.timeline.get_timeline_interface().is_stopped() and self._physics_view is not None:
            indices = self._backend_utils.resolve_indices(indices, self.count, self._device)
            joint_indices = self._backend_utils.resolve_indices(joint_indices, self.num_dof, self._device)
            current_joint_velocities = self._physics_view.get_dof_velocity_targets()
            if clone:
                current_joint_velocities = self._backend_utils.clone_tensor(
                    current_joint_velocities, device=self._device
                )
            result = current_joint_velocities[
                self._backend_utils.expand_dims(indices, 1) if self._backend != "warp" else indices, joint_indices
            ]
            return result
        else:
            carb.log_warn("Physics Simulation View is not created yet in order to use get_joint_velocity_targets")
            return None

    def set_max_velocities(
        self,
        values: Union[np.ndarray, torch.Tensor, wp.array],
        indices: Optional[Union[np.ndarray, List, torch.Tensor, wp.array]] = None,
        joint_indices: Optional[Union[np.ndarray, List, torch.Tensor, wp.array]] = None,
    ) -> None:
        """Sets maximum velocities for articulation in the view.

        Args:
            values (Union[np.ndarray, torch.Tensor, wp.array]): maximum velocities for articulations in the view. shape (M, K).
            indices (Optional[Union[np.ndarray, List, torch.Tensor, wp.array]], optional): indicies to specify which prims
                                                                                 to manipulate. Shape (M,).
                                                                                 Where M <= size of the encapsulated prims in the view.
                                                                                 Defaults to None (i.e: all prims in the view).
            joint_indices (Optional[Union[np.ndarray, List, torch.Tensor, wp.array]], optional): joint indicies to specify which joints
                                                                                 to manipulate. Shape (K,).
                                                                                 Where K <= num of dofs.
                                                                                 Defaults to None (i.e: all dofs).
        """
        if not self._is_initialized:
            carb.log_warn("ArticulationView needs to be initialized.")
            return
        if not omni.timeline.get_timeline_interface().is_stopped() and self._physics_view is not None:
            indices = self._backend_utils.resolve_indices(indices, self.count, "cpu")
            joint_indices = self._backend_utils.resolve_indices(joint_indices, self.num_dof, "cpu")
            new_values = self._physics_view.get_dof_max_velocities()
            new_values = self._backend_utils.assign(
                self._backend_utils.move_data(values, device="cpu"),
                new_values,
                [self._backend_utils.expand_dims(indices, 1) if self._backend != "warp" else indices, joint_indices],
            )
            self._physics_view.set_dof_max_velocities(new_values, indices)
        else:
            indices = self._backend_utils.resolve_indices(indices, self.count, self._device)
            joint_indices = self._backend_utils.resolve_indices(joint_indices, self.num_dof, self._device)
            articulation_read_idx = 0
            indices = self._backend_utils.to_list(indices)
            joint_indices = self._backend_utils.to_list(joint_indices)
            values = self._backend_utils.to_list(values)
            for i in indices:
                dof_read_idx = 0
                for dof_index in joint_indices:
                    prim = PhysxSchema.PhysxJointAPI(get_prim_at_path(self._dof_paths[i][dof_index]))
                    if not prim.GetMaxJointVelocityAttr():
                        prim.CreateMaxJointVelocityAttr().Set(values[articulation_read_idx][dof_read_idx])
                    else:
                        prim.GetMaxJointVelocityAttr().Set(values[articulation_read_idx][dof_read_idx])
                    dof_read_idx += 1
                articulation_read_idx += 1
        return

    def get_max_velocities(
        self,
        indices: Optional[Union[np.ndarray, List, torch.Tensor, wp.array]] = None,
        joint_indices: Optional[Union[np.ndarray, List, torch.Tensor, wp.array]] = None,
        clone: bool = True,
    ) -> Union[np.ndarray, torch.Tensor, wp.indexedarray]:
        """Gets maximum velocities for articulation in the view.

        Args:
            indices (Optional[Union[np.ndarray, List, torch.Tensor, wp.array]], optional): indicies to specify which prims
                                                                                 to query. Shape (M,).
                                                                                 Where M <= size of the encapsulated prims in the view.
                                                                                 Defaults to None (i.e: all prims in the view).
            joint_indices (Optional[Union[np.ndarray, List, torch.Tensor, wp.array]], optional): joint indicies to specify which joints
                                                                                 to query. Shape (K,).
                                                                                 Where K <= num of dofs.
                                                                                 Defaults to None (i.e: all dofs).
            clone (Optional[bool]): True to return a clone of the internal buffer. Otherwise False. Defaults to True.

        Returns:
            Union[np.ndarray, torch.Tensor, wp.indexedarray]: maximum velocities for articulations in the view. shape (M, K).
        """
        if not self._is_initialized:
            carb.log_warn("ArticulationView needs to be initialized.")
            return None
        if not omni.timeline.get_timeline_interface().is_stopped() and self._physics_view is not None:
            indices = self._backend_utils.resolve_indices(indices, self.count, "cpu")
            joint_indices = self._backend_utils.resolve_indices(joint_indices, self.num_dof, "cpu")
            max_velocities = self._physics_view.get_dof_max_velocities()
            if clone:
                max_velocities = self._backend_utils.clone_tensor(max_velocities, device="cpu")
            result = self._backend_utils.move_data(
                max_velocities[
                    self._backend_utils.expand_dims(indices, 1) if self._backend != "warp" else indices, joint_indices
                ],
                device=self._device,
            )
            return result
        else:
            indices = self._backend_utils.resolve_indices(indices, self.count, self._device)
            joint_indices = self._backend_utils.resolve_indices(joint_indices, self.num_dof, self._device)
            max_velocities = np.zeros(shape=(indices.shape[0], joint_indices.shape[0]), dtype="float32")
            indices = self._backend_utils.to_list(indices)
            joint_indices = self._backend_utils.to_list(joint_indices)
            articulation_write_idx = 0
            for i in indices:
                dof_write_idx = 0
                for dof_index in joint_indices:
                    prim = PhysxSchema.PhysxJointAPI(get_prim_at_path(self._dof_paths[i][dof_index]))
                    max_velocities[articulation_write_idx][dof_write_idx] = prim.GetMaxJointVelocityAttr().Get()
                    dof_write_idx += 1
                articulation_write_idx += 1
            max_velocities = self._backend_utils.convert(
                max_velocities, dtype="float32", device=self._device, indexed=True
            )
            return max_velocities

    def set_joint_positions(
        self,
        positions: Optional[Union[np.ndarray, torch.Tensor, wp.array]],
        indices: Optional[Union[np.ndarray, List, torch.Tensor, wp.array]] = None,
        joint_indices: Optional[Union[np.ndarray, List, torch.Tensor, wp.array]] = None,
    ) -> None:
        """Set the joint positions of articulations in the view

        .. warning::

            This method will immediately set (teleport) the affected joints to the indicated value.
            Use the ``set_joint_position_targets`` or the ``apply_action`` methods to control the articulation joints.

        Args:
            positions (Optional[Union[np.ndarray, torch.Tensor, wp.array]]): joint positions of articulations in the view to be set to in the next frame.
                                                                    shape is (M, K).
            indices (Optional[Union[np.ndarray, List, torch.Tensor, wp.array]], optional): indices to specify which prims
                                                                                 to manipulate. Shape (M,).
                                                                                 Where M <= size of the encapsulated prims in the view.
                                                                                 Defaults to None (i.e: all prims in the view).
            joint_indices (Optional[Union[np.ndarray, List, torch.Tensor, wp.array]], optional): joint indices to specify which joints
                                                                                 to manipulate. Shape (K,).
                                                                                 Where K <= num of dofs.
                                                                                 Defaults to None (i.e: all dofs).

        .. hint::

            This method belongs to the methods used to set the articulation kinematic states:

            ``set_velocities`` (``set_linear_velocities``, ``set_angular_velocities``),
            ``set_joint_positions``, ``set_joint_velocities``, ``set_joint_efforts``

        Example:

        .. code-block:: python

            >>> # set all the articulation joints.
            >>> # Since there are 5 envs, the joint positions are repeated 5 times
            >>> positions = np.tile(np.array([0.0, -1.0, 0.0, -2.2, 0.0, 2.4, 0.8, 0.04, 0.04]), (num_envs, 1))
            >>> prims.set_joint_positions(positions)
            >>>
            >>> # set only the fingers in closed position: panda_finger_joint1 (7) and panda_finger_joint2 (8) to 0.0
            >>> # for the first, middle and last of the 5 envs
            >>> positions = np.tile(np.array([0.0, 0.0]), (3, 1))
            >>> prims.set_joint_positions(positions, indices=np.array([0, 2, 4]), joint_indices=np.array([7, 8]))
        """
        if not self._is_initialized:
            carb.log_warn("ArticulationView needs to be initialized.")
            return
        if not omni.timeline.get_timeline_interface().is_stopped() and self._physics_view is not None:
            indices = self._backend_utils.resolve_indices(indices, self.count, self._device)
            joint_indices = self._backend_utils.resolve_indices(joint_indices, self.num_dof, self._device)
            new_dof_pos = self._physics_view.get_dof_positions()
            new_dof_pos = self._backend_utils.assign(
                self._backend_utils.move_data(positions, device=self._device),
                new_dof_pos,
                [self._backend_utils.expand_dims(indices, 1) if self._backend != "warp" else indices, joint_indices],
            )
            self._physics_view.set_dof_positions(new_dof_pos, indices)

            # THIS IS THE FIX:
            #   FIX V1: COMMENT OUT THE BELOW LINE AND SET TARGETS INSTEAD
            #   FIX V2: DECOUPLE INSTANTANEOUS POSITION FROM TARGETS
            # self._physics_view.set_dof_position_targets(new_dof_pos, indices)
            # self.set_joint_position_targets(positions, indices, joint_indices)
        else:
            carb.log_warn("Physics Simulation View is not created yet in order to use set_joint_positions")

    def set_joint_velocities(
        self,
        velocities: Optional[Union[np.ndarray, torch.Tensor, wp.array]],
        indices: Optional[Union[np.ndarray, List, torch.Tensor, wp.array]] = None,
        joint_indices: Optional[Union[np.ndarray, List, torch.Tensor, wp.array]] = None,
    ) -> None:
        """Set the joint velocities of articulations in the view

        .. warning::

            This method will immediately set the affected joints to the indicated value.
            Use the ``set_joint_velocity_targets`` or the ``apply_action`` methods to control the articulation joints.

        Args:
            velocities (Optional[Union[np.ndarray, torch.Tensor, wp.array]]): joint velocities of articulations in the view to be set to in the next frame.
                                                                    shape is (M, K).
            indices (Optional[Union[np.ndarray, List, torch.Tensor, wp.array]], optional): indices to specify which prims
                                                                                 to manipulate. Shape (M,).
                                                                                 Where M <= size of the encapsulated prims in the view.
                                                                                 Defaults to None (i.e: all prims in the view).
            joint_indices (Optional[Union[np.ndarray, List, torch.Tensor, wp.array]], optional): joint indices to specify which joints
                                                                                 to manipulate. Shape (K,).
                                                                                 Where K <= num of dofs.
                                                                                 Defaults to None (i.e: all dofs).

        .. hint::

            This method belongs to the methods used to set the articulation kinematic states:

            ``set_velocities`` (``set_linear_velocities``, ``set_angular_velocities``),
            ``set_joint_positions``, ``set_joint_velocities``, ``set_joint_efforts``

        Example:

        .. code-block:: python

            >>> # set the velocities for all the articulation joints to the indicated values.
            >>> # Since there are 5 envs, the joint velocities are repeated 5 times
            >>> velocities = np.tile(np.array([0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9]), (num_envs, 1))
            >>> prims.set_joint_velocities(velocities)
            >>>
            >>> # set the fingers velocities: panda_finger_joint1 (7) and panda_finger_joint2 (8) to -0.1
            >>> # for the first, middle and last of the 5 envs
            >>> velocities = np.tile(np.array([-0.1, -0.1]), (3, 1))
            >>> prims.set_joint_velocities(velocities, indices=np.array([0, 2, 4]), joint_indices=np.array([7, 8]))
        """
        if not self._is_initialized:
            carb.log_warn("ArticulationView needs to be initialized.")
            return
        if not omni.timeline.get_timeline_interface().is_stopped() and self._physics_view is not None:
            indices = self._backend_utils.resolve_indices(indices, self.count, self._device)
            joint_indices = self._backend_utils.resolve_indices(joint_indices, self.num_dof, self._device)
            new_dof_vel = self._physics_view.get_dof_velocities()
            new_dof_vel = self._backend_utils.assign(
                self._backend_utils.move_data(velocities, device=self._device),
                new_dof_vel,
                [self._backend_utils.expand_dims(indices, 1) if self._backend != "warp" else indices, joint_indices],
            )
            self._physics_view.set_dof_velocities(new_dof_vel, indices)

            # THIS IS THE FIX:
            #   FIX V1: COMMENT OUT THE BELOW LINE AND SET TARGETS INSTEAD
            #   FIX V2: DECOUPLE INSTANTANEOUS VELOCITY FROM TARGETS
            # self._physics_view.set_dof_velocity_targets(new_dof_vel, indices)
            # self.set_joint_velocity_targets(velocities, indices, joint_indices)
        else:
            carb.log_warn("Physics Simulation View is not created yet in order to use set_joint_velocities")
        return

    def set_joint_efforts(
        self,
        efforts: Optional[Union[np.ndarray, torch.Tensor, wp.array]],
        indices: Optional[Union[np.ndarray, List, torch.Tensor, wp.array]] = None,
        joint_indices: Optional[Union[np.ndarray, List, torch.Tensor, wp.array]] = None,
    ) -> None:
        """Set the joint efforts of articulations in the view

        .. note::

            This method can be used for effort control. For this purpose, there must be no joint drive
            or the stiffness and damping must be set to zero.

        Args:
            efforts (Optional[Union[np.ndarray, torch.Tensor, wp.array]]): efforts of articulations in the view to be set to in the next frame.
                                                                    shape is (M, K).
            indices (Optional[Union[np.ndarray, List, torch.Tensor, wp.array]], optional): indices to specify which prims
                                                                                 to manipulate. Shape (M,).
                                                                                 Where M <= size of the encapsulated prims in the view.
                                                                                 Defaults to None (i.e: all prims in the view).
            joint_indices (Optional[Union[np.ndarray, List, torch.Tensor, wp.array]], optional): joint indices to specify which joints
                                                                                 to manipulate. Shape (K,).
                                                                                 Where K <= num of dofs.
                                                                                 Defaults to None (i.e: all dofs).

        .. hint::

            This method belongs to the methods used to set the articulation kinematic states:

            ``set_velocities`` (``set_linear_velocities``, ``set_angular_velocities``),
            ``set_joint_positions``, ``set_joint_velocities``, ``set_joint_efforts``

        Example:

        .. code-block:: python

            >>> # set the efforts for all the articulation joints to the indicated values.
            >>> # Since there are 5 envs, the joint efforts are repeated 5 times
            >>> efforts = np.tile(np.array([10, 20, 30, 40, 50, 60, 70, 80, 90]), (num_envs, 1))
            >>> prims.set_joint_efforts(efforts)
            >>>
            >>> # set the fingers efforts: panda_finger_joint1 (7) and panda_finger_joint2 (8) to 10
            >>> # for the first, middle and last of the 5 envs
            >>> efforts = np.tile(np.array([10, 10]), (3, 1))
            >>> prims.set_joint_efforts(efforts, indices=np.array([0, 2, 4]), joint_indices=np.array([7, 8]))
        """
        if not self._is_initialized:
            carb.log_warn("ArticulationView needs to be initialized.")
            return

        if not omni.timeline.get_timeline_interface().is_stopped() and self._physics_view is not None:
            indices = self._backend_utils.resolve_indices(indices, self.count, self._device)
            joint_indices = self._backend_utils.resolve_indices(joint_indices, self.num_dof, self._device)

            # THIS IS THE FIX: COMMENT OUT THE BELOW LINE AND USE ACTUATION FORCES INSTEAD
            # new_dof_efforts = self._backend_utils.create_zeros_tensor(
            #     shape=[self.count, self.num_dof], dtype="float32", device=self._device
            # )
            new_dof_efforts = self._physics_view.get_dof_actuation_forces()
            new_dof_efforts = self._backend_utils.assign(
                self._backend_utils.move_data(efforts, device=self._device),
                new_dof_efforts,
                [self._backend_utils.expand_dims(indices, 1) if self._backend != "warp" else indices, joint_indices],
            )
            self._physics_view.set_dof_actuation_forces(new_dof_efforts, indices)
        else:
            carb.log_warn("Physics Simulation View is not created yet in order to use set_joint_efforts")
        return

    def _invalidate_physics_handle_callback(self, event):
        # Overwrite super method, add additional de-initialization
        if event.type == int(omni.timeline.TimelineEventType.STOP):
            self._physics_view = None
            self._invalidate_physics_handle_event = None
            self._is_initialized = False

    @property
    def initialized(self):
        # THIS IS THE FIX: another crazy bug from isaac, specifically isaac 4.5
        return self._is_initialized

    def _on_prim_deletion(self, prim_path):
        _XFormPrimView._on_prim_deletion(self, prim_path)
        self._physics_view = None

get_joint_limits(indices=None, joint_indices=None, clone=True)

Gets joint limits for articulation in the view.

Parameters:

Name Type Description Default
indices Optional[Union[ndarray, List, Tensor, array]]

indicies to specify which prims to query. Shape (M,). Where M <= size of the encapsulated prims in the view. Defaults to None (i.e: all prims in the view).

None
joint_indices Optional[Union[ndarray, List, Tensor, array]]

joint indicies to specify which joints to query. Shape (K,). Where K <= num of dofs. Defaults to None (i.e: all dofs).

None
clone Optional[bool]

True to return a clone of the internal buffer. Otherwise False. Defaults to True.

True

Returns:

Type Description
Union[ndarray, Tensor, indexedarray]

joint limits for articulations in the view. shape (M, K).

Source code in OmniGibson/omnigibson/utils/deprecated_utils.py
def get_joint_limits(
    self,
    indices: Optional[Union[np.ndarray, List, torch.Tensor, wp.array]] = None,
    joint_indices: Optional[Union[np.ndarray, List, torch.Tensor, wp.array]] = None,
    clone: bool = True,
) -> Union[np.ndarray, torch.Tensor, wp.array]:
    """Gets joint limits for articulation in the view.

    Args:
        indices (Optional[Union[np.ndarray, List, torch.Tensor, wp.array]], optional): indicies to specify which prims
                                                                             to query. Shape (M,).
                                                                             Where M <= size of the encapsulated prims in the view.
                                                                             Defaults to None (i.e: all prims in the view).
        joint_indices (Optional[Union[np.ndarray, List, torch.Tensor, wp.array]], optional): joint indicies to specify which joints
                                                                             to query. Shape (K,).
                                                                             Where K <= num of dofs.
                                                                             Defaults to None (i.e: all dofs).
        clone (Optional[bool]): True to return a clone of the internal buffer. Otherwise False. Defaults to True.

    Returns:
        Union[np.ndarray, torch.Tensor, wp.indexedarray]: joint limits for articulations in the view. shape (M, K).
    """
    if not self._is_initialized:
        carb.log_warn("ArticulationView needs to be initialized.")
        return None
    if not omni.timeline.get_timeline_interface().is_stopped() and self._physics_view is not None:
        indices = self._backend_utils.resolve_indices(indices, self.count, self._device)
        joint_indices = self._backend_utils.resolve_indices(joint_indices, self.num_dof, self._device)
        values = self._backend_utils.move_data(self._physics_view.get_dof_limits(), self._device)
        if clone:
            values = self._backend_utils.clone_tensor(values, device=self._device)
        result = values[
            self._backend_utils.expand_dims(indices, 1) if self._backend != "warp" else indices, joint_indices
        ]
        return result
    else:
        indices = self._backend_utils.resolve_indices(indices, self.count, self._device)
        dof_types = self._backend_utils.to_list(self.get_dof_types())
        joint_indices = self._backend_utils.resolve_indices(joint_indices, self.num_dof, self._device)
        values = np.zeros(shape=(indices.shape[0], joint_indices.shape[0], 2), dtype="float32")
        articulation_write_idx = 0
        indices = self._backend_utils.to_list(indices)
        joint_indices = self._backend_utils.to_list(joint_indices)
        for i in indices:
            dof_write_idx = 0
            for dof_index in joint_indices:
                prim = get_prim_at_path(self._dof_paths[i][dof_index])
                values[articulation_write_idx][dof_write_idx][0] = prim.GetAttribute("physics:lowerLimit").Get()
                values[articulation_write_idx][dof_write_idx][1] = prim.GetAttribute("physics:upperLimit").Get()
                if dof_types[dof_index] == omni.physics.tensors.DofType.Rotation:
                    values[articulation_write_idx][dof_write_idx] = (
                        values[articulation_write_idx][dof_write_idx] * DEG2RAD
                    )
                dof_write_idx += 1
            articulation_write_idx += 1
        values = self._backend_utils.convert(values, dtype="float32", device=self._device, indexed=True)
        return values

get_joint_position_targets(indices=None, joint_indices=None, clone=True)

Get the joint position targets of articulations in the view

Parameters:

Name Type Description Default
indices Optional[Union[ndarray, List, Tensor, array]]

indices to specify which prims to query. Shape (M,). Where M <= size of the encapsulated prims in the view. Defaults to None (i.e: all prims in the view).

None
joint_indices Optional[Union[ndarray, List, Tensor, array]]

joint indices to specify which joints to query. Shape (K,). Where K <= num of dofs. Defaults to None (i.e: all dofs).

None
clone bool

True to return a clone of the internal buffer. Otherwise False. Defaults to True.

True

Returns:

Type Description
Union[ndarray, Tensor, indexedarray]

joint positions of articulations in the view.

Union[ndarray, Tensor, indexedarray]

Shape is (M, K).

Source code in OmniGibson/omnigibson/utils/deprecated_utils.py
def get_joint_position_targets(
    self,
    indices: Optional[Union[np.ndarray, List, torch.Tensor, wp.array]] = None,
    joint_indices: Optional[Union[np.ndarray, List, torch.Tensor, wp.array]] = None,
    clone: bool = True,
) -> Union[np.ndarray, torch.Tensor, wp.indexedarray]:
    """Get the joint position targets of articulations in the view

    Args:
        indices (Optional[Union[np.ndarray, List, torch.Tensor, wp.array]], optional): indices to specify which prims
                                                                             to query. Shape (M,).
                                                                             Where M <= size of the encapsulated prims in the view.
                                                                             Defaults to None (i.e: all prims in the view).
        joint_indices (Optional[Union[np.ndarray, List, torch.Tensor, wp.array]], optional): joint indices to specify which joints
                                                                             to query. Shape (K,).
                                                                             Where K <= num of dofs.
                                                                             Defaults to None (i.e: all dofs).
        clone (bool, optional): True to return a clone of the internal buffer. Otherwise False. Defaults to True.

    Returns:
        Union[np.ndarray, torch.Tensor, wp.indexedarray]: joint positions of articulations in the view.
        Shape is (M, K).
    """
    if not self._is_initialized:
        carb.log_warn("ArticulationView needs to be initialized.")
        return None
    if not omni.timeline.get_timeline_interface().is_stopped() and self._physics_view is not None:
        indices = self._backend_utils.resolve_indices(indices, self.count, self._device)
        joint_indices = self._backend_utils.resolve_indices(joint_indices, self.num_dof, self._device)
        current_joint_positions = self._physics_view.get_dof_position_targets()
        if clone:
            current_joint_positions = self._backend_utils.clone_tensor(current_joint_positions, device=self._device)
        result = current_joint_positions[
            self._backend_utils.expand_dims(indices, 1) if self._backend != "warp" else indices, joint_indices
        ]
        return result
    else:
        carb.log_warn("Physics Simulation View is not created yet in order to use get_joint_position_targets")
        return None

get_joint_velocity_targets(indices=None, joint_indices=None, clone=True)

Get the joint velocity targets of articulations in the view

Parameters:

Name Type Description Default
indices Optional[Union[ndarray, List, Tensor, array]]

indices to specify which prims to query. Shape (M,). Where M <= size of the encapsulated prims in the view. Defaults to None (i.e: all prims in the view).

None
joint_indices Optional[Union[ndarray, List, Tensor, array]]

joint indices to specify which joints to query. Shape (K,). Where K <= num of dofs. Defaults to None (i.e: all dofs).

None
clone bool

True to return a clone of the internal buffer. Otherwise False. Defaults to True.

True

Returns:

Type Description
Union[ndarray, Tensor, indexedarray]

joint velocities of articulations in the view.

Union[ndarray, Tensor, indexedarray]

Shape is (M, K).

Source code in OmniGibson/omnigibson/utils/deprecated_utils.py
def get_joint_velocity_targets(
    self,
    indices: Optional[Union[np.ndarray, List, torch.Tensor, wp.array]] = None,
    joint_indices: Optional[Union[np.ndarray, List, torch.Tensor, wp.array]] = None,
    clone: bool = True,
) -> Union[np.ndarray, torch.Tensor, wp.indexedarray]:
    """Get the joint velocity targets of articulations in the view

    Args:
        indices (Optional[Union[np.ndarray, List, torch.Tensor, wp.array]], optional): indices to specify which prims
                                                                             to query. Shape (M,).
                                                                             Where M <= size of the encapsulated prims in the view.
                                                                             Defaults to None (i.e: all prims in the view).
        joint_indices (Optional[Union[np.ndarray, List, torch.Tensor, wp.array]], optional): joint indices to specify which joints
                                                                             to query. Shape (K,).
                                                                             Where K <= num of dofs.
                                                                             Defaults to None (i.e: all dofs).
        clone (bool, optional): True to return a clone of the internal buffer. Otherwise False. Defaults to True.

    Returns:
        Union[np.ndarray, torch.Tensor, wp.indexedarray]: joint velocities of articulations in the view.
        Shape is (M, K).
    """
    if not self._is_initialized:
        carb.log_warn("ArticulationView needs to be initialized.")
        return None
    if not omni.timeline.get_timeline_interface().is_stopped() and self._physics_view is not None:
        indices = self._backend_utils.resolve_indices(indices, self.count, self._device)
        joint_indices = self._backend_utils.resolve_indices(joint_indices, self.num_dof, self._device)
        current_joint_velocities = self._physics_view.get_dof_velocity_targets()
        if clone:
            current_joint_velocities = self._backend_utils.clone_tensor(
                current_joint_velocities, device=self._device
            )
        result = current_joint_velocities[
            self._backend_utils.expand_dims(indices, 1) if self._backend != "warp" else indices, joint_indices
        ]
        return result
    else:
        carb.log_warn("Physics Simulation View is not created yet in order to use get_joint_velocity_targets")
        return None

get_max_velocities(indices=None, joint_indices=None, clone=True)

Gets maximum velocities for articulation in the view.

Parameters:

Name Type Description Default
indices Optional[Union[ndarray, List, Tensor, array]]

indicies to specify which prims to query. Shape (M,). Where M <= size of the encapsulated prims in the view. Defaults to None (i.e: all prims in the view).

None
joint_indices Optional[Union[ndarray, List, Tensor, array]]

joint indicies to specify which joints to query. Shape (K,). Where K <= num of dofs. Defaults to None (i.e: all dofs).

None
clone Optional[bool]

True to return a clone of the internal buffer. Otherwise False. Defaults to True.

True

Returns:

Type Description
Union[ndarray, Tensor, indexedarray]

maximum velocities for articulations in the view. shape (M, K).

Source code in OmniGibson/omnigibson/utils/deprecated_utils.py
def get_max_velocities(
    self,
    indices: Optional[Union[np.ndarray, List, torch.Tensor, wp.array]] = None,
    joint_indices: Optional[Union[np.ndarray, List, torch.Tensor, wp.array]] = None,
    clone: bool = True,
) -> Union[np.ndarray, torch.Tensor, wp.indexedarray]:
    """Gets maximum velocities for articulation in the view.

    Args:
        indices (Optional[Union[np.ndarray, List, torch.Tensor, wp.array]], optional): indicies to specify which prims
                                                                             to query. Shape (M,).
                                                                             Where M <= size of the encapsulated prims in the view.
                                                                             Defaults to None (i.e: all prims in the view).
        joint_indices (Optional[Union[np.ndarray, List, torch.Tensor, wp.array]], optional): joint indicies to specify which joints
                                                                             to query. Shape (K,).
                                                                             Where K <= num of dofs.
                                                                             Defaults to None (i.e: all dofs).
        clone (Optional[bool]): True to return a clone of the internal buffer. Otherwise False. Defaults to True.

    Returns:
        Union[np.ndarray, torch.Tensor, wp.indexedarray]: maximum velocities for articulations in the view. shape (M, K).
    """
    if not self._is_initialized:
        carb.log_warn("ArticulationView needs to be initialized.")
        return None
    if not omni.timeline.get_timeline_interface().is_stopped() and self._physics_view is not None:
        indices = self._backend_utils.resolve_indices(indices, self.count, "cpu")
        joint_indices = self._backend_utils.resolve_indices(joint_indices, self.num_dof, "cpu")
        max_velocities = self._physics_view.get_dof_max_velocities()
        if clone:
            max_velocities = self._backend_utils.clone_tensor(max_velocities, device="cpu")
        result = self._backend_utils.move_data(
            max_velocities[
                self._backend_utils.expand_dims(indices, 1) if self._backend != "warp" else indices, joint_indices
            ],
            device=self._device,
        )
        return result
    else:
        indices = self._backend_utils.resolve_indices(indices, self.count, self._device)
        joint_indices = self._backend_utils.resolve_indices(joint_indices, self.num_dof, self._device)
        max_velocities = np.zeros(shape=(indices.shape[0], joint_indices.shape[0]), dtype="float32")
        indices = self._backend_utils.to_list(indices)
        joint_indices = self._backend_utils.to_list(joint_indices)
        articulation_write_idx = 0
        for i in indices:
            dof_write_idx = 0
            for dof_index in joint_indices:
                prim = PhysxSchema.PhysxJointAPI(get_prim_at_path(self._dof_paths[i][dof_index]))
                max_velocities[articulation_write_idx][dof_write_idx] = prim.GetMaxJointVelocityAttr().Get()
                dof_write_idx += 1
            articulation_write_idx += 1
        max_velocities = self._backend_utils.convert(
            max_velocities, dtype="float32", device=self._device, indexed=True
        )
        return max_velocities

set_joint_efforts(efforts, indices=None, joint_indices=None)

Set the joint efforts of articulations in the view

.. note::

This method can be used for effort control. For this purpose, there must be no joint drive
or the stiffness and damping must be set to zero.

Parameters:

Name Type Description Default
efforts Optional[Union[ndarray, Tensor, array]]

efforts of articulations in the view to be set to in the next frame. shape is (M, K).

required
indices Optional[Union[ndarray, List, Tensor, array]]

indices to specify which prims to manipulate. Shape (M,). Where M <= size of the encapsulated prims in the view. Defaults to None (i.e: all prims in the view).

None
joint_indices Optional[Union[ndarray, List, Tensor, array]]

joint indices to specify which joints to manipulate. Shape (K,). Where K <= num of dofs. Defaults to None (i.e: all dofs).

None

.. hint::

This method belongs to the methods used to set the articulation kinematic states:

``set_velocities`` (``set_linear_velocities``, ``set_angular_velocities``),
``set_joint_positions``, ``set_joint_velocities``, ``set_joint_efforts``

Example:

.. code-block:: python

>>> # set the efforts for all the articulation joints to the indicated values.
>>> # Since there are 5 envs, the joint efforts are repeated 5 times
>>> efforts = np.tile(np.array([10, 20, 30, 40, 50, 60, 70, 80, 90]), (num_envs, 1))
>>> prims.set_joint_efforts(efforts)
>>>
>>> # set the fingers efforts: panda_finger_joint1 (7) and panda_finger_joint2 (8) to 10
>>> # for the first, middle and last of the 5 envs
>>> efforts = np.tile(np.array([10, 10]), (3, 1))
>>> prims.set_joint_efforts(efforts, indices=np.array([0, 2, 4]), joint_indices=np.array([7, 8]))
Source code in OmniGibson/omnigibson/utils/deprecated_utils.py
def set_joint_efforts(
    self,
    efforts: Optional[Union[np.ndarray, torch.Tensor, wp.array]],
    indices: Optional[Union[np.ndarray, List, torch.Tensor, wp.array]] = None,
    joint_indices: Optional[Union[np.ndarray, List, torch.Tensor, wp.array]] = None,
) -> None:
    """Set the joint efforts of articulations in the view

    .. note::

        This method can be used for effort control. For this purpose, there must be no joint drive
        or the stiffness and damping must be set to zero.

    Args:
        efforts (Optional[Union[np.ndarray, torch.Tensor, wp.array]]): efforts of articulations in the view to be set to in the next frame.
                                                                shape is (M, K).
        indices (Optional[Union[np.ndarray, List, torch.Tensor, wp.array]], optional): indices to specify which prims
                                                                             to manipulate. Shape (M,).
                                                                             Where M <= size of the encapsulated prims in the view.
                                                                             Defaults to None (i.e: all prims in the view).
        joint_indices (Optional[Union[np.ndarray, List, torch.Tensor, wp.array]], optional): joint indices to specify which joints
                                                                             to manipulate. Shape (K,).
                                                                             Where K <= num of dofs.
                                                                             Defaults to None (i.e: all dofs).

    .. hint::

        This method belongs to the methods used to set the articulation kinematic states:

        ``set_velocities`` (``set_linear_velocities``, ``set_angular_velocities``),
        ``set_joint_positions``, ``set_joint_velocities``, ``set_joint_efforts``

    Example:

    .. code-block:: python

        >>> # set the efforts for all the articulation joints to the indicated values.
        >>> # Since there are 5 envs, the joint efforts are repeated 5 times
        >>> efforts = np.tile(np.array([10, 20, 30, 40, 50, 60, 70, 80, 90]), (num_envs, 1))
        >>> prims.set_joint_efforts(efforts)
        >>>
        >>> # set the fingers efforts: panda_finger_joint1 (7) and panda_finger_joint2 (8) to 10
        >>> # for the first, middle and last of the 5 envs
        >>> efforts = np.tile(np.array([10, 10]), (3, 1))
        >>> prims.set_joint_efforts(efforts, indices=np.array([0, 2, 4]), joint_indices=np.array([7, 8]))
    """
    if not self._is_initialized:
        carb.log_warn("ArticulationView needs to be initialized.")
        return

    if not omni.timeline.get_timeline_interface().is_stopped() and self._physics_view is not None:
        indices = self._backend_utils.resolve_indices(indices, self.count, self._device)
        joint_indices = self._backend_utils.resolve_indices(joint_indices, self.num_dof, self._device)

        # THIS IS THE FIX: COMMENT OUT THE BELOW LINE AND USE ACTUATION FORCES INSTEAD
        # new_dof_efforts = self._backend_utils.create_zeros_tensor(
        #     shape=[self.count, self.num_dof], dtype="float32", device=self._device
        # )
        new_dof_efforts = self._physics_view.get_dof_actuation_forces()
        new_dof_efforts = self._backend_utils.assign(
            self._backend_utils.move_data(efforts, device=self._device),
            new_dof_efforts,
            [self._backend_utils.expand_dims(indices, 1) if self._backend != "warp" else indices, joint_indices],
        )
        self._physics_view.set_dof_actuation_forces(new_dof_efforts, indices)
    else:
        carb.log_warn("Physics Simulation View is not created yet in order to use set_joint_efforts")
    return

set_joint_limits(values, indices=None, joint_indices=None)

Sets joint limits for articulation joints in the view.

Parameters:

Name Type Description Default
values Union[ndarray, Tensor, array]

joint limits for articulations in the view. shape (M, K, 2).

required
indices Optional[Union[ndarray, List, Tensor, array]]

indicies to specify which prims to manipulate. Shape (M,). Where M <= size of the encapsulated prims in the view. Defaults to None (i.e: all prims in the view).

None
joint_indices Optional[Union[ndarray, List, Tensor, array]]

joint indicies to specify which joints to manipulate. Shape (K,). Where K <= num of dofs. Defaults to None (i.e: all dofs).

None
Source code in OmniGibson/omnigibson/utils/deprecated_utils.py
def set_joint_limits(
    self,
    values: Union[np.ndarray, torch.Tensor],
    indices: Optional[Union[np.ndarray, List, torch.Tensor, wp.array]] = None,
    joint_indices: Optional[Union[np.ndarray, List, torch.Tensor, wp.array]] = None,
) -> None:
    """Sets joint limits for articulation joints in the view.

    Args:
        values (Union[np.ndarray, torch.Tensor, wp.array]): joint limits for articulations in the view. shape (M, K, 2).
        indices (Optional[Union[np.ndarray, List, torch.Tensor, wp.array]], optional): indicies to specify which prims
                                                                             to manipulate. Shape (M,).
                                                                             Where M <= size of the encapsulated prims in the view.
                                                                             Defaults to None (i.e: all prims in the view).
        joint_indices (Optional[Union[np.ndarray, List, torch.Tensor, wp.array]], optional): joint indicies to specify which joints
                                                                             to manipulate. Shape (K,).
                                                                             Where K <= num of dofs.
                                                                             Defaults to None (i.e: all dofs).
    """
    if not self._is_initialized:
        carb.log_warn("ArticulationView needs to be initialized.")
        return
    if not omni.timeline.get_timeline_interface().is_stopped() and self._physics_view is not None:
        indices = self._backend_utils.resolve_indices(indices, self.count, "cpu")
        joint_indices = self._backend_utils.resolve_indices(joint_indices, self.num_dof, "cpu")
        new_values = self._physics_view.get_dof_limits()
        values = self._backend_utils.move_data(values, device="cpu")
        new_values = self._backend_utils.assign(
            values,
            new_values,
            [self._backend_utils.expand_dims(indices, 1) if self._backend != "warp" else indices, joint_indices],
        )
        self._physics_view.set_dof_limits(new_values, indices)
    else:
        indices = self._backend_utils.to_list(
            self._backend_utils.resolve_indices(indices, self.count, self._device)
        )
        dof_types = self._backend_utils.to_list(self.get_dof_types())
        joint_indices = self._backend_utils.to_list(
            self._backend_utils.resolve_indices(joint_indices, self.num_dof, self._device)
        )
        values = self._backend_utils.to_list(values)
        articulation_read_idx = 0
        for i in indices:
            dof_read_idx = 0
            for dof_index in joint_indices:
                dof_val = values[articulation_read_idx][dof_read_idx]
                if dof_types[dof_index] == omni.physics.tensors.DofType.Rotation:
                    dof_val /= DEG2RAD
                prim = get_prim_at_path(self._dof_paths[i][dof_index])
                prim.GetAttribute("physics:lowerLimit").Set(dof_val[0])
                prim.GetAttribute("physics:upperLimit").Set(dof_val[1])
                dof_read_idx += 1
            articulation_read_idx += 1
    return

set_joint_positions(positions, indices=None, joint_indices=None)

Set the joint positions of articulations in the view

.. warning::

This method will immediately set (teleport) the affected joints to the indicated value.
Use the ``set_joint_position_targets`` or the ``apply_action`` methods to control the articulation joints.

Parameters:

Name Type Description Default
positions Optional[Union[ndarray, Tensor, array]]

joint positions of articulations in the view to be set to in the next frame. shape is (M, K).

required
indices Optional[Union[ndarray, List, Tensor, array]]

indices to specify which prims to manipulate. Shape (M,). Where M <= size of the encapsulated prims in the view. Defaults to None (i.e: all prims in the view).

None
joint_indices Optional[Union[ndarray, List, Tensor, array]]

joint indices to specify which joints to manipulate. Shape (K,). Where K <= num of dofs. Defaults to None (i.e: all dofs).

None

.. hint::

This method belongs to the methods used to set the articulation kinematic states:

``set_velocities`` (``set_linear_velocities``, ``set_angular_velocities``),
``set_joint_positions``, ``set_joint_velocities``, ``set_joint_efforts``

Example:

.. code-block:: python

>>> # set all the articulation joints.
>>> # Since there are 5 envs, the joint positions are repeated 5 times
>>> positions = np.tile(np.array([0.0, -1.0, 0.0, -2.2, 0.0, 2.4, 0.8, 0.04, 0.04]), (num_envs, 1))
>>> prims.set_joint_positions(positions)
>>>
>>> # set only the fingers in closed position: panda_finger_joint1 (7) and panda_finger_joint2 (8) to 0.0
>>> # for the first, middle and last of the 5 envs
>>> positions = np.tile(np.array([0.0, 0.0]), (3, 1))
>>> prims.set_joint_positions(positions, indices=np.array([0, 2, 4]), joint_indices=np.array([7, 8]))
Source code in OmniGibson/omnigibson/utils/deprecated_utils.py
def set_joint_positions(
    self,
    positions: Optional[Union[np.ndarray, torch.Tensor, wp.array]],
    indices: Optional[Union[np.ndarray, List, torch.Tensor, wp.array]] = None,
    joint_indices: Optional[Union[np.ndarray, List, torch.Tensor, wp.array]] = None,
) -> None:
    """Set the joint positions of articulations in the view

    .. warning::

        This method will immediately set (teleport) the affected joints to the indicated value.
        Use the ``set_joint_position_targets`` or the ``apply_action`` methods to control the articulation joints.

    Args:
        positions (Optional[Union[np.ndarray, torch.Tensor, wp.array]]): joint positions of articulations in the view to be set to in the next frame.
                                                                shape is (M, K).
        indices (Optional[Union[np.ndarray, List, torch.Tensor, wp.array]], optional): indices to specify which prims
                                                                             to manipulate. Shape (M,).
                                                                             Where M <= size of the encapsulated prims in the view.
                                                                             Defaults to None (i.e: all prims in the view).
        joint_indices (Optional[Union[np.ndarray, List, torch.Tensor, wp.array]], optional): joint indices to specify which joints
                                                                             to manipulate. Shape (K,).
                                                                             Where K <= num of dofs.
                                                                             Defaults to None (i.e: all dofs).

    .. hint::

        This method belongs to the methods used to set the articulation kinematic states:

        ``set_velocities`` (``set_linear_velocities``, ``set_angular_velocities``),
        ``set_joint_positions``, ``set_joint_velocities``, ``set_joint_efforts``

    Example:

    .. code-block:: python

        >>> # set all the articulation joints.
        >>> # Since there are 5 envs, the joint positions are repeated 5 times
        >>> positions = np.tile(np.array([0.0, -1.0, 0.0, -2.2, 0.0, 2.4, 0.8, 0.04, 0.04]), (num_envs, 1))
        >>> prims.set_joint_positions(positions)
        >>>
        >>> # set only the fingers in closed position: panda_finger_joint1 (7) and panda_finger_joint2 (8) to 0.0
        >>> # for the first, middle and last of the 5 envs
        >>> positions = np.tile(np.array([0.0, 0.0]), (3, 1))
        >>> prims.set_joint_positions(positions, indices=np.array([0, 2, 4]), joint_indices=np.array([7, 8]))
    """
    if not self._is_initialized:
        carb.log_warn("ArticulationView needs to be initialized.")
        return
    if not omni.timeline.get_timeline_interface().is_stopped() and self._physics_view is not None:
        indices = self._backend_utils.resolve_indices(indices, self.count, self._device)
        joint_indices = self._backend_utils.resolve_indices(joint_indices, self.num_dof, self._device)
        new_dof_pos = self._physics_view.get_dof_positions()
        new_dof_pos = self._backend_utils.assign(
            self._backend_utils.move_data(positions, device=self._device),
            new_dof_pos,
            [self._backend_utils.expand_dims(indices, 1) if self._backend != "warp" else indices, joint_indices],
        )
        self._physics_view.set_dof_positions(new_dof_pos, indices)

        # THIS IS THE FIX:
        #   FIX V1: COMMENT OUT THE BELOW LINE AND SET TARGETS INSTEAD
        #   FIX V2: DECOUPLE INSTANTANEOUS POSITION FROM TARGETS
        # self._physics_view.set_dof_position_targets(new_dof_pos, indices)
        # self.set_joint_position_targets(positions, indices, joint_indices)
    else:
        carb.log_warn("Physics Simulation View is not created yet in order to use set_joint_positions")

set_joint_velocities(velocities, indices=None, joint_indices=None)

Set the joint velocities of articulations in the view

.. warning::

This method will immediately set the affected joints to the indicated value.
Use the ``set_joint_velocity_targets`` or the ``apply_action`` methods to control the articulation joints.

Parameters:

Name Type Description Default
velocities Optional[Union[ndarray, Tensor, array]]

joint velocities of articulations in the view to be set to in the next frame. shape is (M, K).

required
indices Optional[Union[ndarray, List, Tensor, array]]

indices to specify which prims to manipulate. Shape (M,). Where M <= size of the encapsulated prims in the view. Defaults to None (i.e: all prims in the view).

None
joint_indices Optional[Union[ndarray, List, Tensor, array]]

joint indices to specify which joints to manipulate. Shape (K,). Where K <= num of dofs. Defaults to None (i.e: all dofs).

None

.. hint::

This method belongs to the methods used to set the articulation kinematic states:

``set_velocities`` (``set_linear_velocities``, ``set_angular_velocities``),
``set_joint_positions``, ``set_joint_velocities``, ``set_joint_efforts``

Example:

.. code-block:: python

>>> # set the velocities for all the articulation joints to the indicated values.
>>> # Since there are 5 envs, the joint velocities are repeated 5 times
>>> velocities = np.tile(np.array([0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9]), (num_envs, 1))
>>> prims.set_joint_velocities(velocities)
>>>
>>> # set the fingers velocities: panda_finger_joint1 (7) and panda_finger_joint2 (8) to -0.1
>>> # for the first, middle and last of the 5 envs
>>> velocities = np.tile(np.array([-0.1, -0.1]), (3, 1))
>>> prims.set_joint_velocities(velocities, indices=np.array([0, 2, 4]), joint_indices=np.array([7, 8]))
Source code in OmniGibson/omnigibson/utils/deprecated_utils.py
def set_joint_velocities(
    self,
    velocities: Optional[Union[np.ndarray, torch.Tensor, wp.array]],
    indices: Optional[Union[np.ndarray, List, torch.Tensor, wp.array]] = None,
    joint_indices: Optional[Union[np.ndarray, List, torch.Tensor, wp.array]] = None,
) -> None:
    """Set the joint velocities of articulations in the view

    .. warning::

        This method will immediately set the affected joints to the indicated value.
        Use the ``set_joint_velocity_targets`` or the ``apply_action`` methods to control the articulation joints.

    Args:
        velocities (Optional[Union[np.ndarray, torch.Tensor, wp.array]]): joint velocities of articulations in the view to be set to in the next frame.
                                                                shape is (M, K).
        indices (Optional[Union[np.ndarray, List, torch.Tensor, wp.array]], optional): indices to specify which prims
                                                                             to manipulate. Shape (M,).
                                                                             Where M <= size of the encapsulated prims in the view.
                                                                             Defaults to None (i.e: all prims in the view).
        joint_indices (Optional[Union[np.ndarray, List, torch.Tensor, wp.array]], optional): joint indices to specify which joints
                                                                             to manipulate. Shape (K,).
                                                                             Where K <= num of dofs.
                                                                             Defaults to None (i.e: all dofs).

    .. hint::

        This method belongs to the methods used to set the articulation kinematic states:

        ``set_velocities`` (``set_linear_velocities``, ``set_angular_velocities``),
        ``set_joint_positions``, ``set_joint_velocities``, ``set_joint_efforts``

    Example:

    .. code-block:: python

        >>> # set the velocities for all the articulation joints to the indicated values.
        >>> # Since there are 5 envs, the joint velocities are repeated 5 times
        >>> velocities = np.tile(np.array([0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9]), (num_envs, 1))
        >>> prims.set_joint_velocities(velocities)
        >>>
        >>> # set the fingers velocities: panda_finger_joint1 (7) and panda_finger_joint2 (8) to -0.1
        >>> # for the first, middle and last of the 5 envs
        >>> velocities = np.tile(np.array([-0.1, -0.1]), (3, 1))
        >>> prims.set_joint_velocities(velocities, indices=np.array([0, 2, 4]), joint_indices=np.array([7, 8]))
    """
    if not self._is_initialized:
        carb.log_warn("ArticulationView needs to be initialized.")
        return
    if not omni.timeline.get_timeline_interface().is_stopped() and self._physics_view is not None:
        indices = self._backend_utils.resolve_indices(indices, self.count, self._device)
        joint_indices = self._backend_utils.resolve_indices(joint_indices, self.num_dof, self._device)
        new_dof_vel = self._physics_view.get_dof_velocities()
        new_dof_vel = self._backend_utils.assign(
            self._backend_utils.move_data(velocities, device=self._device),
            new_dof_vel,
            [self._backend_utils.expand_dims(indices, 1) if self._backend != "warp" else indices, joint_indices],
        )
        self._physics_view.set_dof_velocities(new_dof_vel, indices)

        # THIS IS THE FIX:
        #   FIX V1: COMMENT OUT THE BELOW LINE AND SET TARGETS INSTEAD
        #   FIX V2: DECOUPLE INSTANTANEOUS VELOCITY FROM TARGETS
        # self._physics_view.set_dof_velocity_targets(new_dof_vel, indices)
        # self.set_joint_velocity_targets(velocities, indices, joint_indices)
    else:
        carb.log_warn("Physics Simulation View is not created yet in order to use set_joint_velocities")
    return

set_max_velocities(values, indices=None, joint_indices=None)

Sets maximum velocities for articulation in the view.

Parameters:

Name Type Description Default
values Union[ndarray, Tensor, array]

maximum velocities for articulations in the view. shape (M, K).

required
indices Optional[Union[ndarray, List, Tensor, array]]

indicies to specify which prims to manipulate. Shape (M,). Where M <= size of the encapsulated prims in the view. Defaults to None (i.e: all prims in the view).

None
joint_indices Optional[Union[ndarray, List, Tensor, array]]

joint indicies to specify which joints to manipulate. Shape (K,). Where K <= num of dofs. Defaults to None (i.e: all dofs).

None
Source code in OmniGibson/omnigibson/utils/deprecated_utils.py
def set_max_velocities(
    self,
    values: Union[np.ndarray, torch.Tensor, wp.array],
    indices: Optional[Union[np.ndarray, List, torch.Tensor, wp.array]] = None,
    joint_indices: Optional[Union[np.ndarray, List, torch.Tensor, wp.array]] = None,
) -> None:
    """Sets maximum velocities for articulation in the view.

    Args:
        values (Union[np.ndarray, torch.Tensor, wp.array]): maximum velocities for articulations in the view. shape (M, K).
        indices (Optional[Union[np.ndarray, List, torch.Tensor, wp.array]], optional): indicies to specify which prims
                                                                             to manipulate. Shape (M,).
                                                                             Where M <= size of the encapsulated prims in the view.
                                                                             Defaults to None (i.e: all prims in the view).
        joint_indices (Optional[Union[np.ndarray, List, torch.Tensor, wp.array]], optional): joint indicies to specify which joints
                                                                             to manipulate. Shape (K,).
                                                                             Where K <= num of dofs.
                                                                             Defaults to None (i.e: all dofs).
    """
    if not self._is_initialized:
        carb.log_warn("ArticulationView needs to be initialized.")
        return
    if not omni.timeline.get_timeline_interface().is_stopped() and self._physics_view is not None:
        indices = self._backend_utils.resolve_indices(indices, self.count, "cpu")
        joint_indices = self._backend_utils.resolve_indices(joint_indices, self.num_dof, "cpu")
        new_values = self._physics_view.get_dof_max_velocities()
        new_values = self._backend_utils.assign(
            self._backend_utils.move_data(values, device="cpu"),
            new_values,
            [self._backend_utils.expand_dims(indices, 1) if self._backend != "warp" else indices, joint_indices],
        )
        self._physics_view.set_dof_max_velocities(new_values, indices)
    else:
        indices = self._backend_utils.resolve_indices(indices, self.count, self._device)
        joint_indices = self._backend_utils.resolve_indices(joint_indices, self.num_dof, self._device)
        articulation_read_idx = 0
        indices = self._backend_utils.to_list(indices)
        joint_indices = self._backend_utils.to_list(joint_indices)
        values = self._backend_utils.to_list(values)
        for i in indices:
            dof_read_idx = 0
            for dof_index in joint_indices:
                prim = PhysxSchema.PhysxJointAPI(get_prim_at_path(self._dof_paths[i][dof_index]))
                if not prim.GetMaxJointVelocityAttr():
                    prim.CreateMaxJointVelocityAttr().Set(values[articulation_read_idx][dof_read_idx])
                else:
                    prim.GetMaxJointVelocityAttr().Set(values[articulation_read_idx][dof_read_idx])
                dof_read_idx += 1
            articulation_read_idx += 1
    return

CreateMeshPrimWithDefaultXformCommand

Bases: CreateMeshPrimWithDefaultXformCommand

Source code in OmniGibson/omnigibson/utils/deprecated_utils.py
class CreateMeshPrimWithDefaultXformCommand(CMPWDXC):
    def __init__(self, prim_type: str, **kwargs):
        """
        Creates primitive.

        Args:
            prim_type (str): It supports Plane/Sphere/Cone/Cylinder/Disk/Torus/Cube.

        kwargs:
            object_origin (Gf.Vec3f): Position of mesh center in stage units.

            u_patches (int): The number of patches to tessellate U direction.

            v_patches (int): The number of patches to tessellate V direction.

            w_patches (int): The number of patches to tessellate W direction.
                             It only works for Cone/Cylinder/Cube.

            half_scale (float): Half size of mesh in centimeters. Default is None, which means it's controlled by settings.

            u_verts_scale (int): Tessellation Level of U. It's a multiplier of u_patches.

            v_verts_scale (int): Tessellation Level of V. It's a multiplier of v_patches.

            w_verts_scale (int): Tessellation Level of W. It's a multiplier of w_patches.
                                 It only works for Cone/Cylinder/Cube.
                                 For Cone/Cylinder, it's to tessellate the caps.
                                 For Cube, it's to tessellate along z-axis.

            above_ground (bool): It will offset the center of mesh above the ground plane if it's True,
                False otherwise. It's False by default. This param only works when param object_origin is not given.
                Otherwise, it will be ignored.

            stage (Usd.Stage): If specified, stage to create prim on
        """

        self._prim_type = prim_type[0:1].upper() + prim_type[1:].lower()
        self._usd_context = omni.usd.get_context()
        self._selection = self._usd_context.get_selection()
        self._stage = kwargs.get("stage", self._usd_context.get_stage())
        self._settings = carb.settings.get_settings()
        self._default_path = kwargs.get("prim_path", None)
        self._select_new_prim = kwargs.get("select_new_prim", True)
        self._prepend_default_prim = kwargs.get("prepend_default_prim", True)
        self._above_round = kwargs.get("above_ground", False)

        self._attributes = {**kwargs}
        # Supported mesh types should have an associated evaluator class
        self._evaluator_class = _get_all_evaluators()[prim_type]
        assert isinstance(self._evaluator_class, type)

__init__(prim_type, **kwargs)

Creates primitive.

Parameters:

Name Type Description Default
prim_type str

It supports Plane/Sphere/Cone/Cylinder/Disk/Torus/Cube.

required
kwargs

object_origin (Gf.Vec3f): Position of mesh center in stage units.

u_patches (int): The number of patches to tessellate U direction.

v_patches (int): The number of patches to tessellate V direction.

w_patches (int): The number of patches to tessellate W direction. It only works for Cone/Cylinder/Cube.

half_scale (float): Half size of mesh in centimeters. Default is None, which means it's controlled by settings.

u_verts_scale (int): Tessellation Level of U. It's a multiplier of u_patches.

v_verts_scale (int): Tessellation Level of V. It's a multiplier of v_patches.

w_verts_scale (int): Tessellation Level of W. It's a multiplier of w_patches. It only works for Cone/Cylinder/Cube. For Cone/Cylinder, it's to tessellate the caps. For Cube, it's to tessellate along z-axis.

above_ground (bool): It will offset the center of mesh above the ground plane if it's True, False otherwise. It's False by default. This param only works when param object_origin is not given. Otherwise, it will be ignored.

stage (Usd.Stage): If specified, stage to create prim on

Source code in OmniGibson/omnigibson/utils/deprecated_utils.py
def __init__(self, prim_type: str, **kwargs):
    """
    Creates primitive.

    Args:
        prim_type (str): It supports Plane/Sphere/Cone/Cylinder/Disk/Torus/Cube.

    kwargs:
        object_origin (Gf.Vec3f): Position of mesh center in stage units.

        u_patches (int): The number of patches to tessellate U direction.

        v_patches (int): The number of patches to tessellate V direction.

        w_patches (int): The number of patches to tessellate W direction.
                         It only works for Cone/Cylinder/Cube.

        half_scale (float): Half size of mesh in centimeters. Default is None, which means it's controlled by settings.

        u_verts_scale (int): Tessellation Level of U. It's a multiplier of u_patches.

        v_verts_scale (int): Tessellation Level of V. It's a multiplier of v_patches.

        w_verts_scale (int): Tessellation Level of W. It's a multiplier of w_patches.
                             It only works for Cone/Cylinder/Cube.
                             For Cone/Cylinder, it's to tessellate the caps.
                             For Cube, it's to tessellate along z-axis.

        above_ground (bool): It will offset the center of mesh above the ground plane if it's True,
            False otherwise. It's False by default. This param only works when param object_origin is not given.
            Otherwise, it will be ignored.

        stage (Usd.Stage): If specified, stage to create prim on
    """

    self._prim_type = prim_type[0:1].upper() + prim_type[1:].lower()
    self._usd_context = omni.usd.get_context()
    self._selection = self._usd_context.get_selection()
    self._stage = kwargs.get("stage", self._usd_context.get_stage())
    self._settings = carb.settings.get_settings()
    self._default_path = kwargs.get("prim_path", None)
    self._select_new_prim = kwargs.get("select_new_prim", True)
    self._prepend_default_prim = kwargs.get("prepend_default_prim", True)
    self._above_round = kwargs.get("above_ground", False)

    self._attributes = {**kwargs}
    # Supported mesh types should have an associated evaluator class
    self._evaluator_class = _get_all_evaluators()[prim_type]
    assert isinstance(self._evaluator_class, type)

RigidPrimView

Bases: RigidPrim

Source code in OmniGibson/omnigibson/utils/deprecated_utils.py
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
class RigidPrimView(_RigidPrimView):
    def get_linear_velocities(
        self, indices: Optional[Union[np.ndarray, list, torch.Tensor, wp.array]] = None, clone: bool = True
    ) -> Union[np.ndarray, torch.Tensor, wp.indexedarray]:
        """Get the linear velocities of prims in the view.

        Args:
            indices (Optional[Union[np.ndarray, list, torch.Tensor, wp.array]], optional): indices to specify which prims
                                                                                    to query. Shape (M,).
                                                                                    Where M <= size of the encapsulated prims in the view.
                                                                                    Defaults to None (i.e: all prims in the view)
            clone (bool, optional): True to return a clone of the internal buffer. Otherwise False. Defaults to True.

        Returns:
            Union[np.ndarray, torch.Tensor, wp.indexedarray]: linear velocities of the prims in the view. shape is (M, 3).

        Example:

        .. code-block:: python

            >>> # get all rigid prim linear velocities. Returned shape is (5, 3) for the example: 5 envs, linear (3)
            >>> prims.get_linear_velocities()
            [[0. 0. 0.]
             [0. 0. 0.]
             [0. 0. 0.]
             [0. 0. 0.]
             [0. 0. 0.]]
            >>>
            >>> # get only the rigid prim linear velocities for the first, middle and last of the 5 envs.
            >>> # Returned shape is (3, 3) for the example: 3 envs selected, linear (3)
            >>> prims.get_linear_velocities(indices=np.array([0, 2, 4]))
            [[0. 0. 0.]
             [0. 0. 0.]
             [0. 0. 0.]]
        """
        if not self._is_valid:
            raise Exception("prim view {} is not a valid view".format(self._regex_prim_paths))
        indices = self._backend_utils.resolve_indices(indices, self.count, self._device)

        if self.is_physics_handle_valid():
            linear_velocities = self._physics_view.get_velocities()
            if clone:
                # THIS LINE WAS NAMED INCORRECTLY!!!
                linear_velocities = self._backend_utils.clone_tensor(linear_velocities, device=self._device)
            return linear_velocities[indices, 0:3]
        else:
            linear_velocities = np.zeros(shape=(indices.shape[0], 3), dtype=np.float32)
            write_idx = 0
            indices = self._backend_utils.to_list(indices)
            for i in indices:
                if self._rigid_body_apis[i] is None:
                    if self._prims[i].HasAPI(UsdPhysics.RigidBodyAPI):
                        rigid_api = UsdPhysics.RigidBodyAPI(self._prims[i])
                    else:
                        rigid_api = UsdPhysics.RigidBodyAPI.Apply(self._prims[i])
                    self._rigid_body_apis[i] = rigid_api
                linear_velocities[write_idx] = np.array(
                    self._rigid_body_apis[i].GetVelocityAttr().Get(), dtype=np.float32
                )
                write_idx += 1
            linear_velocities = self._backend_utils.convert(
                linear_velocities, dtype="float32", device=self._device, indexed=True
            )
            return linear_velocities

    def get_angular_velocities(
        self, indices: Optional[Union[np.ndarray, list, torch.Tensor, wp.array]] = None, clone: bool = True
    ) -> Union[np.ndarray, torch.Tensor, wp.indexedarray]:
        """Get the angular velocities of prims in the view.

        Args:
            indices (Optional[Union[np.ndarray, list, torch.Tensor, wp.array]], optional): indices to specify which prims
                                                                                    to query. Shape (M,).
                                                                                    Where M <= size of the encapsulated prims in the view.
                                                                                    Defaults to None (i.e: all prims in the view)
            clone (bool, optional): True to return a clone of the internal buffer. Otherwise False. Defaults to True.

        Returns:
            Union[np.ndarray, torch.Tensor, wp.indexedarray]: angular velocities of the prims in the view. shape is (M, 3).

        Example:

        .. code-block:: python

            >>> # get all rigid prim angular velocities. Returned shape is (5, 3) for the example: 5 envs, angular (3)
            >>> prims.get_angular_velocities()
            [[0. 0. 0.]
             [0. 0. 0.]
             [0. 0. 0.]
             [0. 0. 0.]
             [0. 0. 0.]]
            >>>
            >>> # get only the rigid prim angular velocities for the first, middle and last of the 5 envs
            >>> # Returned shape is (5, 3) for the example: 3 envs selected, angular (3)
            >>> prims.get_angular_velocities(indices=np.array([0, 2, 4]))
            [[0. 0. 0.]
             [0. 0. 0.]
             [0. 0. 0.]]
        """
        if not self._is_valid:
            raise Exception("prim view {} is not a valid view".format(self._regex_prim_paths))
        indices = self._backend_utils.resolve_indices(indices, self.count, self._device)
        if self.is_physics_handle_valid():
            angular_velocities = self._physics_view.get_velocities()
            if clone:
                # THIS LINE WAS NAMED INCORRECTLY!!
                angular_velocities = self._backend_utils.clone_tensor(angular_velocities, device=self._device)
            return angular_velocities[indices, 3:6]
        else:
            angular_velocities = np.zeros(shape=(indices.shape[0], 3), dtype=np.float32)
            write_idx = 0
            indices = self._backend_utils.to_list(indices)
            for i in indices:
                if self._rigid_body_apis[i] is None:
                    if self._prims[i].HasAPI(UsdPhysics.RigidBodyAPI):
                        rigid_api = UsdPhysics.RigidBodyAPI(self._prims[i])
                    else:
                        rigid_api = UsdPhysics.RigidBodyAPI.Apply(self._prims[i])
                    self._rigid_body_apis[i] = rigid_api
                angular_velocities[write_idx] = np.array(
                    self._rigid_body_apis[i].GetAngularVelocityAttr().Get(), dtype="float32"
                )
                write_idx += 1
            angular_velocities = self._backend_utils.convert(
                angular_velocities, dtype="float32", device=self._device, indexed=True
            )
            return angular_velocities

    def get_world_poses(
        self,
        indices: Optional[Union[np.ndarray, list, torch.Tensor, wp.array]] = None,
        clone: bool = True,
        usd: bool = True,
    ) -> Union[
        Tuple[np.ndarray, np.ndarray], Tuple[torch.Tensor, torch.Tensor], Tuple[wp.indexedarray, wp.indexedarray]
    ]:
        """Get the poses of the prims in the view with respect to the world's frame.

        Args:
            indices (Optional[Union[np.ndarray, list, torch.Tensor, wp.array]], optional): indices to specify which prims
                                                                                 to query. Shape (M,).
                                                                                 Where M <= size of the encapsulated prims in the view.
                                                                                 Defaults to None (i.e: all prims in the view).
            clone (bool, optional): True to return a clone of the internal buffer. Otherwise False. Defaults to True.
            usd (bool, optional): True to query from usd. Otherwise False to query from Fabric data. Defaults to True.

        Returns:
            Union[Tuple[np.ndarray, np.ndarray], Tuple[torch.Tensor, torch.Tensor], Tuple[wp.indexedarray, wp.indexedarray]]:
            first index is positions in the world frame of the prims. shape is (M, 3).
            second index is quaternion orientations in the world frame of the prims.
            quaternion is scalar-first (w, x, y, z). shape is (M, 4).

        Example:

        .. code-block:: python

            >>> # get all rigid prim poses with respect to the world's frame.
            >>> # Returned shape is position (5, 3) and orientation (5, 4) for the example: 5 envs
            >>> positions, orientations = prims.get_world_poses()
            >>> positions
            [[ 1.4999989e+00 -7.4999851e-01 -1.5118626e-07]
             [ 1.4999989e+00  7.5000149e-01 -2.5988294e-07]
             [-1.0017333e-06 -7.4999845e-01  7.6070329e-08]
             [-9.5906785e-07  7.5000149e-01  1.0593490e-07]
             [-1.5000011e+00 -7.4999851e-01  1.9655154e-07]]
            >>> orientations
            [[ 9.9999994e-01 -8.8168377e-07 -4.1946004e-07 -1.5067183e-08]
             [ 9.9999994e-01 -8.8691013e-07 -4.2665880e-07 -2.7188951e-09]
             [ 1.0000000e+00 -9.5171310e-07 -2.2615541e-07  5.5922797e-08]
             [ 1.0000000e+00 -8.9923367e-07 -1.4408238e-07  1.3476099e-08]
             [ 1.0000000e+00 -7.9806580e-07 -1.3064776e-07  5.3154917e-08]]
            >>>
            >>> # get only the rigid prim poses with respect to the world's frame for the first, middle and last of the 5 envs.
            >>> # Returned shape is position (3, 3) and orientation (3, 4) for the example: 3 envs selected
            >>> positions, orientations = prims.get_world_poses(indices=np.array([0, 2, 4]))
            >>> positions
            [[ 1.4999989e+00 -7.4999851e-01 -1.5118626e-07]
             [-1.0017333e-06 -7.4999845e-01  7.6070329e-08]
             [-1.5000011e+00 -7.4999851e-01  1.9655154e-07]]
            >>> orientations
            [[ 9.9999994e-01 -8.8168377e-07 -4.1946004e-07 -1.5067183e-08]
             [ 1.0000000e+00 -9.5171310e-07 -2.2615541e-07  5.5922797e-08]
             [ 1.0000000e+00 -7.9806580e-07 -1.3064776e-07  5.3154917e-08]]
        """
        if not self._is_valid:
            raise Exception("prim view {} is not a valid view".format(self._regex_prim_paths))
        if self.is_physics_handle_valid():
            indices = self._backend_utils.resolve_indices(indices, self.count, self._device)
            pose = self._physics_view.get_transforms()
            if clone:
                pose = self._backend_utils.clone_tensor(pose, device=self._device)
            pos = pose[indices, 0:3]

            # We AVOID native self._backend_utils.xyzw2wxyz(pose[indices, 3:7]) because it's slow!!
            rot = pose[:, [6, 3, 4, 5]][indices]
            return pos, rot
        else:
            return _XFormPrimView.get_world_poses(self, indices=indices, usd=usd)

    def enable_gravities(self, indices: Optional[Union[np.ndarray, list, torch.Tensor, wp.array]] = None) -> None:
        """Enable gravity on rigid bodies (enabled by default).

        Args:
            indices (Optional[Union[np.ndarray, list, torch.Tensor, wp.array]], optional): indicies to specify which prims
                                                                                 to manipulate. Shape (M,).
                                                                                 Where M <= size of the encapsulated prims in the view.
                                                                                 Defaults to None (i.e: all prims in the view).
        """
        if not self._is_valid:
            raise Exception("prim view {} is not a valid view".format(self._regex_prim_paths))
        if self.is_physics_handle_valid():
            indices = self._backend_utils.resolve_indices(indices, self.count, "cpu")
            data = self._physics_view.get_disable_gravities().reshape(self._count)
            data = self._backend_utils.assign(
                self._backend_utils.create_tensor_from_list([False] * len(indices), dtype="uint8"), data, indices
            )
            self._physics_view.set_disable_gravities(data, indices)
        else:
            indices = self._backend_utils.resolve_indices(indices, self.count, self._device)
            indices = self._backend_utils.to_list(indices)
            for i in indices:
                if self._physx_rigid_body_apis[i] is None:
                    if self._prims[i].HasAPI(PhysxSchema.PhysxRigidBodyAPI):
                        rigid_api = PhysxSchema.PhysxRigidBodyAPI(self._prims[i])
                    else:
                        rigid_api = PhysxSchema.PhysxRigidBodyAPI.Apply(self._prims[i])
                    self._physx_rigid_body_apis[i] = rigid_api
                self._physx_rigid_body_apis[i].GetDisableGravityAttr().Set(False)

    def disable_gravities(self, indices: Optional[Union[np.ndarray, list, torch.Tensor, wp.array]] = None) -> None:
        """Disable gravity on rigid bodies (enabled by default).

        Args:
            indices (Optional[Union[np.ndarray, list, torch.Tensor, wp.array]], optional): indicies to specify which prims
                                                                                 to manipulate. Shape (M,).
                                                                                 Where M <= size of the encapsulated prims in the view.
                                                                                 Defaults to None (i.e: all prims in the view).
        """
        if not self._is_valid:
            raise Exception("prim view {} is not a valid view".format(self._regex_prim_paths))
        indices = self._backend_utils.resolve_indices(indices, self.count, "cpu")
        if self.is_physics_handle_valid():
            data = self._physics_view.get_disable_gravities().reshape(self._count)
            data = self._backend_utils.assign(
                self._backend_utils.create_tensor_from_list([True] * len(indices), dtype="uint8"), data, indices
            )
            self._physics_view.set_disable_gravities(data, indices)
        else:
            indices = self._backend_utils.resolve_indices(indices, self.count, self._device)
            indices = self._backend_utils.to_list(indices)
            for i in indices:
                if self._physx_rigid_body_apis[i] is None:
                    if self._prims[i].HasAPI(PhysxSchema.PhysxRigidBodyAPI):
                        rigid_api = PhysxSchema.PhysxRigidBodyAPI(self._prims[i])
                    else:
                        rigid_api = PhysxSchema.PhysxRigidBodyAPI.Apply(self._prims[i])
                    self._physx_rigid_body_apis[i] = rigid_api
                self._physx_rigid_body_apis[i].GetDisableGravityAttr().Set(True)
            return

    def get_coms(
        self, indices: Optional[Union[np.ndarray, List, torch.Tensor, wp.array]] = None, clone: bool = True
    ) -> Union[np.ndarray, torch.Tensor, wp.indexedarray]:
        """Get rigid body center of mass (COM) of bodies in the view.

        Args:
            indices (Optional[Union[np.ndarray, List, torch.Tensor, wp.array]], optional): indices to specify which prims
                                                                                 to query. Shape (M,).
                                                                                 Where M <= size of the encapsulated prims in the view.
                                                                                 Defaults to None (i.e: all prims in the view).
            clone (bool, optional): True to return a clone of the internal buffer. Otherwise False. Defaults to True.

        Returns:
            Union[np.ndarray, torch.Tensor, wp.indexedarray]: rigid body center of mass positions and orientations of prims in the view.
            position shape is (M, 1, 3), orientation shape is (M, 1, 4).

        Example:

        .. code-block:: python

            >>> # get all rigid body center of mass.
            >>> # Returned shape is (5, 1, 3) for positions and (5, 1, 4) for orientations for the example: 5 envs
            >>> positions, orientations = prims.get_coms()
            >>> positions
            [[[0. 0. 0.]]
             [[0. 0. 0.]]
             [[0. 0. 0.]]
             [[0. 0. 0.]]
             [[0. 0. 0.]]]
            >>> orientations
            [[[1. 0. 0. 0.]]
             [[1. 0. 0. 0.]]
             [[1. 0. 0. 0.]]
             [[1. 0. 0. 0.]]
             [[1. 0. 0. 0.]]]
            >>>
            >>> # get rigid body center of mass for the first, middle and last of the 5 envs.
            >>> # Returned shape is (3, 1, 3) for positions and (3, 1, 4) for orientations
            >>> positions, orientations = prims.get_coms(indices=np.array([0, 2, 4]))
            >>> positions
            [[[0. 0. 0.]]
             [[0. 0. 0.]]
             [[0. 0. 0.]]]
            >>> orientations
            [[[1. 0. 0. 0.]]
             [[1. 0. 0. 0.]]
             [[1. 0. 0. 0.]]]
        """
        if not self._is_valid:
            raise Exception("prim view {} is not a valid view".format(self._regex_prim_paths))
        if self.is_physics_handle_valid():
            indices = self._backend_utils.resolve_indices(indices, self.count, self._device)
            current_values = self._backend_utils.move_data(
                self._physics_view.get_coms().reshape((self.count, 7)), self._device
            )
            if clone:
                current_values = self._backend_utils.clone_tensor(current_values, device=self._device)
            positions = current_values[
                self._backend_utils.expand_dims(indices, 1) if self._backend != "warp" else indices, 0:3
            ]
            orientations = self._backend_utils.xyzw2wxyz(
                current_values[self._backend_utils.expand_dims(indices, 1) if self._backend != "warp" else indices, 3:7]
            )
            return positions, orientations
        else:
            indices = self._backend_utils.resolve_indices(indices, self.count, self._device)
            positions = np.zeros((indices.shape[0], 1, 3), dtype=np.float32)
            orientations = np.zeros((indices.shape[0], 1, 4), dtype=np.float32)
            indices = self._backend_utils.to_list(indices)
            write_idx = 0
            for i in indices:
                positions[write_idx][0] = np.array(self._prims[i].GetAttribute("physics:centerOfMass").Get())
                orientations[write_idx][0] = np.array([1, 0, 0, 0])
                write_idx += 1
            positions = self._backend_utils.convert(positions, device=self._device, dtype="float32", indexed=True)
            orientations = self._backend_utils.convert(orientations, device=self._device, dtype="float32", indexed=True)
            return positions, orientations

    def set_coms(
        self,
        positions: Union[np.ndarray, torch.Tensor, wp.array] = None,
        orientations: Union[np.ndarray, torch.Tensor, wp.array] = None,
        indices: Optional[Union[np.ndarray, List, torch.Tensor, wp.array]] = None,
    ) -> None:
        """Set body center of mass (COM) positions and orientations for bodies in the view.

        Args:
            positions (Union[np.ndarray, torch.Tensor, wp.array]): body center of mass positions for bodies in the view. shape (M, 1, 3).
            orientations (Union[np.ndarray, torch.Tensor, wp.array]): body center of mass orientations for bodies in the view. shape (M, 1, 4).
            indices (Optional[Union[np.ndarray, List, torch.Tensor, wp.array]], optional): indices to specify which prims
                                                                                 to manipulate. Shape (M,).
                                                                                 Where M <= size of the encapsulated prims in the view.
                                                                                 Defaults to None (i.e: all prims in the view).

        Example:

        .. code-block:: python

            >>> # set the center of mass for all the rigid bodies to the specified values.
            >>> # Since there are 5 envs, the inertias are repeated 5 times
            >>> positions = np.tile(np.array([0.01, 0.02, 0.03]), (num_envs, 1, 1))
            >>> orientations = np.tile(np.array([1.0, 0.0, 0.0, 0.0]), (num_envs, 1, 1))
            >>> prims.set_coms(positions, orientations)
            >>>
            >>> # set the rigid bodies center of mass for the first, middle and last of the 5 envs
            >>> positions = np.tile(np.array([0.01, 0.02, 0.03]), (3, 1, 1))
            >>> orientations = np.tile(np.array([1.0, 0.0, 0.0, 0.0]), (3, 1, 1))
            >>> prims.set_coms(positions, orientations, indices=np.array([0, 2, 4]))
        """
        if not self._is_valid:
            raise Exception("prim view {} is not a valid view".format(self._regex_prim_paths))
        indices = self._backend_utils.resolve_indices(indices, self.count, "cpu")
        if self.is_physics_handle_valid():
            coms = self._physics_view.get_coms().reshape((self.count, 7))
            if positions is not None:
                if self._backend == "warp":
                    coms = self._backend_utils.assign(
                        self._backend_utils.move_data(positions, device="cpu"),
                        coms,
                        [indices, wp.array([0, 1, 2], dtype=wp.int32, device="cpu")],
                    )
                else:
                    coms[self._backend_utils.expand_dims(indices, 1), 0:3] = self._backend_utils.move_data(
                        positions, device="cpu"
                    )
            if orientations is not None:
                if self._backend == "warp":
                    coms = self._backend_utils.assign(
                        self._backend_utils.move_data(self._backend_utils.wxyz2xyzw(orientations), device="cpu"),
                        coms,
                        [indices, wp.array([3, 4, 5, 6], dtype=wp.int32, device="cpu")],
                    )
                else:
                    coms[self._backend_utils.expand_dims(indices, 1), 3:7] = self._backend_utils.move_data(
                        orientations[:, :, [1, 2, 3, 0]], device="cpu"
                    )
            self._physics_view.set_coms(coms, indices)
        else:
            # Note: this does NOT set orientation, as it is not supported in USD
            positions = self._backend_utils.to_list(positions)
            write_idx = 0
            for i in indices:
                properties = self._prims[i].GetPropertyNames()
                position = Gf.Vec3f(*positions[write_idx][0])
                if "physics:centerOfMass" not in properties:
                    carb.log_error(
                        "physics:centerOfMass property needs to be set for {} before setting its position".format(
                            self.name
                        )
                    )
                xform_op = self._prims[i].GetAttribute("physics:centerOfMass")
                xform_op.Set(position)
                write_idx += 1

disable_gravities(indices=None)

Disable gravity on rigid bodies (enabled by default).

Parameters:

Name Type Description Default
indices Optional[Union[ndarray, list, Tensor, array]]

indicies to specify which prims to manipulate. Shape (M,). Where M <= size of the encapsulated prims in the view. Defaults to None (i.e: all prims in the view).

None
Source code in OmniGibson/omnigibson/utils/deprecated_utils.py
def disable_gravities(self, indices: Optional[Union[np.ndarray, list, torch.Tensor, wp.array]] = None) -> None:
    """Disable gravity on rigid bodies (enabled by default).

    Args:
        indices (Optional[Union[np.ndarray, list, torch.Tensor, wp.array]], optional): indicies to specify which prims
                                                                             to manipulate. Shape (M,).
                                                                             Where M <= size of the encapsulated prims in the view.
                                                                             Defaults to None (i.e: all prims in the view).
    """
    if not self._is_valid:
        raise Exception("prim view {} is not a valid view".format(self._regex_prim_paths))
    indices = self._backend_utils.resolve_indices(indices, self.count, "cpu")
    if self.is_physics_handle_valid():
        data = self._physics_view.get_disable_gravities().reshape(self._count)
        data = self._backend_utils.assign(
            self._backend_utils.create_tensor_from_list([True] * len(indices), dtype="uint8"), data, indices
        )
        self._physics_view.set_disable_gravities(data, indices)
    else:
        indices = self._backend_utils.resolve_indices(indices, self.count, self._device)
        indices = self._backend_utils.to_list(indices)
        for i in indices:
            if self._physx_rigid_body_apis[i] is None:
                if self._prims[i].HasAPI(PhysxSchema.PhysxRigidBodyAPI):
                    rigid_api = PhysxSchema.PhysxRigidBodyAPI(self._prims[i])
                else:
                    rigid_api = PhysxSchema.PhysxRigidBodyAPI.Apply(self._prims[i])
                self._physx_rigid_body_apis[i] = rigid_api
            self._physx_rigid_body_apis[i].GetDisableGravityAttr().Set(True)
        return

enable_gravities(indices=None)

Enable gravity on rigid bodies (enabled by default).

Parameters:

Name Type Description Default
indices Optional[Union[ndarray, list, Tensor, array]]

indicies to specify which prims to manipulate. Shape (M,). Where M <= size of the encapsulated prims in the view. Defaults to None (i.e: all prims in the view).

None
Source code in OmniGibson/omnigibson/utils/deprecated_utils.py
def enable_gravities(self, indices: Optional[Union[np.ndarray, list, torch.Tensor, wp.array]] = None) -> None:
    """Enable gravity on rigid bodies (enabled by default).

    Args:
        indices (Optional[Union[np.ndarray, list, torch.Tensor, wp.array]], optional): indicies to specify which prims
                                                                             to manipulate. Shape (M,).
                                                                             Where M <= size of the encapsulated prims in the view.
                                                                             Defaults to None (i.e: all prims in the view).
    """
    if not self._is_valid:
        raise Exception("prim view {} is not a valid view".format(self._regex_prim_paths))
    if self.is_physics_handle_valid():
        indices = self._backend_utils.resolve_indices(indices, self.count, "cpu")
        data = self._physics_view.get_disable_gravities().reshape(self._count)
        data = self._backend_utils.assign(
            self._backend_utils.create_tensor_from_list([False] * len(indices), dtype="uint8"), data, indices
        )
        self._physics_view.set_disable_gravities(data, indices)
    else:
        indices = self._backend_utils.resolve_indices(indices, self.count, self._device)
        indices = self._backend_utils.to_list(indices)
        for i in indices:
            if self._physx_rigid_body_apis[i] is None:
                if self._prims[i].HasAPI(PhysxSchema.PhysxRigidBodyAPI):
                    rigid_api = PhysxSchema.PhysxRigidBodyAPI(self._prims[i])
                else:
                    rigid_api = PhysxSchema.PhysxRigidBodyAPI.Apply(self._prims[i])
                self._physx_rigid_body_apis[i] = rigid_api
            self._physx_rigid_body_apis[i].GetDisableGravityAttr().Set(False)

get_angular_velocities(indices=None, clone=True)

Get the angular velocities of prims in the view.

Parameters:

Name Type Description Default
indices Optional[Union[ndarray, list, Tensor, array]]

indices to specify which prims to query. Shape (M,). Where M <= size of the encapsulated prims in the view. Defaults to None (i.e: all prims in the view)

None
clone bool

True to return a clone of the internal buffer. Otherwise False. Defaults to True.

True

Returns:

Type Description
Union[ndarray, Tensor, indexedarray]

angular velocities of the prims in the view. shape is (M, 3).

Example:

.. code-block:: python

>>> # get all rigid prim angular velocities. Returned shape is (5, 3) for the example: 5 envs, angular (3)
>>> prims.get_angular_velocities()
[[0. 0. 0.]
 [0. 0. 0.]
 [0. 0. 0.]
 [0. 0. 0.]
 [0. 0. 0.]]
>>>
>>> # get only the rigid prim angular velocities for the first, middle and last of the 5 envs
>>> # Returned shape is (5, 3) for the example: 3 envs selected, angular (3)
>>> prims.get_angular_velocities(indices=np.array([0, 2, 4]))
[[0. 0. 0.]
 [0. 0. 0.]
 [0. 0. 0.]]
Source code in OmniGibson/omnigibson/utils/deprecated_utils.py
def get_angular_velocities(
    self, indices: Optional[Union[np.ndarray, list, torch.Tensor, wp.array]] = None, clone: bool = True
) -> Union[np.ndarray, torch.Tensor, wp.indexedarray]:
    """Get the angular velocities of prims in the view.

    Args:
        indices (Optional[Union[np.ndarray, list, torch.Tensor, wp.array]], optional): indices to specify which prims
                                                                                to query. Shape (M,).
                                                                                Where M <= size of the encapsulated prims in the view.
                                                                                Defaults to None (i.e: all prims in the view)
        clone (bool, optional): True to return a clone of the internal buffer. Otherwise False. Defaults to True.

    Returns:
        Union[np.ndarray, torch.Tensor, wp.indexedarray]: angular velocities of the prims in the view. shape is (M, 3).

    Example:

    .. code-block:: python

        >>> # get all rigid prim angular velocities. Returned shape is (5, 3) for the example: 5 envs, angular (3)
        >>> prims.get_angular_velocities()
        [[0. 0. 0.]
         [0. 0. 0.]
         [0. 0. 0.]
         [0. 0. 0.]
         [0. 0. 0.]]
        >>>
        >>> # get only the rigid prim angular velocities for the first, middle and last of the 5 envs
        >>> # Returned shape is (5, 3) for the example: 3 envs selected, angular (3)
        >>> prims.get_angular_velocities(indices=np.array([0, 2, 4]))
        [[0. 0. 0.]
         [0. 0. 0.]
         [0. 0. 0.]]
    """
    if not self._is_valid:
        raise Exception("prim view {} is not a valid view".format(self._regex_prim_paths))
    indices = self._backend_utils.resolve_indices(indices, self.count, self._device)
    if self.is_physics_handle_valid():
        angular_velocities = self._physics_view.get_velocities()
        if clone:
            # THIS LINE WAS NAMED INCORRECTLY!!
            angular_velocities = self._backend_utils.clone_tensor(angular_velocities, device=self._device)
        return angular_velocities[indices, 3:6]
    else:
        angular_velocities = np.zeros(shape=(indices.shape[0], 3), dtype=np.float32)
        write_idx = 0
        indices = self._backend_utils.to_list(indices)
        for i in indices:
            if self._rigid_body_apis[i] is None:
                if self._prims[i].HasAPI(UsdPhysics.RigidBodyAPI):
                    rigid_api = UsdPhysics.RigidBodyAPI(self._prims[i])
                else:
                    rigid_api = UsdPhysics.RigidBodyAPI.Apply(self._prims[i])
                self._rigid_body_apis[i] = rigid_api
            angular_velocities[write_idx] = np.array(
                self._rigid_body_apis[i].GetAngularVelocityAttr().Get(), dtype="float32"
            )
            write_idx += 1
        angular_velocities = self._backend_utils.convert(
            angular_velocities, dtype="float32", device=self._device, indexed=True
        )
        return angular_velocities

get_coms(indices=None, clone=True)

Get rigid body center of mass (COM) of bodies in the view.

Parameters:

Name Type Description Default
indices Optional[Union[ndarray, List, Tensor, array]]

indices to specify which prims to query. Shape (M,). Where M <= size of the encapsulated prims in the view. Defaults to None (i.e: all prims in the view).

None
clone bool

True to return a clone of the internal buffer. Otherwise False. Defaults to True.

True

Returns:

Type Description
Union[ndarray, Tensor, indexedarray]

rigid body center of mass positions and orientations of prims in the view.

Union[ndarray, Tensor, indexedarray]

position shape is (M, 1, 3), orientation shape is (M, 1, 4).

Example:

.. code-block:: python

>>> # get all rigid body center of mass.
>>> # Returned shape is (5, 1, 3) for positions and (5, 1, 4) for orientations for the example: 5 envs
>>> positions, orientations = prims.get_coms()
>>> positions
[[[0. 0. 0.]]
 [[0. 0. 0.]]
 [[0. 0. 0.]]
 [[0. 0. 0.]]
 [[0. 0. 0.]]]
>>> orientations
[[[1. 0. 0. 0.]]
 [[1. 0. 0. 0.]]
 [[1. 0. 0. 0.]]
 [[1. 0. 0. 0.]]
 [[1. 0. 0. 0.]]]
>>>
>>> # get rigid body center of mass for the first, middle and last of the 5 envs.
>>> # Returned shape is (3, 1, 3) for positions and (3, 1, 4) for orientations
>>> positions, orientations = prims.get_coms(indices=np.array([0, 2, 4]))
>>> positions
[[[0. 0. 0.]]
 [[0. 0. 0.]]
 [[0. 0. 0.]]]
>>> orientations
[[[1. 0. 0. 0.]]
 [[1. 0. 0. 0.]]
 [[1. 0. 0. 0.]]]
Source code in OmniGibson/omnigibson/utils/deprecated_utils.py
def get_coms(
    self, indices: Optional[Union[np.ndarray, List, torch.Tensor, wp.array]] = None, clone: bool = True
) -> Union[np.ndarray, torch.Tensor, wp.indexedarray]:
    """Get rigid body center of mass (COM) of bodies in the view.

    Args:
        indices (Optional[Union[np.ndarray, List, torch.Tensor, wp.array]], optional): indices to specify which prims
                                                                             to query. Shape (M,).
                                                                             Where M <= size of the encapsulated prims in the view.
                                                                             Defaults to None (i.e: all prims in the view).
        clone (bool, optional): True to return a clone of the internal buffer. Otherwise False. Defaults to True.

    Returns:
        Union[np.ndarray, torch.Tensor, wp.indexedarray]: rigid body center of mass positions and orientations of prims in the view.
        position shape is (M, 1, 3), orientation shape is (M, 1, 4).

    Example:

    .. code-block:: python

        >>> # get all rigid body center of mass.
        >>> # Returned shape is (5, 1, 3) for positions and (5, 1, 4) for orientations for the example: 5 envs
        >>> positions, orientations = prims.get_coms()
        >>> positions
        [[[0. 0. 0.]]
         [[0. 0. 0.]]
         [[0. 0. 0.]]
         [[0. 0. 0.]]
         [[0. 0. 0.]]]
        >>> orientations
        [[[1. 0. 0. 0.]]
         [[1. 0. 0. 0.]]
         [[1. 0. 0. 0.]]
         [[1. 0. 0. 0.]]
         [[1. 0. 0. 0.]]]
        >>>
        >>> # get rigid body center of mass for the first, middle and last of the 5 envs.
        >>> # Returned shape is (3, 1, 3) for positions and (3, 1, 4) for orientations
        >>> positions, orientations = prims.get_coms(indices=np.array([0, 2, 4]))
        >>> positions
        [[[0. 0. 0.]]
         [[0. 0. 0.]]
         [[0. 0. 0.]]]
        >>> orientations
        [[[1. 0. 0. 0.]]
         [[1. 0. 0. 0.]]
         [[1. 0. 0. 0.]]]
    """
    if not self._is_valid:
        raise Exception("prim view {} is not a valid view".format(self._regex_prim_paths))
    if self.is_physics_handle_valid():
        indices = self._backend_utils.resolve_indices(indices, self.count, self._device)
        current_values = self._backend_utils.move_data(
            self._physics_view.get_coms().reshape((self.count, 7)), self._device
        )
        if clone:
            current_values = self._backend_utils.clone_tensor(current_values, device=self._device)
        positions = current_values[
            self._backend_utils.expand_dims(indices, 1) if self._backend != "warp" else indices, 0:3
        ]
        orientations = self._backend_utils.xyzw2wxyz(
            current_values[self._backend_utils.expand_dims(indices, 1) if self._backend != "warp" else indices, 3:7]
        )
        return positions, orientations
    else:
        indices = self._backend_utils.resolve_indices(indices, self.count, self._device)
        positions = np.zeros((indices.shape[0], 1, 3), dtype=np.float32)
        orientations = np.zeros((indices.shape[0], 1, 4), dtype=np.float32)
        indices = self._backend_utils.to_list(indices)
        write_idx = 0
        for i in indices:
            positions[write_idx][0] = np.array(self._prims[i].GetAttribute("physics:centerOfMass").Get())
            orientations[write_idx][0] = np.array([1, 0, 0, 0])
            write_idx += 1
        positions = self._backend_utils.convert(positions, device=self._device, dtype="float32", indexed=True)
        orientations = self._backend_utils.convert(orientations, device=self._device, dtype="float32", indexed=True)
        return positions, orientations

get_linear_velocities(indices=None, clone=True)

Get the linear velocities of prims in the view.

Parameters:

Name Type Description Default
indices Optional[Union[ndarray, list, Tensor, array]]

indices to specify which prims to query. Shape (M,). Where M <= size of the encapsulated prims in the view. Defaults to None (i.e: all prims in the view)

None
clone bool

True to return a clone of the internal buffer. Otherwise False. Defaults to True.

True

Returns:

Type Description
Union[ndarray, Tensor, indexedarray]

linear velocities of the prims in the view. shape is (M, 3).

Example:

.. code-block:: python

>>> # get all rigid prim linear velocities. Returned shape is (5, 3) for the example: 5 envs, linear (3)
>>> prims.get_linear_velocities()
[[0. 0. 0.]
 [0. 0. 0.]
 [0. 0. 0.]
 [0. 0. 0.]
 [0. 0. 0.]]
>>>
>>> # get only the rigid prim linear velocities for the first, middle and last of the 5 envs.
>>> # Returned shape is (3, 3) for the example: 3 envs selected, linear (3)
>>> prims.get_linear_velocities(indices=np.array([0, 2, 4]))
[[0. 0. 0.]
 [0. 0. 0.]
 [0. 0. 0.]]
Source code in OmniGibson/omnigibson/utils/deprecated_utils.py
def get_linear_velocities(
    self, indices: Optional[Union[np.ndarray, list, torch.Tensor, wp.array]] = None, clone: bool = True
) -> Union[np.ndarray, torch.Tensor, wp.indexedarray]:
    """Get the linear velocities of prims in the view.

    Args:
        indices (Optional[Union[np.ndarray, list, torch.Tensor, wp.array]], optional): indices to specify which prims
                                                                                to query. Shape (M,).
                                                                                Where M <= size of the encapsulated prims in the view.
                                                                                Defaults to None (i.e: all prims in the view)
        clone (bool, optional): True to return a clone of the internal buffer. Otherwise False. Defaults to True.

    Returns:
        Union[np.ndarray, torch.Tensor, wp.indexedarray]: linear velocities of the prims in the view. shape is (M, 3).

    Example:

    .. code-block:: python

        >>> # get all rigid prim linear velocities. Returned shape is (5, 3) for the example: 5 envs, linear (3)
        >>> prims.get_linear_velocities()
        [[0. 0. 0.]
         [0. 0. 0.]
         [0. 0. 0.]
         [0. 0. 0.]
         [0. 0. 0.]]
        >>>
        >>> # get only the rigid prim linear velocities for the first, middle and last of the 5 envs.
        >>> # Returned shape is (3, 3) for the example: 3 envs selected, linear (3)
        >>> prims.get_linear_velocities(indices=np.array([0, 2, 4]))
        [[0. 0. 0.]
         [0. 0. 0.]
         [0. 0. 0.]]
    """
    if not self._is_valid:
        raise Exception("prim view {} is not a valid view".format(self._regex_prim_paths))
    indices = self._backend_utils.resolve_indices(indices, self.count, self._device)

    if self.is_physics_handle_valid():
        linear_velocities = self._physics_view.get_velocities()
        if clone:
            # THIS LINE WAS NAMED INCORRECTLY!!!
            linear_velocities = self._backend_utils.clone_tensor(linear_velocities, device=self._device)
        return linear_velocities[indices, 0:3]
    else:
        linear_velocities = np.zeros(shape=(indices.shape[0], 3), dtype=np.float32)
        write_idx = 0
        indices = self._backend_utils.to_list(indices)
        for i in indices:
            if self._rigid_body_apis[i] is None:
                if self._prims[i].HasAPI(UsdPhysics.RigidBodyAPI):
                    rigid_api = UsdPhysics.RigidBodyAPI(self._prims[i])
                else:
                    rigid_api = UsdPhysics.RigidBodyAPI.Apply(self._prims[i])
                self._rigid_body_apis[i] = rigid_api
            linear_velocities[write_idx] = np.array(
                self._rigid_body_apis[i].GetVelocityAttr().Get(), dtype=np.float32
            )
            write_idx += 1
        linear_velocities = self._backend_utils.convert(
            linear_velocities, dtype="float32", device=self._device, indexed=True
        )
        return linear_velocities

get_world_poses(indices=None, clone=True, usd=True)

Get the poses of the prims in the view with respect to the world's frame.

Parameters:

Name Type Description Default
indices Optional[Union[ndarray, list, Tensor, array]]

indices to specify which prims to query. Shape (M,). Where M <= size of the encapsulated prims in the view. Defaults to None (i.e: all prims in the view).

None
clone bool

True to return a clone of the internal buffer. Otherwise False. Defaults to True.

True
usd bool

True to query from usd. Otherwise False to query from Fabric data. Defaults to True.

True

Returns:

Type Description
Union[Tuple[ndarray, ndarray], Tuple[Tensor, Tensor], Tuple[indexedarray, indexedarray]]
Union[Tuple[ndarray, ndarray], Tuple[Tensor, Tensor], Tuple[indexedarray, indexedarray]]

first index is positions in the world frame of the prims. shape is (M, 3).

Union[Tuple[ndarray, ndarray], Tuple[Tensor, Tensor], Tuple[indexedarray, indexedarray]]

second index is quaternion orientations in the world frame of the prims.

Union[Tuple[ndarray, ndarray], Tuple[Tensor, Tensor], Tuple[indexedarray, indexedarray]]

quaternion is scalar-first (w, x, y, z). shape is (M, 4).

Example:

.. code-block:: python

>>> # get all rigid prim poses with respect to the world's frame.
>>> # Returned shape is position (5, 3) and orientation (5, 4) for the example: 5 envs
>>> positions, orientations = prims.get_world_poses()
>>> positions
[[ 1.4999989e+00 -7.4999851e-01 -1.5118626e-07]
 [ 1.4999989e+00  7.5000149e-01 -2.5988294e-07]
 [-1.0017333e-06 -7.4999845e-01  7.6070329e-08]
 [-9.5906785e-07  7.5000149e-01  1.0593490e-07]
 [-1.5000011e+00 -7.4999851e-01  1.9655154e-07]]
>>> orientations
[[ 9.9999994e-01 -8.8168377e-07 -4.1946004e-07 -1.5067183e-08]
 [ 9.9999994e-01 -8.8691013e-07 -4.2665880e-07 -2.7188951e-09]
 [ 1.0000000e+00 -9.5171310e-07 -2.2615541e-07  5.5922797e-08]
 [ 1.0000000e+00 -8.9923367e-07 -1.4408238e-07  1.3476099e-08]
 [ 1.0000000e+00 -7.9806580e-07 -1.3064776e-07  5.3154917e-08]]
>>>
>>> # get only the rigid prim poses with respect to the world's frame for the first, middle and last of the 5 envs.
>>> # Returned shape is position (3, 3) and orientation (3, 4) for the example: 3 envs selected
>>> positions, orientations = prims.get_world_poses(indices=np.array([0, 2, 4]))
>>> positions
[[ 1.4999989e+00 -7.4999851e-01 -1.5118626e-07]
 [-1.0017333e-06 -7.4999845e-01  7.6070329e-08]
 [-1.5000011e+00 -7.4999851e-01  1.9655154e-07]]
>>> orientations
[[ 9.9999994e-01 -8.8168377e-07 -4.1946004e-07 -1.5067183e-08]
 [ 1.0000000e+00 -9.5171310e-07 -2.2615541e-07  5.5922797e-08]
 [ 1.0000000e+00 -7.9806580e-07 -1.3064776e-07  5.3154917e-08]]
Source code in OmniGibson/omnigibson/utils/deprecated_utils.py
def get_world_poses(
    self,
    indices: Optional[Union[np.ndarray, list, torch.Tensor, wp.array]] = None,
    clone: bool = True,
    usd: bool = True,
) -> Union[
    Tuple[np.ndarray, np.ndarray], Tuple[torch.Tensor, torch.Tensor], Tuple[wp.indexedarray, wp.indexedarray]
]:
    """Get the poses of the prims in the view with respect to the world's frame.

    Args:
        indices (Optional[Union[np.ndarray, list, torch.Tensor, wp.array]], optional): indices to specify which prims
                                                                             to query. Shape (M,).
                                                                             Where M <= size of the encapsulated prims in the view.
                                                                             Defaults to None (i.e: all prims in the view).
        clone (bool, optional): True to return a clone of the internal buffer. Otherwise False. Defaults to True.
        usd (bool, optional): True to query from usd. Otherwise False to query from Fabric data. Defaults to True.

    Returns:
        Union[Tuple[np.ndarray, np.ndarray], Tuple[torch.Tensor, torch.Tensor], Tuple[wp.indexedarray, wp.indexedarray]]:
        first index is positions in the world frame of the prims. shape is (M, 3).
        second index is quaternion orientations in the world frame of the prims.
        quaternion is scalar-first (w, x, y, z). shape is (M, 4).

    Example:

    .. code-block:: python

        >>> # get all rigid prim poses with respect to the world's frame.
        >>> # Returned shape is position (5, 3) and orientation (5, 4) for the example: 5 envs
        >>> positions, orientations = prims.get_world_poses()
        >>> positions
        [[ 1.4999989e+00 -7.4999851e-01 -1.5118626e-07]
         [ 1.4999989e+00  7.5000149e-01 -2.5988294e-07]
         [-1.0017333e-06 -7.4999845e-01  7.6070329e-08]
         [-9.5906785e-07  7.5000149e-01  1.0593490e-07]
         [-1.5000011e+00 -7.4999851e-01  1.9655154e-07]]
        >>> orientations
        [[ 9.9999994e-01 -8.8168377e-07 -4.1946004e-07 -1.5067183e-08]
         [ 9.9999994e-01 -8.8691013e-07 -4.2665880e-07 -2.7188951e-09]
         [ 1.0000000e+00 -9.5171310e-07 -2.2615541e-07  5.5922797e-08]
         [ 1.0000000e+00 -8.9923367e-07 -1.4408238e-07  1.3476099e-08]
         [ 1.0000000e+00 -7.9806580e-07 -1.3064776e-07  5.3154917e-08]]
        >>>
        >>> # get only the rigid prim poses with respect to the world's frame for the first, middle and last of the 5 envs.
        >>> # Returned shape is position (3, 3) and orientation (3, 4) for the example: 3 envs selected
        >>> positions, orientations = prims.get_world_poses(indices=np.array([0, 2, 4]))
        >>> positions
        [[ 1.4999989e+00 -7.4999851e-01 -1.5118626e-07]
         [-1.0017333e-06 -7.4999845e-01  7.6070329e-08]
         [-1.5000011e+00 -7.4999851e-01  1.9655154e-07]]
        >>> orientations
        [[ 9.9999994e-01 -8.8168377e-07 -4.1946004e-07 -1.5067183e-08]
         [ 1.0000000e+00 -9.5171310e-07 -2.2615541e-07  5.5922797e-08]
         [ 1.0000000e+00 -7.9806580e-07 -1.3064776e-07  5.3154917e-08]]
    """
    if not self._is_valid:
        raise Exception("prim view {} is not a valid view".format(self._regex_prim_paths))
    if self.is_physics_handle_valid():
        indices = self._backend_utils.resolve_indices(indices, self.count, self._device)
        pose = self._physics_view.get_transforms()
        if clone:
            pose = self._backend_utils.clone_tensor(pose, device=self._device)
        pos = pose[indices, 0:3]

        # We AVOID native self._backend_utils.xyzw2wxyz(pose[indices, 3:7]) because it's slow!!
        rot = pose[:, [6, 3, 4, 5]][indices]
        return pos, rot
    else:
        return _XFormPrimView.get_world_poses(self, indices=indices, usd=usd)

set_coms(positions=None, orientations=None, indices=None)

Set body center of mass (COM) positions and orientations for bodies in the view.

Parameters:

Name Type Description Default
positions Union[ndarray, Tensor, array]

body center of mass positions for bodies in the view. shape (M, 1, 3).

None
orientations Union[ndarray, Tensor, array]

body center of mass orientations for bodies in the view. shape (M, 1, 4).

None
indices Optional[Union[ndarray, List, Tensor, array]]

indices to specify which prims to manipulate. Shape (M,). Where M <= size of the encapsulated prims in the view. Defaults to None (i.e: all prims in the view).

None

Example:

.. code-block:: python

>>> # set the center of mass for all the rigid bodies to the specified values.
>>> # Since there are 5 envs, the inertias are repeated 5 times
>>> positions = np.tile(np.array([0.01, 0.02, 0.03]), (num_envs, 1, 1))
>>> orientations = np.tile(np.array([1.0, 0.0, 0.0, 0.0]), (num_envs, 1, 1))
>>> prims.set_coms(positions, orientations)
>>>
>>> # set the rigid bodies center of mass for the first, middle and last of the 5 envs
>>> positions = np.tile(np.array([0.01, 0.02, 0.03]), (3, 1, 1))
>>> orientations = np.tile(np.array([1.0, 0.0, 0.0, 0.0]), (3, 1, 1))
>>> prims.set_coms(positions, orientations, indices=np.array([0, 2, 4]))
Source code in OmniGibson/omnigibson/utils/deprecated_utils.py
def set_coms(
    self,
    positions: Union[np.ndarray, torch.Tensor, wp.array] = None,
    orientations: Union[np.ndarray, torch.Tensor, wp.array] = None,
    indices: Optional[Union[np.ndarray, List, torch.Tensor, wp.array]] = None,
) -> None:
    """Set body center of mass (COM) positions and orientations for bodies in the view.

    Args:
        positions (Union[np.ndarray, torch.Tensor, wp.array]): body center of mass positions for bodies in the view. shape (M, 1, 3).
        orientations (Union[np.ndarray, torch.Tensor, wp.array]): body center of mass orientations for bodies in the view. shape (M, 1, 4).
        indices (Optional[Union[np.ndarray, List, torch.Tensor, wp.array]], optional): indices to specify which prims
                                                                             to manipulate. Shape (M,).
                                                                             Where M <= size of the encapsulated prims in the view.
                                                                             Defaults to None (i.e: all prims in the view).

    Example:

    .. code-block:: python

        >>> # set the center of mass for all the rigid bodies to the specified values.
        >>> # Since there are 5 envs, the inertias are repeated 5 times
        >>> positions = np.tile(np.array([0.01, 0.02, 0.03]), (num_envs, 1, 1))
        >>> orientations = np.tile(np.array([1.0, 0.0, 0.0, 0.0]), (num_envs, 1, 1))
        >>> prims.set_coms(positions, orientations)
        >>>
        >>> # set the rigid bodies center of mass for the first, middle and last of the 5 envs
        >>> positions = np.tile(np.array([0.01, 0.02, 0.03]), (3, 1, 1))
        >>> orientations = np.tile(np.array([1.0, 0.0, 0.0, 0.0]), (3, 1, 1))
        >>> prims.set_coms(positions, orientations, indices=np.array([0, 2, 4]))
    """
    if not self._is_valid:
        raise Exception("prim view {} is not a valid view".format(self._regex_prim_paths))
    indices = self._backend_utils.resolve_indices(indices, self.count, "cpu")
    if self.is_physics_handle_valid():
        coms = self._physics_view.get_coms().reshape((self.count, 7))
        if positions is not None:
            if self._backend == "warp":
                coms = self._backend_utils.assign(
                    self._backend_utils.move_data(positions, device="cpu"),
                    coms,
                    [indices, wp.array([0, 1, 2], dtype=wp.int32, device="cpu")],
                )
            else:
                coms[self._backend_utils.expand_dims(indices, 1), 0:3] = self._backend_utils.move_data(
                    positions, device="cpu"
                )
        if orientations is not None:
            if self._backend == "warp":
                coms = self._backend_utils.assign(
                    self._backend_utils.move_data(self._backend_utils.wxyz2xyzw(orientations), device="cpu"),
                    coms,
                    [indices, wp.array([3, 4, 5, 6], dtype=wp.int32, device="cpu")],
                )
            else:
                coms[self._backend_utils.expand_dims(indices, 1), 3:7] = self._backend_utils.move_data(
                    orientations[:, :, [1, 2, 3, 0]], device="cpu"
                )
        self._physics_view.set_coms(coms, indices)
    else:
        # Note: this does NOT set orientation, as it is not supported in USD
        positions = self._backend_utils.to_list(positions)
        write_idx = 0
        for i in indices:
            properties = self._prims[i].GetPropertyNames()
            position = Gf.Vec3f(*positions[write_idx][0])
            if "physics:centerOfMass" not in properties:
                carb.log_error(
                    "physics:centerOfMass property needs to be set for {} before setting its position".format(
                        self.name
                    )
                )
            xform_op = self._prims[i].GetAttribute("physics:centerOfMass")
            xform_op.Set(position)
            write_idx += 1

colorize_bboxes(bboxes_2d_data, bboxes_2d_rgb, num_channels=3)

Colorizes 2D bounding box data for visualization.

We are overriding the replicator native version of this function to fix a bug. In their version of this function, the ordering of the rectangle corners is incorrect and we fix it here.

Parameters:

Name Type Description Default
bboxes_2d_data ndarray

2D bounding box data from the sensor.

required
bboxes_2d_rgb ndarray

RGB data from the sensor to embed bounding box.

required
num_channels int

Specify number of channels i.e. 3 or 4.

3
Source code in OmniGibson/omnigibson/utils/deprecated_utils.py
def colorize_bboxes(bboxes_2d_data, bboxes_2d_rgb, num_channels=3):
    """Colorizes 2D bounding box data for visualization.

    We are overriding the replicator native version of this function to fix a bug.
    In their version of this function, the ordering of the rectangle corners is incorrect and we fix it here.

    Args:
        bboxes_2d_data (numpy.ndarray): 2D bounding box data from the sensor.
        bboxes_2d_rgb (numpy.ndarray): RGB data from the sensor to embed bounding box.
        num_channels (int): Specify number of channels i.e. 3 or 4.
    """
    semantic_id_list = []
    bbox_2d_list = []
    rgb_img = Image.fromarray(bboxes_2d_rgb)
    rgb_img_draw = ImageDraw.Draw(rgb_img)
    for bbox_2d in bboxes_2d_data:
        semantic_id_list.append(bbox_2d[0])
        bbox_2d_list.append(bbox_2d)
    semantic_id_list_np = np.unique(np.array(semantic_id_list))
    color_list = random_colours(len(semantic_id_list_np.tolist()), True, num_channels)
    for bbox_2d in bbox_2d_list:
        index = np.where(semantic_id_list_np == bbox_2d[0])[0][0]
        bbox_color = color_list[index]
        outline = (bbox_color[0], bbox_color[1], bbox_color[2])
        if num_channels == 4:
            outline = (
                bbox_color[0],
                bbox_color[1],
                bbox_color[2],
                bbox_color[3],
            )
        rgb_img_draw.rectangle([(bbox_2d[1], bbox_2d[2]), (bbox_2d[3], bbox_2d[4])], outline=outline, width=2)
    bboxes_2d_rgb = np.array(rgb_img)
    return bboxes_2d_rgb