4 from std_msgs.msg
import Bool
5 from rtabmap_ros.msg
import Goal
7 pub = rospy.Publisher(
'rtabmap/goal_node', Goal, queue_size=1)
18 rospy.loginfo(rospy.get_caller_id() +
": Goal '%s' reached! Publishing next goal in %.1f sec...", waypoints[currentIndex], waitingTime)
20 rospy.loginfo(rospy.get_caller_id() +
": Goal '%s' failed! Publishing next goal in %.1f sec...", waypoints[currentIndex], waitingTime)
22 currentIndex = (currentIndex+1) % len(waypoints)
25 rospy.sleep(waitingTime)
28 msg.frame_id = frameId
30 int(waypoints[currentIndex])
35 msg.node_id = int(waypoints[currentIndex])
39 msg.node_label = waypoints[currentIndex]
41 rospy.loginfo(rospy.get_caller_id() +
": Publishing goal '%s'! (%d/%d)", waypoints[currentIndex], currentIndex+1, len(waypoints))
42 msg.header.stamp = rospy.get_rostime()
46 rospy.init_node(
'patrol', anonymous=
False)
47 sub = rospy.Subscriber(
"rtabmap/goal_reached", Bool, callback)
50 waitingTime = rospy.get_param(
'~time', waitingTime)
51 frameId = rospy.get_param(
'~frame_id', frameId)
54 rospy.loginfo(rospy.get_caller_id() +
": Waypoints: [%s]", str(waypoints).strip(
'[]'))
55 rospy.loginfo(rospy.get_caller_id() +
": time: %f", waitingTime)
56 rospy.loginfo(rospy.get_caller_id() +
": publish goal on %s", pub.resolved_name)
57 rospy.loginfo(rospy.get_caller_id() +
": receive goal status on %s", sub.resolved_name)
61 msg.frame_id = frameId
63 int(waypoints[currentIndex])
68 msg.node_id = int(waypoints[currentIndex])
72 msg.node_label = waypoints[currentIndex]
73 while rospy.Time.now().secs == 0:
74 rospy.loginfo(rospy.get_caller_id() +
": Waiting clock...")
76 msg.header.stamp = rospy.Time.now()
77 rospy.loginfo(rospy.get_caller_id() +
": Publishing goal '%s'! (%d/%d)", waypoints[currentIndex], currentIndex+1, len(waypoints))
81 if __name__ ==
'__main__':
83 print(
"usage: patrol.py waypointA waypointB waypointC ... [_time:=1 frame_id:=base_footprint] [topic remaps] (at least 2 waypoints, can be node id, landmark or label)")
85 waypoints = sys.argv[1:]
86 waypoints = [x
for x
in waypoints
if not x.startswith(
'/')
and not x.startswith(
'_')]