Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060 import roslib
00061 PKG = "srs_user_tests"
00062 roslib.load_manifest(PKG)
00063 import rospy
00064
00065 import rosbag
00066 from std_msgs.msg import Int32, String
00067
00068 import tf
00069 from tf.msg import *
00070 from tf.transformations import euler_from_quaternion
00071
00072 from simple_script_server import *
00073 sss = simple_script_server()
00074
00075 from kinematics_msgs.srv import *
00076 from std_msgs.msg import *
00077 from sensor_msgs.msg import *
00078 from move_base_msgs.msg import *
00079 from visualization_msgs.msg import *
00080
00081 import math
00082 import rostopic
00083 import time
00084
00085 import os
00086 import sys, subprocess
00087
00088 import joint_states_aggregator
00089 import tf_aggregator
00090
00091 import global_lock
00092
00093 class record_topic():
00094
00095 def __init__(self, topic_name, bagfile, continuous=False):
00096
00097 the_type = rostopic.get_topic_type(topic_name, blocking=True)[0]
00098
00099 the_type = the_type.split("/")
00100 the_type[0] += ".msg"
00101
00102
00103 mod = __import__(the_type[0], fromlist=[the_type[1]])
00104 cls = getattr( mod , the_type[1] )
00105
00106 self.msg = None
00107 self.topic_name = topic_name
00108 self.topic_type = cls
00109 self.continuous = continuous
00110 self.bagfile = bagfile
00111
00112
00113 rospy.Subscriber(self.topic_name, self.topic_type, self.callback)
00114 global_lock.locked = False
00115
00116 def lock(self):
00117 global_lock.locked = True
00118
00119 def unlock(self):
00120 global_lock.locked = False
00121
00122 def callback(self, msg):
00123 self.msg = msg
00124 if self.continuous:
00125 self.record()
00126
00127 def record(self):
00128 if(self.msg!=None):
00129 if not global_lock.locked:
00130 try:
00131 if(global_lock.active_bag):
00132 self.lock()
00133 self.bagfile.write(self.topic_name, self.msg)
00134 self.unlock()
00135 except KeyError, e:
00136 rospy.loginfo(self.msg)
00137
00138 if __name__ == "__main__":
00139
00140 rospy.init_node('record_topic')
00141 topics_list = ["/tf", "/collision_velocity_filter/velocity_limited_marker", "/joint_states"]
00142 topics_c = []
00143
00144 for top in topics_list:
00145 topic_r = record_topic(top)
00146
00147 topics_c.append(topic_r)
00148
00149 while not rospy.is_shutdown():
00150
00151 for tops_c in topics_c:
00152 rospy.loginfo(tops_c.msg)
00153 rospy.sleep(2)
00154