Skip to content

Commit c95fd7c

Browse files
committed
fixed multiverse parser
1 parent c3f2238 commit c95fd7c

1 file changed

Lines changed: 28 additions & 24 deletions

File tree

src/semantic_world/adapters/multi_parser.py

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
JointBuilder, JointType)
1010
from pxr import UsdUrdf
1111

12-
from ..connections import RevoluteConnection, PrismaticConnection, FixedConnection
13-
from ..spatial_types.derivatives import Derivatives
12+
from ..connections import RevoluteConnection, PrismaticConnection, FixedConnection, UnitVector
13+
from ..spatial_types.derivatives import DerivativeMap
1414
from ..prefixed_name import PrefixedName
1515
from ..spatial_types import spatial_types as cas
1616
from ..world import World, Body, Connection
@@ -115,13 +115,13 @@ def parse_joints(self, body_builder: BodyBuilder, world: World) -> list[Connecti
115115
transform = body_builder.xform.GetLocalTransformation()
116116
pos = transform.ExtractTranslation()
117117
quat = transform.ExtractRotationQuat()
118-
origin = cas.TransformationMatrix.from_xyz_quat(pos_x=pos[0],
119-
pos_y=pos[1],
120-
pos_z=pos[2],
121-
quat_w=quat.GetReal(),
122-
quat_x=quat.GetImaginary()[0],
123-
quat_y=quat.GetImaginary()[1],
124-
quat_z=quat.GetImaginary()[2])
118+
point_expr = cas.Point3((pos[0], pos[1], pos[2]))
119+
quaternion_expr = cas.Quaternion((quat.GetImaginary()[0],
120+
quat.GetImaginary()[1],
121+
quat.GetImaginary()[2],
122+
quat.GetReal()))
123+
origin = cas.TransformationMatrix.from_point_rotation_matrix(point=point_expr,
124+
rotation_matrix=quaternion_expr.to_rotation_matrix())
125125
connection = FixedConnection(parent=parent_body, child=child_body, origin_expression=origin)
126126
connections.append(connection)
127127

@@ -132,13 +132,13 @@ def parse_joint(self, joint_builder: JointBuilder, parent_body: Body, child_body
132132
joint_name = joint_prim.GetName()
133133
joint_pos = joint_builder.pos
134134
joint_quat = joint_builder.quat
135-
origin = cas.TransformationMatrix.from_xyz_quat(pos_x=joint_pos[0],
136-
pos_y=joint_pos[1],
137-
pos_z=joint_pos[2],
138-
quat_w=joint_quat.GetReal(),
139-
quat_x=joint_quat.GetImaginary()[0],
140-
quat_y=joint_quat.GetImaginary()[1],
141-
quat_z=joint_quat.GetImaginary()[2])
135+
point_expr = cas.Point3((joint_pos[0], joint_pos[1], joint_pos[2]))
136+
quaternion_expr = cas.Quaternion((joint_quat.GetImaginary()[0],
137+
joint_quat.GetImaginary()[1],
138+
joint_quat.GetImaginary()[2],
139+
joint_quat.GetReal()))
140+
origin = cas.TransformationMatrix.from_point_rotation_matrix(point=point_expr,
141+
rotation_matrix=quaternion_expr.to_rotation_matrix())
142142
free_variable_name = PrefixedName(joint_name)
143143
offset = None
144144
multiplier = None
@@ -153,16 +153,20 @@ def parse_joint(self, joint_builder: JointBuilder, parent_body: Body, child_body
153153
elif joint_builder.type == JointType.FIXED:
154154
return FixedConnection(parent=parent_body, child=child_body, origin_expression=origin)
155155
elif joint_builder.type in [JointType.REVOLUTE, JointType.CONTINUOUS, JointType.PRISMATIC]:
156-
axis = (float(joint_builder.axis.to_array()[0]),
157-
float(joint_builder.axis.to_array()[1]),
158-
float(joint_builder.axis.to_array()[2]))
159-
if free_variable_name in world.degrees_of_freedom:
160-
dof = world.degrees_of_freedom[free_variable_name]
161-
else:
156+
axis = UnitVector(float(joint_builder.axis.to_array()[0]),
157+
float(joint_builder.axis.to_array()[1]),
158+
float(joint_builder.axis.to_array()[2]))
159+
try:
160+
dof = world.get_degree_of_freedom_by_name(free_variable_name)
161+
except KeyError:
162162
if joint_builder.type == JointType.CONTINUOUS:
163+
lower_limits = DerivativeMap()
164+
lower_limits.position = joint_builder.joint.GetLowerLimitAttr().Get()
165+
upper_limits = DerivativeMap()
166+
upper_limits.position = joint_builder.joint.GetUpperLimitAttr().Get()
163167
dof = world.create_degree_of_freedom(name=PrefixedName(joint_name),
164-
lower_limits={Derivatives.position: joint_builder.joint.GetLowerLimitAttr().Get()},
165-
upper_limits={Derivatives.position: joint_builder.joint.GetUpperLimitAttr().Get()})
168+
lower_limits=lower_limits,
169+
upper_limits=upper_limits)
166170
else:
167171
dof = world.create_degree_of_freedom(name=PrefixedName(joint_name))
168172
if joint_builder.type in [JointType.REVOLUTE, JointType.CONTINUOUS]:

0 commit comments

Comments
 (0)