cmd_vel_mux.py
Go to the documentation of this file.
1 #!/usr/bin/python
2 
3 import rospy
4 import time
5 
6 from geometry_msgs.msg import Twist
7 
8 class CmdVelMux:
9  def __init__(self):
10  self.pub = rospy.Publisher("cmd_vel", Twist, queue_size=10)
11  rospy.Subscriber("move_base/cmd_vel", Twist, callback=self.on_autonomous_cmd)
12  rospy.Subscriber("teleop/cmd_vel", Twist, callback=self.on_human_cmd)
13  self.block_duration = 0
14  self.human_cmd_time = time.time()
15 
16  def on_autonomous_cmd(self, twist):
17  time_since_human_cmd = time.time() - self.human_cmd_time
18  if time_since_human_cmd >= self.block_duration:
19  self.block_duration = 0 # stop blocking
20  self.pub.publish(twist)
21 
22  def on_human_cmd(self, twist):
23  self.human_cmd_time = time.time()
24  self.block_duration = rospy.get_param('~block_duration', 5) # to get the lowest latency, comment this or hard code this so that there is no call to rospy.get_param
25  self.pub.publish(twist)
26 
27 def main():
28  rospy.init_node("cmd_vel_mux")
29  muxer = CmdVelMux()
30  rospy.spin()
def on_autonomous_cmd(self, twist)
Definition: cmd_vel_mux.py:16


simple_drive
Author(s): Daniel Snider , Matthew Mirvish
autogenerated on Mon Jun 10 2019 15:05:01