Go to the documentation of this file.00001 
00002 
00003 import roslib
00004 roslib.load_manifest( 'tf' )
00005 roslib.load_manifest( 'hrl_lib' )
00006 import rospy
00007 
00008 import tf
00009 from hrl_lib.cmd_process import CmdProcess
00010 
00011 from threading import Thread
00012 import time
00013 
00014 
00015 def bagplay( fname ):
00016     
00017     
00018     
00019     
00020     
00021     
00022     cmd = 'rosbag play --clock ' + fname + ' -r 2.0 -q'
00023     rospy.logout( 'Launching bag file: %s' % fname )
00024     return CmdProcess( cmd.split() )
00025 
00026 
00027 def sim_safe_sleep( dur, real_time_sleep = 0.05 ):
00028     t0 = rospy.Time.now().to_sec()
00029     ct = rospy.Time.now().to_sec()
00030     while True:
00031         if ct - t0 >= dur:
00032             break
00033 
00034         time.sleep( real_time_sleep )
00035         nt = rospy.Time.now().to_sec()
00036 
00037         if nt == ct: 
00038             break  
00039         
00040         ct = nt
00041     return
00042 
00043 class TFthread( Thread ):
00044     
00045     
00046     
00047     
00048     
00049     
00050     
00051     
00052     
00053     
00054     
00055     
00056     def __init__( self, d ):
00057         self.d = d
00058         Thread.__init__( self )
00059         
00060         
00061         
00062 
00063         self.bc = tf.TransformBroadcaster()
00064 
00065         self.should_run = True
00066         self.start()
00067 
00068     def run( self ):
00069         rospy.logout( 'TFthread: Starting %s ' % self.d[ 'child_frame' ] )
00070         while self.should_run and not rospy.is_shutdown():
00071             self.bc.sendTransform( ( self.d[ 'x_pos' ],
00072                                      self.d[ 'y_pos' ],
00073                                      self.d[ 'z_pos' ] ),
00074                                    ( self.d[ 'x_orient' ],
00075                                      self.d[ 'y_orient' ],
00076                                      self.d[ 'z_orient' ],
00077                                      self.d[ 'w_orient' ] ),
00078                                    rospy.Time.now(),
00079                                    self.d[ 'child_frame' ],
00080                                    self.d[ 'parent_frame' ] )
00081 
00082             try:
00083                 sim_safe_sleep( 0.10 )  
00084             except:
00085                 pass 
00086         rospy.logout( 'TFthread: Stopping %s ' % self.d[ 'child_frame' ] )
00087         
00088     def stop( self ):
00089         
00090         self.should_run = False
00091         self.join(5)
00092         if (self.isAlive()):
00093             raise RuntimeError('TFthread: Unable to stop thread %s ' % self.d[ 'child_frame' ] )