2
2
3
3
from pyrep .objects .shape import Shape
4
4
5
- from pyrep .backend import sim
5
+ from pyrep .backend import sim , utils
6
6
from pyrep .const import JointType
7
7
from pyrep .objects .object import Object
8
8
from pyrep .objects .joint import Joint
@@ -24,7 +24,6 @@ def __init__(self, count: int, name: str, joint_names: List[str],
24
24
self .joints = [Joint (jname + suffix )
25
25
for jname in joint_names ]
26
26
self ._joint_handles = [j .get_handle () for j in self .joints ]
27
- self ._config_tree = self .get_configuration_tree ()
28
27
29
28
def copy (self ) -> 'RobotComponent' :
30
29
"""Copy and pastes the arm in the scene.
@@ -76,21 +75,47 @@ def get_joint_positions(self) -> List[float]:
76
75
"""
77
76
return [j .get_joint_position () for j in self .joints ]
78
77
79
- def set_joint_positions (self , positions : List [float ]) -> None :
78
+ def set_joint_positions (self , positions : List [float ],
79
+ disable_dynamics : bool = False ) -> None :
80
80
"""Sets the intrinsic position of the joints.
81
81
82
82
See :py:meth:`Joint.set_joint_position` for more information.
83
83
84
+ :param disable_dynamics: If True, then the position can be set even
85
+ when the joint mode is in Force mode. It will disable dynamics,
86
+ move the joint, and then re-enable dynamics.
87
+
84
88
:param positions: A list of positions of the joints (angular or linear
85
89
values depending on the joint type).
86
90
"""
87
91
self ._assert_len (positions )
88
- sim .simSetConfigurationTree (self ._config_tree )
92
+ if not disable_dynamics :
93
+ [sim .simSetJointPosition (jh , p ) # type: ignore
94
+ for jh , p in zip (self ._joint_handles , positions )]
95
+ return
96
+
97
+ is_model = self .is_model ()
98
+ if not is_model :
99
+ self .set_model (True )
100
+
101
+ prior = sim .simGetModelProperty (self .get_handle ())
102
+ p = prior | sim .sim_modelproperty_not_dynamic
103
+ # Disable the dynamics
104
+ sim .simSetModelProperty (self ._handle , p )
105
+ with utils .step_lock :
106
+ sim .simExtStep (True ) # Have to step for changes to take effect
107
+
89
108
[sim .simSetJointPosition (jh , p ) # type: ignore
90
109
for jh , p in zip (self ._joint_handles , positions )]
91
- [j .set_joint_target_position (p )
110
+ [j .set_joint_target_position (p ) # type: ignore
92
111
for j , p in zip (self .joints , positions )]
93
112
113
+ # Re-enable the dynamics
114
+ sim .simSetModelProperty (self ._handle , prior )
115
+ self .set_model (is_model )
116
+ with utils .step_lock :
117
+ sim .simExtStep (True ) # Have to step for changes to take effect
118
+
94
119
def get_joint_target_positions (self ) -> List [float ]:
95
120
"""Retrieves the target positions of the joints.
96
121
0 commit comments