barDetectChanger.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # coding: UTF-8
3 import roslib
4 import rospy
5 from geometry_msgs.msg import Twist
6 from math import radians, pi
7 from std_msgs.msg import Bool
9 
10  def __init__(self):
11  rospy.init_node('BarDetectChanger', anonymous=False)
12  rospy.on_shutdown(self.shutdown)
13  bar_disabled = rospy.get_param("~barDetectFlag", 1.0)
14 
15  # 发布TWist消息控制机器人
16  self.cmd_vel_pub = rospy.Publisher('cmd_vel', Twist, queue_size=1)
17  self.barDetectFlag_pub = rospy.Publisher('/xiaoqiang_driver/infrared_sensor', Bool, queue_size=1)
18  if bar_disabled == 1 :
19  return
20  rospy.loginfo("Stopping the robot...")
21  # Stop the robot
22  self.cmd_vel_pub.publish(Twist())
23 
24  rospy.loginfo("disable BarDetectFlag")
25  r = rospy.Rate(1) # 1hz
26  while not rospy.is_shutdown():
27  flag=Bool()
28  flag.data=False
29  self.barDetectFlag_pub.publish(flag) # disable BarDetectFlag
30  r.sleep()
31 
32 
33  def shutdown(self):
34  rospy.loginfo("Stopping the robot...")
35  # Stop the robot
36  self.cmd_vel_pub.publish(Twist())
37  rospy.loginfo("enable BarDetectFlag")
38  # enable BarDetectFlag
39  flag=Bool()
40  flag.data=True
41  self.barDetectFlag_pub.publish(flag)
42  rospy.sleep(0.5)
43 
44 if __name__ == '__main__':
45  try:
47  except rospy.ROSInterruptException:
48  rospy.loginfo("BarDetectChanger finished.")


xiaoqiang_navigation_example
Author(s):
autogenerated on Mon Jun 10 2019 15:53:36