test_launch.py
Go to the documentation of this file.
1 #! /usr/bin/env python
2 import roslib; roslib.load_manifest('openni_launch')
3 
4 import rospy
5 from sensor_msgs.msg import PointCloud2
6 import os
7 import subprocess
8 import shutil
9 import shlex
10 import tempfile
11 import signal
12 import time
13 
14 def callback(data, args):
15  args[0] = True
16 
17 rospy.init_node('test_sub')
18 
19 attempt = 0
20 successes = 0
21 failures = 0
22 consecutive_failures = 0
23 while not rospy.is_shutdown() and consecutive_failures < 5:
24  # Bind received flag and use new topic each time to be very sure results
25  # aren't affected by tardy callbacks
26  received = [False]
27  ns = "depth_reg_%d" % attempt
28  topic = "/camera/%s/points" % ns
29  attempt = attempt + 1
30  sub = rospy.Subscriber(topic, PointCloud2, callback, callback_args=received)
31 
32  command = "roslaunch openni_launch openni.launch depth_registered:=%s" % ns
33  #tmp = tempfile.TemporaryFile(mode='r+')
34  tmp = open(os.devnull, 'w')
35  p = subprocess.Popen(shlex.split(command), stdout=tmp, stderr=subprocess.STDOUT)
36  start = time.time()
37  end = start + 15.0
38  while (not rospy.is_shutdown()) and (time.time() < end) and (not received[0]):
39  time.sleep(0.1)
40  duration = time.time() - start
41 
42  sub.unregister()
43  p.send_signal(signal.SIGINT) # roslaunch will bring everything down
44  p.wait()
45 
46  if not rospy.is_shutdown():
47  if received[0]:
48  rospy.loginfo("Succeeded in %.1fs", duration)
49  successes = successes + 1
50  consecutive_failures = 0
51  status = "success"
52  else:
53  rospy.logerr("Failed!")
54  failures = failures + 1
55  consecutive_failures = consecutive_failures + 1
56  status = "fail"
57  if 0:
58  # Write out log
59  with open("%s_%05d.log" % (status, attempt), 'w') as f:
60  tmp.seek(0)
61  shutil.copyfileobj(tmp, f)
62  # Move core dump if present (would be at ~/.ros/core)
63  try:
64  core_name = "core_%d" % attempt
65  os.rename("core", core_name)
66  print("Core dump %s" % core_name)
67  except OSError:
68  pass
69 
70 print("Successes: %d" % successes)
71 print("Failures: %d" % failures)
test_launch.callback
def callback(data, args)
Definition: test_launch.py:14


openni_camera
Author(s): Patrick Mihelich, Suat Gedikli, Radu Bogdan Rusu
autogenerated on Thu Apr 21 2022 02:37:23