Hello,
Is there a ropsy scheduler for calling a function after a period of time (or periodically calling it every n secs). The python sched module is kind of misbehaving, I guess it conflicts with ros based on the following example using the ps joystick with the PR2:
#!/usr/bin/env python
import roslib; roslib.load_manifest('d3')
import rospy
import sched, time
from sensor_msgs.msg import Joy
class Joystick(object):
def __init__(self, topic_name='/joy'):
self.topic_name = topic_name
self.buttons_names = {'l1':10, 'l2':8}
self.sub = rospy.Subscriber(topic_name, Joy, self.cb)
self.blocked = False
self.sched = sched.scheduler(time.time, time.sleep)
print '>>> press L1 button'
def cb(self, data):
print '>> in callback:', data.buttons[self.buttons_names['l1']], data.buttons[self.buttons_names['l2']]
if not self.blocked:
self.foo(data)
def foo(self, data):
print '>> in foo:', data.buttons[self.buttons_names['l1']], data.buttons[self.buttons_names['l2']]
if data.buttons[self.buttons_names['l1']]:
self.blocked = True
rospy.loginfo('%d', data.buttons[self.buttons_names['l1']])
rospy.loginfo('L1 pressed')
self.sched.enter(1, 1, self.bar, ())
self.sched.run()
def bar(self):
rospy.loginfo('resuming control')
self.blocked = False
if __name__=='__main__':
rospy.init_node('foo', anonymous=False)
joy = Joystick()
rospy.spin()
Thanks!
Originally posted by Yianni on ROS Answers with karma: 123 on 2012-06-01
Post score: 2