emulation_clock.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 import time
4 import rospy
5 from rosgraph_msgs.msg import Clock
6 
7 class EmulationClock(object):
8  def __init__(self):
9  self.t = time.time()
10  self.dt_ms = rospy.get_param('/emulation_dt_ms', 10)
11  self.time_factor = rospy.get_param('/emulation_time_factor', 1.0)
12  if not self.time_factor > 0.0:
13  rospy.logerr("emulation_time_factor must be >0.0, but is {}. exiting...".format(self.time_factor))
14  exit(-1)
15  self.pub = rospy.Publisher('/clock', Clock, queue_size=1)
16  rospy.Timer(rospy.Duration(self.dt_ms/1000.0), self.timer_cb)
17 
18  def timer_cb(self, event):
19  self.t+=self.time_factor*self.dt_ms/1000
20  msg = Clock()
21  msg.clock = rospy.Time(self.t)
22  self.pub.publish(msg)
23 
24 
25 if __name__ == '__main__':
26  rospy.init_node('emulation_clock', disable_rostime=True)
28  rospy.spin()


cob_hardware_emulation
Author(s): Florian Weisshardt
autogenerated on Thu Apr 8 2021 02:39:41