15
15
import os
16
16
from typing import Any , Callable , Dict , List , Tuple , Type , Union , cast
17
17
18
- import habitat_sim .utils as hab_utils
19
18
import numpy as np
19
+ import quaternion as qt
20
20
import scipy .ndimage
21
21
from scipy .spatial .transform import Rotation as rot # noqa: N813
22
22
@@ -1150,7 +1150,7 @@ def tangential_direction(self) -> VectorXYZ:
1150
1150
self .tangential_angle * (1 - self .alpha ) + new_target_direction * self .alpha
1151
1151
)
1152
1152
1153
- direction = hab_utils . quat_rotate_vector (
1153
+ direction = qt . rotate_vectors (
1154
1154
self .state [self .agent_id ]["rotation" ],
1155
1155
[
1156
1156
np .cos (self .tangential_angle - np .pi / 2 ),
@@ -1220,19 +1220,14 @@ def get_inverse_agent_rot(self):
1220
1220
identity pose, which will be aquired by transforming the original pose by the
1221
1221
inverse
1222
1222
1223
- NB Magnum appears to be a library used by Habitat; i.e. it is still grounded
1224
- in quaternions
1225
-
1226
1223
Returns:
1227
1224
Inverse quaternion rotation.
1228
1225
"""
1229
- inverse_magnum_rotation = hab_utils .common .quat_to_magnum (
1230
- self .state ["agent_id_0" ]["rotation" ]
1231
- ).inverted ()
1232
- inverse_quaternion_rotation = hab_utils .common .quat_from_magnum (
1233
- inverse_magnum_rotation
1234
- )
1235
- return inverse_quaternion_rotation
1226
+ # Note that quaternion format is [w, x, y, z]
1227
+ [w , x , y , z ] = qt .as_float_array (self .state [self .agent_id ]["rotation" ])
1228
+ # Note that scipy.spatial.transform.Rotation (v1.10.0) format is [x, y, z, w]
1229
+ [x , y , z , w ] = rot .from_quat ([x , y , z , w ]).inv ().as_quat ()
1230
+ return qt .quaternion (w , x , y , z )
1236
1231
1237
1232
def orienting_angle_from_normal (self , orienting : str ) -> float :
1238
1233
"""Compute turn angle to face the object.
@@ -1250,7 +1245,7 @@ def orienting_angle_from_normal(self, orienting: str) -> float:
1250
1245
1251
1246
inverse_quaternion_rotation = self .get_inverse_agent_rot ()
1252
1247
1253
- rotated_point_normal = hab_utils . quat_rotate_vector (
1248
+ rotated_point_normal = qt . rotate_vectors (
1254
1249
inverse_quaternion_rotation , original_point_normal
1255
1250
)
1256
1251
x , y , z = rotated_point_normal
@@ -1603,9 +1598,7 @@ def perform_pc_guided_step(self):
1603
1598
# Rotate the tangential vector to be in the coordinate frame of the sensory
1604
1599
# agent (rather than the global reference frame of the environment)
1605
1600
inverse_quaternion_rotation = self .get_inverse_agent_rot ()
1606
- rotated_form = hab_utils .quat_rotate_vector (
1607
- inverse_quaternion_rotation , selected_pc_dir
1608
- )
1601
+ rotated_form = qt .rotate_vectors (inverse_quaternion_rotation , selected_pc_dir )
1609
1602
1610
1603
# Before updating the representation and removing z-axis direction, check
1611
1604
# for movements defined in the z-axis
@@ -1654,7 +1647,7 @@ def perform_pc_guided_step(self):
1654
1647
self .reset_pc_buffers ()
1655
1648
self .following_heading_counter = 0
1656
1649
1657
- return hab_utils . quat_rotate_vector (
1650
+ return qt . rotate_vectors (
1658
1651
self .state ["agent_id_0" ]["rotation" ],
1659
1652
self .tangential_vec ,
1660
1653
)
@@ -1675,7 +1668,7 @@ def perform_pc_guided_step(self):
1675
1668
self .following_pc_counter += 1
1676
1669
self .continuous_pc_steps += 1
1677
1670
1678
- return hab_utils . quat_rotate_vector (
1671
+ return qt . rotate_vectors (
1679
1672
self .state ["agent_id_0" ]["rotation" ],
1680
1673
self .tangential_vec ,
1681
1674
)
@@ -1739,7 +1732,7 @@ def perform_standard_tang_step(self):
1739
1732
1740
1733
self .following_heading_counter += 1
1741
1734
1742
- return hab_utils . quat_rotate_vector (
1735
+ return qt . rotate_vectors (
1743
1736
self .state ["agent_id_0" ]["rotation" ],
1744
1737
self .tangential_vec ,
1745
1738
)
@@ -1895,10 +1888,9 @@ def avoid_revisiting_locations(
1895
1888
# locations to the headings (also in the reference frame of the agent) that
1896
1889
# we might take
1897
1890
# TODO could vectorize this
1898
- rotated_locs = [
1899
- hab_utils .quat_rotate_vector (inverse_quaternion_rotation , point )
1900
- for point in adjusted_prev_locs
1901
- ]
1891
+ rotated_locs = qt .rotate_vectors (
1892
+ inverse_quaternion_rotation , adjusted_prev_locs
1893
+ )
1902
1894
1903
1895
# Until we have not found a direction that we can guarentee is
1904
1896
# in a new heading, continue to attempt new directions
0 commit comments