Skip to content

Commit f4774d8

Browse files
committed
Adding tags for capturing trajectory timing data
1 parent 23f59e4 commit f4774d8

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

src/prpy/base/robot.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,16 @@
2828
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2929
# POSSIBILITY OF SUCH DAMAGE.
3030

31-
import functools, logging, openravepy, numpy
31+
import functools, logging, openravepy, numpy, time
3232
import prpy.util
3333
from .. import bind, named_config, planning, util
3434
from ..clone import Clone, Cloned
3535
from ..tsr.tsrlibrary import TSRLibrary
36-
from ..planning.base import Sequence
36+
from ..planning.base import Sequence, Tags
3737
from ..planning.ompl import OMPLSimplifier
3838
from ..planning.retimer import HauserParabolicSmoother, OpenRAVEAffineRetimer, ParabolicRetimer
3939
from ..planning.mac_smoother import MacSmoother
40+
from ..util import CopyTrajectory, GetTrajectoryTags, SetTrajectoryTags, TagTrajectoryTiming
4041

4142
logger = logging.getLogger('robot')
4243

@@ -377,6 +378,7 @@ def do_execute():
377378

378379
with Timer() as timer:
379380
traj = self.PostProcessPath(path, defer=False, **kwargs)
381+
TagTrajectoryTiming(traj, Tags.POSTPROCESS_TIME, timer.get_duration())
380382

381383
logger.info('Post-processing took %.3f seconds and produced a path'
382384
' with %d waypoints and a duration of %.3f seconds.',
@@ -385,7 +387,10 @@ def do_execute():
385387
traj.GetDuration()
386388
)
387389

388-
return self.ExecuteTrajectory(traj, defer=False, **kwargs)
390+
with Timer() as timer:
391+
exec_traj = self.ExecuteTrajectory(traj, defer=False, **kwargs)
392+
TagTrajectoryTiming(exec_traj, Tags.EXECUTION_TIME, timer.get_duration())
393+
return exec_traj
389394

390395
if defer is True:
391396
from trollius.executor import get_default_executor
@@ -541,7 +546,10 @@ def _PlanWrapper(self, planning_method, args, kw_args):
541546
config_spec = self.GetActiveConfigurationSpecification('linear')
542547

543548
# Call the planner.
544-
result = planning_method(self, *args, **kw_args)
549+
from ..util import Timer
550+
with Timer() as timer:
551+
result = planning_method(self, *args, **kw_args)
552+
TagTrajectoryTiming(result, Tags.PLAN_TIME, timer.get_duration())
545553

546554
def postprocess_trajectory(traj):
547555
# Strip inactive DOFs from the trajectory.

src/prpy/planning/base.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ class Tags(object):
4343
CONSTRAINED = 'constrained'
4444
PLANNER = 'planner'
4545
METHOD = 'planning_method'
46+
PLAN_TIME = 'planning_time'
47+
POSTPROCESS_TIME = 'postprocess_time'
48+
EXECUTION_TIME = 'execution_time'
4649

4750
class PlanningError(Exception):
4851
pass

src/prpy/util.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -693,3 +693,14 @@ def FindCatkinResource(package, relative_path):
693693
else:
694694
raise IOError('Loading resource "{:s}" failed.'.format(
695695
relative_path))
696+
697+
def TagTrajectoryTiming(traj, tag, timedata):
698+
"""
699+
Tag a trajectory with timing metadata
700+
@param traj The trajectory to tag
701+
@param tag The name of the tag to add
702+
@param timedata The timing data to put in the tag (usually time in seconds)
703+
"""
704+
tags = GetTrajectoryTags(traj)
705+
tags.setdefault(tag, timedata)
706+
SetTrajectoryTags(traj, tags, append=False)

0 commit comments

Comments
 (0)