Skip to content

Commit 186dcf6

Browse files
committed
[ci skip] set_joint_positions bug fix.
1 parent e07df8c commit 186dcf6

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

pyrep/objects/joint.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class Joint(Object):
1414

1515
def __init__(self, name_or_handle: Union[str, int]):
1616
super().__init__(name_or_handle)
17+
self._config_tree = self.get_configuration_tree()
1718

1819
def _get_requested_type(self) -> ObjectType:
1920
return ObjectType.JOINT
@@ -42,12 +43,9 @@ def set_joint_position(self, position: float) -> None:
4243
:param positions: A list of positions of the joints (angular or linear
4344
values depending on the joint type).
4445
"""
45-
46-
prev_mode = self.get_joint_mode()
47-
self.set_joint_mode(JointMode.IK)
46+
sim.simSetConfigurationTree(self._config_tree)
4847
sim.simSetJointPosition(self._handle, position)
4948
self.set_joint_target_position(position)
50-
self.set_joint_mode(prev_mode)
5149

5250
def get_joint_target_position(self) -> float:
5351
"""Retrieves the target position of a joint.

pyrep/robots/robot_component.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ def __init__(self, count: int, name: str, joint_names: List[str],
2323
# Joint handles
2424
self.joints = [Joint(jname + suffix)
2525
for jname in joint_names]
26+
self._joint_handles = [j.get_handle() for j in self.joints]
27+
self._config_tree = self.get_configuration_tree()
2628

2729
def copy(self) -> 'RobotComponent':
2830
"""Copy and pastes the arm in the scene.
@@ -83,14 +85,11 @@ def set_joint_positions(self, positions: List[float]) -> None:
8385
values depending on the joint type).
8486
"""
8587
self._assert_len(positions)
86-
87-
prev_mode = self.get_joint_modes()
88-
self.set_joint_mode(JointMode.IK)
89-
[j.set_joint_position(p) # type: ignore
90-
for j, p in zip(self.joints, positions)]
91-
[j.set_joint_target_position(p) # type: ignore
88+
sim.simSetConfigurationTree(self._config_tree)
89+
[sim.simSetJointPosition(jh, p) # type: ignore
90+
for jh, p in zip(self._joint_handles, positions)]
91+
[j.set_joint_target_position(p)
9292
for j, p in zip(self.joints, positions)]
93-
self.set_joint_mode(prev_mode[0])
9493

9594
def get_joint_target_positions(self) -> List[float]:
9695
"""Retrieves the target positions of the joints.

0 commit comments

Comments
 (0)