ros_time_rate.py
Go to the documentation of this file.
00001 
00002 #
00003 # Display ratio between ROS time and system-time.
00004 # using curses to avoid scrolling but still keep things terminal
00005 # based.
00006 #
00007 ## author: Advait Jain
00008 
00009 
00010 import sys, time
00011 import curses
00012 import numpy as np, math
00013 import threading
00014 
00015 import roslib; roslib.load_manifest('hrl_lib')
00016 import rospy
00017 
00018 class ROSTimeRate(threading.Thread):
00019     def __init__(self):
00020         threading.Thread.__init__(self)
00021         self.rt = -1
00022         self.start()
00023 
00024     def run(self):
00025         prev_sim_time = rospy.get_time()
00026         prev_sys_time = time.time()
00027         while not rospy.is_shutdown():
00028             time.sleep(0.1)
00029             sim_time = rospy.get_time()
00030             sys_time = time.time()
00031             self.rt = (sim_time-prev_sim_time) / (sys_time-prev_sys_time)
00032             prev_sim_time = sim_time
00033             prev_sys_time = sys_time
00034 
00035     def get_rate(self):
00036         return self.rt
00037 
00038 
00039 if __name__ == '__main__':
00040     rospy.init_node('ros_time_rate_printer')
00041     
00042     rtr = ROSTimeRate()
00043 
00044     stdscr = curses.initscr()
00045     curses.start_color()
00046     curses.noecho()
00047     curses.cbreak()
00048     stdscr.keypad(1)
00049 
00050     row, col = 1, 2
00051 
00052     while not rospy.is_shutdown():
00053         rt = rtr.get_rate()
00054         stdscr.clear()
00055         msg = 'ROS time is %.2f x real-time'%rt
00056         stdscr.addstr(row, col, msg)
00057         stdscr.refresh()
00058         time.sleep(0.1)
00059 
00060     #------ gracefully exit curses? --------
00061     curses.nocbreak();
00062     stdscr.keypad(0);
00063     curses.echo()
00064     curses.endwin()
00065 
00066 
00067 
00068 
00069 


hrl_lib
Author(s): Cressel Anderson, Travis Deyle, Advait Jain, Hai Nguyen, Advisor: Prof. Charlie Kemp, Lab: Healthcare Robotics Lab at Georgia Tech
autogenerated on Wed Nov 27 2013 11:34:06