|
27 | 27 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
28 | 28 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
29 | 29 | # POSSIBILITY OF SUCH DAMAGE. |
30 | | - |
| 30 | +import collections |
31 | 31 | import functools, logging, openravepy, numpy |
32 | 32 | from .. import bind, named_config, exceptions, util |
33 | 33 | from ..clone import Clone, Cloned |
|
42 | 42 |
|
43 | 43 |
|
44 | 44 | class Robot(openravepy.Robot): |
| 45 | + |
| 46 | + _postprocess_envs = collections.defaultdict(openravepy.Environment) |
| 47 | + """ |
| 48 | + Mapping from robot environments to plan postprocessing environments. |
| 49 | + """ |
| 50 | + |
45 | 51 | def __init__(self, robot_name=None): |
46 | 52 | self.actions = None |
47 | 53 | self.planner = None |
@@ -74,6 +80,13 @@ def __init__(self, robot_name=None): |
74 | 80 | self.smoother = self.retimer |
75 | 81 | self.affine_retimer = OpenRAVEAffineRetimer() |
76 | 82 |
|
| 83 | + # Since we don't want to endlessly create postprocessing environments, |
| 84 | + # we maintain a map that uniquely associates each OpenRAVE environment |
| 85 | + # with a given postprocessing environment. This way, if we re-clone |
| 86 | + # into a previously used environment, we will not create a new one. |
| 87 | + self._postprocess_env = Robot._postprocess_envs[ |
| 88 | + openravepy.RaveGetEnvironmentId(self.GetEnv())] |
| 89 | + |
77 | 90 | def __dir__(self): |
78 | 91 | # We have to manually perform a lookup in InstanceDeduplicator because |
79 | 92 | # __methods__ bypass __getattribute__. |
@@ -165,6 +178,7 @@ def CloneBindings(self, parent): |
165 | 178 | self.base_manipulation = openravepy.interfaces.BaseManipulation(self) |
166 | 179 | self.task_manipulation = openravepy.interfaces.TaskManipulation(self) |
167 | 180 |
|
| 181 | + |
168 | 182 | def AttachController(self, name, args, dof_indices, affine_dofs, simulated): |
169 | 183 | """ |
170 | 184 | Create and attach a controller to a subset of this robot's DOFs. If |
@@ -286,11 +300,6 @@ def PostProcessPath(self, path, |
286 | 300 | logger.debug('Detected "%s" tag on trajectory: Setting smooth' |
287 | 301 | ' = True', Tags.SMOOTH) |
288 | 302 |
|
289 | | - # Lazily create an environment for post-processing. |
290 | | - # This is faster than creating a new environment for every operation. |
291 | | - if not hasattr(self, '_postprocess_env'): |
292 | | - self._postprocess_env = openravepy.Environment() |
293 | | - |
294 | 303 | with Clone(self.GetEnv(), |
295 | 304 | clone_env=self._postprocess_env) as cloned_env: |
296 | 305 | cloned_robot = cloned_env.Cloned(self) |
|
0 commit comments