|
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
|
@@ -165,6 +171,7 @@ def CloneBindings(self, parent):
|
165 | 171 | self.base_manipulation = openravepy.interfaces.BaseManipulation(self)
|
166 | 172 | self.task_manipulation = openravepy.interfaces.TaskManipulation(self)
|
167 | 173 |
|
| 174 | + |
168 | 175 | def AttachController(self, name, args, dof_indices, affine_dofs, simulated):
|
169 | 176 | """
|
170 | 177 | Create and attach a controller to a subset of this robot's DOFs. If
|
@@ -286,13 +293,15 @@ def PostProcessPath(self, path,
|
286 | 293 | logger.debug('Detected "%s" tag on trajectory: Setting smooth'
|
287 | 294 | ' = True', Tags.SMOOTH)
|
288 | 295 |
|
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() |
| 296 | + # Since we don't want to endlessly create postprocessing environments, |
| 297 | + # we maintain a map that uniquely associates each OpenRAVE environment |
| 298 | + # with a given postprocessing environment. This way, if we re-clone |
| 299 | + # into a previously used environment, we will not create a new one. |
| 300 | + postprocess_env = Robot._postprocess_envs[ |
| 301 | + openravepy.RaveGetEnvironmentId(self.GetEnv())] |
293 | 302 |
|
294 | 303 | with Clone(self.GetEnv(),
|
295 |
| - clone_env=self._postprocess_env) as cloned_env: |
| 304 | + clone_env=postprocess_env) as cloned_env: |
296 | 305 | cloned_robot = cloned_env.Cloned(self)
|
297 | 306 |
|
298 | 307 | # Planners only operate on the active DOFs. We'll set any DOFs
|
|
0 commit comments