Skip to content

Commit b5eeeca

Browse files
[BugFix] Fixed joints inferred angle (#127)
1 parent aa1e02a commit b5eeeca

File tree

2 files changed

+10
-21
lines changed

2 files changed

+10
-21
lines changed

vmas/simulator/core.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2095,7 +2095,7 @@ def _apply_vectorized_enviornment_force(self):
20952095
frozenset({entity_a.name, entity_b.name}), None
20962096
)
20972097
if joint is not None:
2098-
joints.append((entity_a, entity_b, joint))
2098+
joints.append(joint)
20992099
if joint.dist == 0:
21002100
continue
21012101
if not self.collides(entity_a, entity_b):
@@ -2187,7 +2187,9 @@ def _vectorized_joint_constraints(self, joints):
21872187
rot_a = []
21882188
rot_b = []
21892189
joint_rot = []
2190-
for entity_a, entity_b, joint in joints:
2190+
for joint in joints:
2191+
entity_a = joint.entity_a
2192+
entity_b = joint.entity_b
21912193
pos_joint_a.append(joint.pos_point(entity_a))
21922194
pos_joint_b.append(joint.pos_point(entity_b))
21932195
pos_a.append(entity_a.state.pos)
@@ -2257,12 +2259,12 @@ def _vectorized_joint_constraints(self, joints):
22572259
rotate, torque_b_rotate, torque_b_rotate + torque_b_fixed
22582260
)
22592261

2260-
for i, (entity_a, entity_b, _) in enumerate(joints):
2262+
for i, joint in enumerate(joints):
22612263
self.update_env_forces(
2262-
entity_a,
2264+
joint.entity_a,
22632265
force_a[:, i],
22642266
torque_a[:, i],
2265-
entity_b,
2267+
joint.entity_b,
22662268
force_b[:, i],
22672269
torque_b[:, i],
22682270
)
@@ -2828,12 +2830,7 @@ def _get_constraint_torques(
28282830
k = 1
28292831
penetration = k * (torch.exp(abs_delta_rot / k) - 1)
28302832

2831-
torque = (
2832-
force_multiplier
2833-
* delta_rot
2834-
/ torch.where(abs_delta_rot > 0, abs_delta_rot, 1e-8)
2835-
* penetration
2836-
)
2833+
torque = force_multiplier * delta_rot.sign() * penetration
28372834
torque = torch.where((abs_delta_rot < min_delta_rot), 0.0, torque)
28382835

28392836
return -torque, torque

vmas/simulator/joints.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -138,17 +138,9 @@ def notify(self, observable, *args, **kwargs):
138138

139139
# If we do not allow rotation, and we did not provide a fixed rotation value, we infer it
140140
if not self.rotate_a and self.fixed_rotation_a is None:
141-
self.joint_constraints[0].fixed_rotation = torch.where(
142-
angle >= 0,
143-
angle - self.entity_a.state.rot,
144-
-angle + self.entity_a.state.rot,
145-
)
141+
self.joint_constraints[0].fixed_rotation = angle - self.entity_a.state.rot
146142
if not self.rotate_b and self.fixed_rotation_b is None:
147-
self.joint_constraints[1].fixed_rotation = torch.where(
148-
angle >= 0,
149-
angle - self.entity_b.state.rot,
150-
-angle + self.entity_b.state.rot,
151-
)
143+
self.joint_constraints[1].fixed_rotation = angle - self.entity_b.state.rot
152144

153145

154146
# Private class: do not instantiate directly

0 commit comments

Comments
 (0)