MCPcopy Index your code
hub / github.com/google-deepmind/dm_control / shift_pose

Method shift_pose

dm_control/composer/entity.py:495–536  ·  view source on GitHub ↗

Shifts the position and/or orientation from its current configuration. This is a convenience function that performs the same operation as `set_pose`, but where the specified `position` is added to the current position, and the specified `quaternion` is premultiplied to the current q

(self,
                 physics,
                 position=None,
                 quaternion=None,
                 rotate_velocity=False)

Source from the content-addressed store, hash-verified

493 physics.bind(attachment_frame).quat = normalised_quaternion
494
495 def shift_pose(self,
496 physics,
497 position=None,
498 quaternion=None,
499 rotate_velocity=False):
500 """Shifts the position and/or orientation from its current configuration.
501
502 This is a convenience function that performs the same operation as
503 `set_pose`, but where the specified `position` is added to the current
504 position, and the specified `quaternion` is premultiplied to the current
505 quaternion.
506
507 Args:
508 physics: An instance of `mjcf.Physics`.
509 position: (optional) A NumPy array of size 3.
510 quaternion: (optional) A NumPy array of size 4.
511 rotate_velocity: (optional) A bool, whether to shift the current linear
512 velocity along with the pose. This will rotate the current linear
513 velocity, which is expressed relative to the world frame. The angular
514 velocity, which is expressed relative to the local frame is left
515 unchanged.
516
517 Raises:
518 RuntimeError: If the entity is not attached.
519 """
520 current_position, current_quaternion = self.get_pose(physics)
521 new_position, new_quaternion = None, None
522 if position is not None:
523 new_position = current_position + position
524 if quaternion is not None:
525 quaternion = np.asarray(quaternion, dtype=np.float64)
526 new_quaternion = _multiply_quaternions(quaternion, current_quaternion)
527 root_joint = mjcf.get_frame_freejoint(self.mjcf_model)
528 if root_joint and rotate_velocity:
529 # Rotate the linear velocity. The angular velocity (qvel[3:])
530 # is left unchanged, as it is expressed in the local frame.
531 # When rotatating the body frame the angular velocity already
532 # tracks the rotation but the linear velocity does not.
533 velocity = physics.bind(root_joint).qvel[:3]
534 rotated_velocity = _rotate_vector(velocity, quaternion)
535 self.set_velocity(physics, rotated_velocity)
536 self.set_pose(physics, new_position, new_quaternion)
537
538 def get_velocity(self, physics):
539 """Gets the linear and angular velocity of this free entity.

Callers 11

testShiftPoseMethod · 0.80
_respawnMethod · 0.80
initialize_episodeMethod · 0.80
initialize_episodeMethod · 0.80
_respawn_walkerMethod · 0.80
set_walkerFunction · 0.80
_initialize_walkerMethod · 0.80

Calls 6

get_poseMethod · 0.95
set_velocityMethod · 0.95
set_poseMethod · 0.95
_multiply_quaternionsFunction · 0.85
_rotate_vectorFunction · 0.85
bindMethod · 0.45