FeatureExtractorROSE2.py
Go to the documentation of this file.
1 #! /usr/bin/env python
2 import rospy
3 from rose2.msg import ROSEFeatures
4 from rose2.msg import ROSE2Features
5 from jsk_recognition_msgs.msg import PolygonArray
6 import rose2.srv
7 from util import MsgUtils as mu
8 from rose_v2_repo import minibatch, parameters
9 from visualization_msgs.msg import Marker
10 from visualization_msgs.msg import MarkerArray
11 import warnings
12 """
13 Subscribers: /features_ROSE (rose2/ROSEFeatures)
14 Publishers: /features_ROSE2 (rose2/ROSE2Features)
15  /extended_lines (visualization_msgs/Marker)
16  /edges (visualization_msgs/MarkerArray)
17  /rooms (jsk_recognition_msgs/PolygonArray)
18 Service: /features_ROSESrv (nav_msgs/ROSE2Features)
19 params: /pub_once -> publish once or or keep publishing at a certain rate
20  #rose2 PARAMS
21  /spatialClusteringLineSegmentsThreshold
22  /lines_th1 #real number 0 to 1 (0 keeps all the lines)
23  /lines_distance
24  /edges_th #real number 0 to 1
25  #voronoi params
26  #find more rooms with voronoi method (slower)
27  /rooms_voronoi -> True if you want to use this method
28  /filepath
29  /voronoi_closeness
30  /voronoi_blur
31  /voronoi_iterations
32 
33 This node has to be started after ROSE node (with param pub_once=True) which gives a filtered map and its main directions.
34 ROSE2 node applies ROSE2 method to the filtered map, finds walls and rooms of the map.
35 After computing the result, ROSE2 publishes ROSE2Features: edges, extended lines, rooms and contours
36 
37 """
39  def __init__(self):
40  rospy.init_node('ROSE2')
41  rospy.loginfo("[ROSE2] waiting for features...")
42 
43 
44  self.pubOnce = rospy.get_param("ROSE/pub_once2", True)
45  self.spatialClusteringLineSegmentsThreshold = rospy.get_param("ROSE/spatialClusteringLineSegmentsThreshold", 5)
46  #extended lines parameters
47  self.lines_th1 = rospy.get_param("ROSE/lines_th1", 0.1)
48  self.distance_extended_segment = rospy.get_param("ROSE/lines_distance", 20)
49  # Edges parameters
50  self.threshold_edges = rospy.get_param("ROSE/edges_th", 0.1)
51  #voronoi params
52  self.rooms_voronoi = rospy.get_param("ROSE/rooms_voronoi", False)
53  self.filepath = rospy.get_param("ROSE/filepath", None)
54  self.voronoi_closeness = rospy.get_param("ROSE/voronoi_closeness", 10)
55  self.blur = rospy.get_param("ROSE/voronoi_blur", 8)
56  self.iterations = rospy.get_param("ROSE/voronoi_iterations", 5)
57 
58  #store ros params into param obj
60  self.param_obj.voronoi_closeness = self.voronoi_closeness
61  self.param_obj.blur = self.blur
62  self.param_obj.iterations = self.iterations
63  self.param_obj.spatialClusteringLineSegmentsThreshold = self.spatialClusteringLineSegmentsThreshold
64  self.param_obj.distance_extended_segment = self.distance_extended_segment
65  self.param_obj.th1 = self.lines_th1
66  self.param_obj.threshold_edges = self.threshold_edges
67 
68  #features storing variables
69  self.features = None #rose2/ROSEFeatures
70  self.features2 = None #rose2/ROSE2Features
71  self.cleanMap = None #np.array
72  self.originalOccMap = None #np.array
73  self.origin = None #map origin
74  self.res = None #map res
75 
76  self.pubRate = 1
77 
78  #Flow control variables
79  self.publish = False # True if this node has new features to publish
80 
81  #SUBSCRIBER
82  rospy.Subscriber('features_ROSE', ROSEFeatures, self.processMap, queue_size=1, buff_size=2 ** 29)
83 
84  #PUBLISHERS
85  self.pubFeatures = rospy.Publisher('features_ROSE2', ROSE2Features, queue_size=1)
86  self.pubLines = rospy.Publisher('extended_lines', Marker, queue_size=1)
87  self.pubEdges = rospy.Publisher('edges', MarkerArray, queue_size=1)
88  self.pubRooms = rospy.Publisher('rooms', PolygonArray, queue_size=1)
89 
90  #Service
91  rospy.Service('ROSE2Srv', rose2.srv.ROSE2, self.featuresSrv)
92 
93 
94 
95  def run(self):
96  r = rospy.Rate(self.pubRate)
97  while not rospy.is_shutdown():
98  if self.publish:
99  self.publishFeatures()
100  if self.pubOnce:
101  self.publish = False
102  r.sleep()
103 
104  #CALLBACK
105  def processMap(self, features):
106  self.features = features
107  self.cleanMap = mu.fromOccupancyGridRawToImg(features.cleanMap)
108  self.originalMap = mu.fromOccupancyGridToImg(features.originalMap)
109  self.directions = list(features.directions)
110  self.param_obj.comp = self.directions
112  self.rose2.start_main(parameters, self.param_obj, self.cleanMap, self.originalMap, self.filepath, self.rooms_voronoi)
113  self.makeFeaturesMsg()
114  self.publish = True
115  rospy.loginfo('[ROSE2] publishing edges, lines, contour and rooms')
116 
117  #SERVICE RESPONSE
118  def featuresSrv(self, features):
119  if(self.publish is False):
120  self.processMap(features)
121  return self.features2
122 
123  def makeFeaturesMsg(self):
124  self.line_markers = Marker()
125  self.edge_markers = MarkerArray()
126  self.room_polygons = PolygonArray()
127  edgesRviz = []
128  roomsRviz = []
129  linesMsg = []
130  edgesMsg = []
131  roomsMsg = []
132  contourMsg = None
133  self.origin = self.features.originalMap.info.origin
134  self.res = self.features.originalMap.info.resolution
135  extended_lines = self.rose2.extended_segments_th1_merged.copy()
136  edges = self.rose2.edges_th1.copy()
137  #Lines Marker and ExtendedLine messages
138  self.line_markers = mu.make_lines_marker(extended_lines, self.origin, self.res)
139  for l in self.rose2.extended_segments_th1_merged:
140  linesMsg.append(mu.make_extendedline_msg(l))
141  i = 0
142  # Edge MarkerArray and Edge messages
143  for e in edges:
144  edgesRviz.append(mu.make_edge_marker(e, i, self.origin, self.res))
145  edgesMsg.append(mu.make_edge_msg(e))
146  i += 1
147  #Room PolygonArray and Room messages
148  if self.rose2.rooms_th1 is not None:
149  labels = []
150  for r in self.rose2.rooms_th1:
151  roomsMsg.append(mu.make_room_msg(r))
152  roomsRviz.append(mu.make_room_polygon(r, self.origin, self.res))
153  labels.append(1)
154  contourMsg = mu.make_contour_msg(self.rose2.vertices)
155  self.room_polygons.polygons = roomsRviz
156  self.room_polygons.header.frame_id = "map"
157  self.room_polygons.labels = labels
158  self.features2 = ROSE2Features()
159  self.edge_markers.markers = edgesRviz
160  self.features2.rooms = roomsMsg
161  self.features2.contour = contourMsg
162  self.features2.lines = linesMsg
163  self.features2.edges = edgesMsg
164 
165  def publishFeatures(self):
166  self.pubEdges.publish(self.edge_markers)
167  self.pubLines.publish(self.line_markers)
168  self.pubRooms.publish(self.room_polygons)
169  self.pubFeatures.publish(self.features2)
170 
171 if __name__ == '__main__':
173  warnings.filterwarnings("ignore")
174  f.run()
src.FeatureExtractorROSE2.FeatureExtractorROSE2.featuresSrv
def featuresSrv(self, features)
Definition: FeatureExtractorROSE2.py:118
src.FeatureExtractorROSE2.FeatureExtractorROSE2.rooms_voronoi
rooms_voronoi
Definition: FeatureExtractorROSE2.py:52
src.FeatureExtractorROSE2.FeatureExtractorROSE2.publish
publish
Definition: FeatureExtractorROSE2.py:79
src.FeatureExtractorROSE2.FeatureExtractorROSE2.pubEdges
pubEdges
Definition: FeatureExtractorROSE2.py:87
src.FeatureExtractorROSE2.FeatureExtractorROSE2.iterations
iterations
Definition: FeatureExtractorROSE2.py:56
src.FeatureExtractorROSE2.FeatureExtractorROSE2.pubLines
pubLines
Definition: FeatureExtractorROSE2.py:86
src.FeatureExtractorROSE2.FeatureExtractorROSE2.pubOnce
pubOnce
ROS PARAMS ###.
Definition: FeatureExtractorROSE2.py:44
src.FeatureExtractorROSE2.FeatureExtractorROSE2.distance_extended_segment
distance_extended_segment
Definition: FeatureExtractorROSE2.py:48
src.FeatureExtractorROSE2.FeatureExtractorROSE2.pubRate
pubRate
Definition: FeatureExtractorROSE2.py:76
src.FeatureExtractorROSE2.FeatureExtractorROSE2
Definition: FeatureExtractorROSE2.py:38
src.FeatureExtractorROSE2.FeatureExtractorROSE2.res
res
Definition: FeatureExtractorROSE2.py:74
src.FeatureExtractorROSE2.FeatureExtractorROSE2.edge_markers
edge_markers
Definition: FeatureExtractorROSE2.py:125
src.FeatureExtractorROSE2.FeatureExtractorROSE2.publishFeatures
def publishFeatures(self)
Definition: FeatureExtractorROSE2.py:165
src.FeatureExtractorROSE2.FeatureExtractorROSE2.spatialClusteringLineSegmentsThreshold
spatialClusteringLineSegmentsThreshold
Definition: FeatureExtractorROSE2.py:45
src.FeatureExtractorROSE2.FeatureExtractorROSE2.processMap
def processMap(self, features)
Definition: FeatureExtractorROSE2.py:105
src.FeatureExtractorROSE2.FeatureExtractorROSE2.threshold_edges
threshold_edges
Definition: FeatureExtractorROSE2.py:50
src.FeatureExtractorROSE2.FeatureExtractorROSE2.originalMap
originalMap
Definition: FeatureExtractorROSE2.py:108
src.FeatureExtractorROSE2.FeatureExtractorROSE2.blur
blur
Definition: FeatureExtractorROSE2.py:55
src.FeatureExtractorROSE2.FeatureExtractorROSE2.filepath
filepath
Definition: FeatureExtractorROSE2.py:53
src.FeatureExtractorROSE2.FeatureExtractorROSE2.pubFeatures
pubFeatures
Definition: FeatureExtractorROSE2.py:85
src.FeatureExtractorROSE2.FeatureExtractorROSE2.__init__
def __init__(self)
Definition: FeatureExtractorROSE2.py:39
src.FeatureExtractorROSE2.FeatureExtractorROSE2.param_obj
param_obj
Definition: FeatureExtractorROSE2.py:59
minibatch.Minibatch
Definition: minibatch.py:50
src.FeatureExtractorROSE2.FeatureExtractorROSE2.makeFeaturesMsg
def makeFeaturesMsg(self)
Definition: FeatureExtractorROSE2.py:123
src.FeatureExtractorROSE2.FeatureExtractorROSE2.pubRooms
pubRooms
Definition: FeatureExtractorROSE2.py:88
src.FeatureExtractorROSE2.FeatureExtractorROSE2.cleanMap
cleanMap
Definition: FeatureExtractorROSE2.py:71
parameters.ParameterObj
Definition: parameters.py:26
src.FeatureExtractorROSE2.FeatureExtractorROSE2.directions
directions
Definition: FeatureExtractorROSE2.py:109
src.FeatureExtractorROSE2.FeatureExtractorROSE2.rose2
rose2
Definition: FeatureExtractorROSE2.py:111
src.FeatureExtractorROSE2.FeatureExtractorROSE2.lines_th1
lines_th1
Definition: FeatureExtractorROSE2.py:47
src.FeatureExtractorROSE2.FeatureExtractorROSE2.originalOccMap
originalOccMap
Definition: FeatureExtractorROSE2.py:72
src.FeatureExtractorROSE2.FeatureExtractorROSE2.voronoi_closeness
voronoi_closeness
Definition: FeatureExtractorROSE2.py:54
src.FeatureExtractorROSE2.FeatureExtractorROSE2.features
features
Definition: FeatureExtractorROSE2.py:69
src.FeatureExtractorROSE2.FeatureExtractorROSE2.features2
features2
Definition: FeatureExtractorROSE2.py:70
src.FeatureExtractorROSE2.FeatureExtractorROSE2.room_polygons
room_polygons
Definition: FeatureExtractorROSE2.py:126
src.FeatureExtractorROSE2.FeatureExtractorROSE2.line_markers
line_markers
Definition: FeatureExtractorROSE2.py:124
src.FeatureExtractorROSE2.FeatureExtractorROSE2.origin
origin
Definition: FeatureExtractorROSE2.py:73
src.FeatureExtractorROSE2.FeatureExtractorROSE2.run
def run(self)
Definition: FeatureExtractorROSE2.py:95


rose2
Author(s): Gabriele Somaschini, Matteo Luperto
autogenerated on Wed Jun 28 2023 02:21:53