frontier_opencv_detector.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 
4 #--------Include modules---------------
5 import rospy
6 from visualization_msgs.msg import Marker
7 from nav_msgs.msg import OccupancyGrid
8 from geometry_msgs.msg import PointStamped
9 from getfrontier import getfrontier
10 
11 #-----------------------------------------------------
12 # Subscribers' callbacks------------------------------
13 mapData=OccupancyGrid()
14 
15 
16 def mapCallBack(data):
17  global mapData
18  mapData=data
19 
20 
21 
22 
23 # Node----------------------------------------------
24 def node():
25  global mapData
26  exploration_goal=PointStamped()
27  map_topic= rospy.get_param('~map_topic','/robot_1/map')
28  rospy.Subscriber(map_topic, OccupancyGrid, mapCallBack)
29  targetspub = rospy.Publisher('/detected_points', PointStamped, queue_size=10)
30  pub = rospy.Publisher('shapes', Marker, queue_size=10)
31  rospy.init_node('detector', anonymous=False)
32 # wait until map is received, when a map is received, mapData.header.seq will not be < 1
33  while mapData.header.seq<1 or len(mapData.data)<1:
34  pass
35 
36  rate = rospy.Rate(50)
37  points=Marker()
38 
39  #Set the frame ID and timestamp. See the TF tutorials for information on these.
40  points.header.frame_id=mapData.header.frame_id
41  points.header.stamp=rospy.Time.now()
42 
43  points.ns= "markers"
44  points.id = 0
45 
46  points.type = Marker.POINTS
47  #Set the marker action. Options are ADD, DELETE, and new in ROS Indigo: 3 (DELETEALL)
48  points.action = Marker.ADD;
49 
50  points.pose.orientation.w = 1.0;
51  points.scale.x=points.scale.y=0.3;
52  points.color.r = 255.0/255.0
53  points.color.g = 0.0/255.0
54  points.color.b = 0.0/255.0
55  points.color.a=1;
56  points.lifetime == rospy.Duration();
57 
58 #-------------------------------OpenCV frontier detection------------------------------------------
59  while not rospy.is_shutdown():
60  frontiers=getfrontier(mapData)
61  for i in range(len(frontiers)):
62  x=frontiers[i]
63  exploration_goal.header.frame_id= mapData.header.frame_id
64  exploration_goal.header.stamp=rospy.Time(0)
65  exploration_goal.point.x=x[0]
66  exploration_goal.point.y=x[1]
67  exploration_goal.point.z=0
68 
69 
70  targetspub.publish(exploration_goal)
71  points.points=[exploration_goal.point]
72  pub.publish(points)
73  rate.sleep()
74 
75 
76 
77  #rate.sleep()
78 
79 
80 
81 #_____________________________________________________________________________
82 
83 if __name__ == '__main__':
84  try:
85  node()
86  except rospy.ROSInterruptException:
87  pass
88 
89 
90 
91 


rrt_exploration
Author(s): Hassan Umari
autogenerated on Mon Jun 10 2019 14:57:44