simulateMeasurements.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 '''
4 Copyright (c) 2016, Braun Kai, Gehrung Joachim, Heizmann Heinrich, Meissner Pascal
5 All rights reserved.
6 
7 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
8 
9 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
10 
11 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
12 
13 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
14 
15 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
16 '''
17 
18 import os
19 
20 import rospy
21 import rosbag
22 import roslib
23 
24 import random
25 import math
26 import time
27 
28 import subprocess
29 
30 roslib.load_manifest('asr_psm')
31 
32 from asr_msgs.msg import AsrObject
33 from visualization_msgs.msg import Marker
34 
35 # NOTE: IN CASE THE SCENE_GRAPH_GENERATOR CANT TRANSFORM THE OBJECTS INTO THE RIGHT COORDINATE FRAME,
36 # DO THE FOLLOWING: roslaunch kinematic_chain_asr transformation_publishers_left.launch
37 
38 
39 def publishPdbObjectMessage(pub, posX, posY, posZ, oriW, oriX, oriY, oriZ, objType):
40 
41  # build object ...
42  msg = AsrObject()
43  msg.header.stamp = rospy.Time.now()
44  msg.header.frame_id = '/PTU'
45  msg.providedBy = 'textured'
46  msg.poseEstimation.pose.position.x = posX;
47  msg.poseEstimation.pose.position.y = posY;
48  msg.poseEstimation.pose.position.z = posZ;
49  msg.poseEstimation.pose.orientation.w = oriW;
50  msg.poseEstimation.pose.orientation.x = oriX;
51  msg.poseEstimation.pose.orientation.y = oriY;
52  msg.poseEstimation.pose.orientation.z = oriZ;
53  msg.type = objType
54 
55  # ... and publish it
56  pub.publish(msg)
57 
58 def rosbagPdbObjectMessage(bag, posX, posY, posZ, oriW, oriX, oriY, oriZ, objType):
59 
60  # build object ...
61  msg = AsrObject()
62  msg.header.stamp = rospy.Time.now()
63  msg.header.frame_id = '/PTU'
64  msg.providedBy = 'textured'
65  msg.poseEstimation.pose.position.x = posX;
66  msg.poseEstimation.pose.position.y = posY;
67  msg.poseEstimation.pose.position.z = posZ;
68  msg.poseEstimation.pose.orientation.w = oriW;
69  msg.poseEstimation.pose.orientation.x = oriX;
70  msg.poseEstimation.pose.orientation.y = oriY;
71  msg.poseEstimation.pose.orientation.z = oriZ;
72  msg.type = objType
73 
74  # ... and write it into bag file
75  bag.write('/stereo/objects', msg)
76 
77 def publishVisualizationMessage(pub, posX, posY, posZ, oriW, oriX, oriY, oriZ, objType, mid, mesh):
78 
79  # build object ...
80  msg = Marker()
81  msg.header.stamp = rospy.Time.now()
82  msg.header.frame_id = '/PTU'
83  msg.ns = 'textured'
84  msg.id = mid
85  msg.type = 10
86  msg.action = 0
87  msg.pose.position.x = posX;
88  msg.pose.position.y = posY;
89  msg.pose.position.z = posZ;
90  msg.pose.orientation.w = oriW;
91  msg.pose.orientation.x = oriX;
92  msg.pose.orientation.y = oriY;
93  msg.pose.orientation.z = oriZ;
94  msg.scale.x = 0.001
95  msg.scale.y = 0.001
96  msg.scale.z = 0.001
97  msg.mesh_resource = mesh
98  msg.mesh_use_embedded_materials = True
99 
100  # ... and publish it
101  pub.publish(msg)
102 
103 def rosbagVisualizationMessage(bag, posX, posY, posZ, oriW, oriX, oriY, oriZ, objType, mid, mesh):
104 
105  # build object ...
106  msg = Marker()
107  msg.header.stamp = rospy.Time.now()
108  msg.header.frame_id = '/PTU'
109  msg.ns = 'textured'
110  msg.id = mid
111  msg.type = 10
112  msg.action = 0
113  msg.pose.position.x = posX;
114  msg.pose.position.y = posY;
115  msg.pose.position.z = posZ;
116  msg.pose.orientation.w = oriW;
117  msg.pose.orientation.x = oriX;
118  msg.pose.orientation.y = oriY;
119  msg.pose.orientation.z = oriZ;
120  msg.scale.x = 0.001
121  msg.scale.y = 0.001
122  msg.scale.z = 0.001
123  msg.mesh_resource = mesh
124  msg.mesh_use_embedded_materials = True
125 
126  # ... and write it into bag file
127  bag.write('/stereo/visualization_marker', msg)
128 
129 def publishEvidence(bag, pubObj, pubVis, posX, posY, posZ, oriW, oriX, oriY, oriZ, objType, mid, mesh):
130 
131  # publish
132  publishPdbObjectMessage(pubObj, posX, posY, posZ, oriW, oriX, oriY, oriZ, objType)
133  publishVisualizationMessage(pubVis, posX, posY, posZ, oriW, oriX, oriY, oriZ, objType, mid, mesh)
134 
135  # if rosbag defined, also write to rosbag
136  if bag:
137  rosbagPdbObjectMessage(bag, posX, posY, posZ, oriW, oriX, oriY, oriZ, objType)
138  rosbagVisualizationMessage(bag, posX, posY, posZ, oriW, oriX, oriY, oriZ, objType, mid, mesh)
139 
140 def publishNoisedEvidence(bag, pubObj, pubVis, posX, posY, posZ, oriW, oriX, oriY, oriZ, objType, mid, mesh, sigma):
141 
142  # generate random noise for the position
143  pX = posX + random.normalvariate(0.0, sigma)
144  pY = posY + random.normalvariate(0.0, sigma)
145  pZ = posZ + random.normalvariate(0.0, sigma)
146 
147  # generate random noise for the orientation
148  oW = oriW + random.normalvariate(0.0, sigma)
149  oX = oriX + random.normalvariate(0.0, sigma)
150  oY = oriY + random.normalvariate(0.0, sigma)
151  oZ = oriZ + random.normalvariate(0.0, sigma)
152 
153  # normalize quaternion
154  magnitude = math.sqrt(math.pow(oW, 2) + math.pow(oX, 2) + math.pow(oY, 2) + math.pow(oZ, 2))
155 
156  oW /= magnitude
157  oX /= magnitude
158  oY /= magnitude
159  oZ /= magnitude
160 
161  # publish object and visualization message
162  publishEvidence(bag, pubObj, pubVis, pX, pY, pZ, oW, oX, oY, oZ, objType, mid, mesh)
163 
164 def simulateFourObjectsSzenario(meshTexturedPath, meshSegmentablePath, pubObj, pubVis):
165 
166  print "Running sample generation."
167 
168  for i in range(0,1000):
169  sigma = 0.05;
170 
171  # subset_scene_simulated
172  publishNoisedEvidence(None, pubObj, pubVis, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 'VitalisSchoko', 0, meshTexturedPath + 'vitalis_schoko.dae', sigma)
173  publishNoisedEvidence(None, pubObj, pubVis, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 'Smacks', 1, meshTexturedPath + 'smacks.dae', sigma)
174  publishNoisedEvidence(None, pubObj, pubVis, 1.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 'CoffeeBox', 2, meshTexturedPath + 'coffeebox.dae', sigma)
175  publishNoisedEvidence(None, pubObj, pubVis, 1.0, 2.0, 0.0, 1.0, 0.0, 0.0, 0.0, 'Plate', 3, meshSegmentablePath + 'plate_deep/object.dae', sigma)
176 
177  time.sleep(0.01)
178 
179  print "Done generating samples."
180 
181 def simulateObjectEvidence(meshTexturedPath, meshSegmentablePath, pubObj, pubVis, number):
182 
183  print "Generating object evidences."
184 
185  for i in range(0,1000):
186 
187  sigma = 0.05;
188 
189  # publish n object evidence
190  for obj in range(1, number):
191  publishNoisedEvidence(None, pubObj, pubVis, i * (1.0 / samplesOnEdge), obj + 1, 0.0, 1.0, 0.0, 0.0, 0.0, 'VitalisSchoko-' + str(obj), obj + 1, meshTexturedPath + 'vitalis_schoko.dae', 0.05)
192 
193  time.sleep(0.01)
194 
195  print "Done generating object evidences."
196 
197 def runtimeCreateSamplesSimple(meshTexturedPath, pubObj, pubVis, pathToBags, scenarios, sceneObjects, samplesOnEdge):
198 
199  # iterate over all scenarios (that means number of samples times 100)
200  for scenario in range(1, scenarios + 1):
201  numberOfSamples = samplesOnEdge * scenario
202 
203  # iterate over all scene objects in the scenario
204  for sceneobject in range(0, sceneObjects + 1):
205  print 'Publishing ' + str(numberOfSamples) + ' samples with ' + str(sceneobject) + ' objects.'
206 
207  # define the id of the scene and the path to the bag file
208  sceneId = str(numberOfSamples).zfill(3) + '_' + str(sceneobject).zfill(2)
209  bagObjects = pathToBags + '/objects/' + sceneId + '.bag'
210 
211  # create rosbag
212  bag = rosbag.Bag(bagObjects, 'w')
213 
214  try:
215  # create m samples...
216  for i in range(0, numberOfSamples):
217 
218  publishNoisedEvidence(bag, pubObj, pubVis, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 'Smacks', 0, meshTexturedPath + 'smacks.dae', 0.05)
219 
220  # publish evidence into rosbag, also publish to message system for online visualization
221  for obj in range(0, sceneobject):
222  publishNoisedEvidence(bag, pubObj, pubVis, i * (1.0 / samplesOnEdge), obj + 1, 0.0, 1.0, 0.0, 0.0, 0.0, 'VitalisSchoko-' + str(obj), obj + 1, meshTexturedPath + 'vitalis_schoko.dae', 0.05)
223  finally:
224  bag.close()
225 
226 def runtimePrepareStandalonePSM(meshTexturedPath, pubObj, pubVis, pathToBags, sceneObjects, samplesPerObject):
227 
228  # iterate over all objects to generate models
229  for sceneobject in range(1, sceneObjects + 1):
230 
231  print 'Publishing ' + str(samplesPerObject) + ' samples for ' + str(sceneobject) + ' objects.'
232 
233  # define the id of the scene and the path to the bag file
234  sceneId = 'run_' + str(sceneobject).zfill(2)
235  bagObjects = pathToBags + '/objects/' + sceneId + '.bag'
236 
237  # create rosbag
238  bag = rosbag.Bag(bagObjects, 'w')
239 
240  try:
241  # publish evidence into rosbag, also publish to message system for online visualization
242  for i in range(0, samplesPerObject):
243  for obj in range(0, sceneobject):
244  publishNoisedEvidence(bag, pubObj, pubVis, 0.0, obj + 1, 0.0, 1.0, 0.0, 0.0, 0.0, 'VitalisSchoko-' + str(obj), obj + 1, meshTexturedPath + 'vitalis_schoko.dae', 0.05)
245  finally:
246  bag.close()
247 
248  #print 'Generating scene graphs.'
249 
250  #bagSceneGraph = pathToBags + '/scenegraphs/SCENEGRAPH_' + sceneId + '.bag'
251 
252  #subprocess.call(['rosrun', 'scene_graph_generator', 'scene_graph_generator', '_base_frame:=/PTU', '_scene_id:=' + sceneId,'_im_frame_id:=null', '_rosbag_source:=' + bagObjects, '_rosbag_target:=' + bagSceneGraph])
253 
254  #print "Learn scene model."
255 
256  ## Create a temporary launch file and execute it.
257  #with open(pathToBags + "/temp.launch", "wt") as fout:
258  #with open(pathToBags + "/learner.launch", "rt") as fin:
259  #for line in fin:
260  #line = line.replace('$$$SCENE_GRAPH_BAGS$$$', '[\'' + bagSceneGraph + '\']')
261  #line = line.replace('$$$SCENARIO$$$', sceneId)
262  #line = line.replace('$$$OUTPUT_DIRECTORY$$$', pathToBags + '/psm_models')
263  #line = line.replace('$$$KERNELS_MIN$$$', "1")
264  #line = line.replace('$$$KERNELS_MAX$$$', "1")
265  #fout.write(line)
266 
267  #subprocess.check_call(['roslaunch', pathToBags + '/temp.launch'])
268  #os.remove(pathToBags + "/temp.launch")
269 
270 def runtimeEvaluateStandalonePSM(meshTexturedPath, pubObj, pubVis, pathToBags, sceneObjects, samplesPerObject):
271 
272  evidences = sceneObjects
273 
274  # Iterate over all objects to execute runtime evaluation.
275  for sceneobject in range(1, sceneObjects + 1):
276 
277  # Evaluate all number of evidences up to the given threshold for the current model.
278  for evidence in range(1, evidences + 1):
279 
280  print "Execute PSM inference for " + str(evidence) + " evidences."
281 
282  # Define scene id, name of the model and the bag file.
283  sceneId = 'run_' + str(evidence).zfill(2)
284  modelFilename = pathToBags + '/psm_models/run_' + str(sceneobject) + '.xml'
285  bagObjects = pathToBags + '/objects/' + sceneId + '.bag'
286 
287  # Create a subfolder for the runtime evaluation results.
288  psmRuntimeLogFolder = pathToBags + '/runtime/obj_' + str(sceneobject) + '_' + sceneId
289  if not os.path.exists(psmRuntimeLogFolder):
290  os.makedirs(psmRuntimeLogFolder)
291 
292  # Execute the PSM inference in batch mode to get the runtime values.
293  subprocess.call(['rosrun', 'asr_psm', 'inference_batch', '_plot:=false', '_object_topic:=/stereo/objects', '_scene_graph_topic:=/scene_graphs', '_scene_model_filename:=' + modelFilename, '_bag_filenames_list:=', '_base_frame_id:=/PTU', '_scale_factor:=1.0', '_sigma_multiplicator:=2.0', '_targeting_help:=false', '_inference_algorithm:=maximum', '_runtime_log_path:=' + psmRuntimeLogFolder, '_bag_path:=' + bagObjects])
294 
295 def runtimeEvaluateStandalonePSMKickass(meshTexturedPath, pubObj, pubVis, pathToBags, sceneObjects):
296 
297  # Iterate over all objects to execute runtime evaluation.
298  for sceneobject in range(1, sceneObjects + 1):
299 
300  print "Execute PSM inference for " + str(sceneobject) + " evidences."
301 
302  # Define scene id, name of the model and the bag file.
303  sceneId = 'run_' + str(sceneobject).zfill(2)
304  modelFilename = pathToBags + '/psm_models/' + sceneId + '.xml'
305  bagObjects = pathToBags + '/objects/' + sceneId + '.bag'
306 
307  # Create a subfolder for the runtime evaluation results.
308  psmRuntimeLogFolder = pathToBags + '/runtime/PSM/' + sceneId
309  if not os.path.exists(psmRuntimeLogFolder):
310  os.makedirs(psmRuntimeLogFolder)
311 
312  # Execute the PSM inference in batch mode to get the runtime values.
313  subprocess.call(['rosrun', 'asr_psm', 'inference_batch', '_plot:=false', '_object_topic:=/stereo/objects', '_scene_graph_topic:=/scene_graphs', '_scene_model_filename:=' + modelFilename, '_bag_filenames_list:=', '_base_frame_id:=/PTU', '_scale_factor:=1.0', '_sigma_multiplicator:=2.0', '_targeting_help:=false', '_inference_algorithm:=maximum', '_runtime_log_path:=' + psmRuntimeLogFolder, '_bag_path:=' + bagObjects])
314 
315 def runtimeCreateSamplesComplex(meshTexturedPath, pubObj, pubVis, pathToBags, scenarios, sceneObjects, samplesOnEdge):
316 
317  # iterate over all scenarios (that means number of samples times 100)
318  for scenario in range(1, scenarios + 1):
319  numberOfSamples = samplesOnEdge * scenario
320 
321  # iterate over all scene objects in the scenario
322  for sceneobject in range(0, sceneObjects + 1):
323  print 'Publishing ' + str(numberOfSamples) + ' samples with ' + str(sceneobject) + ' objects(' + str(scenario) + " clusters)"
324 
325  # define the id of the scene and the path to the bag file
326  sceneId = str(numberOfSamples).zfill(3) + '_' + str(sceneobject).zfill(2)
327  bagObjects = pathToBags + '/objects/' + sceneId + '.bag'
328 
329  # direction of movement and position offsets
330  direction = 0
331  posX = 0
332  posY = 0
333 
334  # create rosbag
335  bag = rosbag.Bag(bagObjects, 'w')
336 
337  try:
338  # iterate over all turns
339  for seq in range(0, scenario):
340  for i in range(0, samplesOnEdge):
341  if direction:
342  posY += 1.0 / samplesOnEdge
343  else:
344  posX += 1.0 / samplesOnEdge
345 
346  publishNoisedEvidence(bag, pubObj, pubVis, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 'Smacks', 0, meshTexturedPath + 'smacks.dae', 0.05)
347 
348  # publish evidence into rosbag, also publish to message system for online visualization
349  for obj in range(0, sceneobject):
350  publishNoisedEvidence(bag, pubObj, pubVis, posX - obj, posY + obj, 0.0, 1.0, 0.0, 0.0, 0.0, 'VitalisSchoko-' + str(obj), obj + 1, meshTexturedPath + 'vitalis_schoko.dae', 0.05)
351 
352  # toggle between directions
353  direction += 1
354  if direction > 1:
355  direction = 0
356  finally:
357  bag.close()
358 
359 def runtimePreparePSM(meshTexturedPath, pubObj, pubVis, pathToBags, scenarios, sceneObjects, samplesOnEdge, useComplex):
360 
361  # iterate over all scenarios (that means number of samples times 100)
362  for scenario in range(1, scenarios + 1):
363  numberOfSamples = samplesOnEdge * scenario
364 
365  # iterate over all scene objects in the scenario
366  for sceneobject in range(0, sceneObjects + 1):
367  print 'Publishing ' + str(numberOfSamples) + ' samples with ' + str(sceneobject) + ' objects.'
368 
369  # define the id of the scene and the path to the bag file
370  sceneId = str(numberOfSamples).zfill(3) + '_' + str(sceneobject).zfill(2)
371  bagObjects = pathToBags + '/objects/' + sceneId + '.bag'
372 
373  print 'Generating scene graphs.'
374 
375  bagSceneGraph = pathToBags + '/scenegraphs/SCENEGRAPH_' + sceneId + '.bag'
376 
377  # Execute subprocess that generates the scene graph
378  subprocess.call(['rosrun', 'scene_graph_generator', 'scene_graph_generator', '_base_frame:=/PTU', '_scene_id:=' + sceneId,'_im_frame_id:=null', '_rosbag_source:=' + bagObjects, '_rosbag_target:=' + bagSceneGraph])
379 
380  print "Learn scene model."
381  6,
382  # Create a temporary launch file and execute it.
383  with open(pathToBags + "/temp.launch", "wt") as fout:
384  with open(pathToBags + "/learner.launch", "rt") as fin:
385  for line in fin:
386  line = line.replace('$$$SCENE_GRAPH_BAGS$$$', '[\'' + bagSceneGraph + '\']')
387  line = line.replace('$$$SCENARIO$$$', sceneId)
388  line = line.replace('$$$OUTPUT_DIRECTORY$$$', pathToBags + '/psm_models')
389 
390  if useComplex:
391  line = line.replace('$$$KERNELS_MIN$$$', str(scenario))
392  line = line.replace('$$$KERNELS_MAX$$$', str(scenario))
393  else:
394  line = line.replace('$$$KERNELS_MIN$$$', "1")
395  line = line.replace('$$$KERNELS_MAX$$$', "1")
396  fout.write(line)
397 
398  subprocess.check_call(['roslaunch', pathToBags + '/temp.launch'])
399  os.remove(pathToBags + "/temp.launch")
400 
401 def runtimeEvaluatePSM(meshTexturedPath, pubObj, pubVis, pathToBags, scenarios, sceneObjects, samplesOnEdge):
402 
403  # iterate over all scenarios (that means number of samples times 100)
404  for scenario in range(1, scenarios + 1):
405  numberOfSamples = samplesOnEdge * scenario
406 
407  # iterate over all scene objects in the scenario
408  for sceneobject in range(0, sceneObjects + 1):
409  print 'Publishing ' + str(numberOfSamples) + ' samples with ' + str(sceneobject) + ' objects.'
410 
411  # define the id of the scene and the path to the bag file
412  sceneId = str(numberOfSamples).zfill(3) + '_' + str(sceneobject).zfill(2)
413  bagObjects = pathToBags + '/objects/' + sceneId + '.bag'
414 
415  print "Execute PSM inference in batch mode to determine runtime."
416 
417  modelFilename = pathToBags + '/psm_models/' + sceneId + '.xml'
418 
419  # Create a subfolder for the runtime evaluation results.
420  psmRuntimeLogFolder = pathToBags + '/runtime/PSM/' + sceneId
421  if not os.path.exists(psmRuntimeLogFolder):
422  os.makedirs(psmRuntimeLogFolder)
423 
424  # Execute the PSM inference in batch mode to get the runtime values.
425  subprocess.call(['rosrun', 'asr_psm', 'inference_batch', '_plot:=false', '_object_topic:=/stereo/objects', '_scene_graph_topic:=/scene_graphs', '_scene_model_filename:=' + modelFilename, '_bag_filenames_list:=', '_base_frame_id:=/PTU', '_scale_factor:=1.0', '_sigma_multiplicator:=2.0', '_targeting_help:=false', '_inference_algorithm:=maximum', '_runtime_log_path:=' + psmRuntimeLogFolder, '_bag_path:=' + bagObjects])
426 
427 def runtimeEvaluatePSMStandalone(meshTexturedPath, pubObj, pubVis, pathToBags, scenarios, sceneObjects, samplesOnEdge):
428 
429  # iterate over all scenarios (that means number of samples times 100)
430  for scenario in range(1, scenarios + 1):
431  numberOfSamples = samplesOnEdge * scenario
432 
433  # iterate over all scene objects in the scenario
434  for sceneobject in range(0, sceneObjects + 1):
435  print 'Publishing ' + str(numberOfSamples) + ' samples with ' + str(sceneobject) + ' objects.'
436 
437  # define the id of the scene and the path to the bag file
438  sceneId = str(numberOfSamples).zfill(3) + '_' + str(sceneobject).zfill(2)
439  bagObjects = pathToBags + '/objects/' + sceneId + '.bag'
440 
441  print "Execute PSM inference in batch mode to determine runtime."
442 
443  modelFilename = pathToBags + '/psm_models/' + sceneId + '.xml'
444 
445  # Create a subfolder for the runtime evaluation results.
446  psmRuntimeLogFolder = pathToBags + '/runtime/PSM/' + sceneId
447  if not os.path.exists(psmRuntimeLogFolder):
448  os.makedirs(psmRuntimeLogFolder)
449 
450  # Execute the PSM inference in batch mode to get the runtime values.
451  subprocess.call(['rosrun', 'asr_psm', 'inference_batch', '_plot:=false', '_object_topic:=/stereo/objects', '_scene_graph_topic:=/scene_graphs', '_scene_model_filename:=' + modelFilename, '_bag_filenames_list:=', '_base_frame_id:=/PTU', '_scale_factor:=1.0', '_sigma_multiplicator:=2.0', '_targeting_help:=false', '_inference_algorithm:=maximum', '_runtime_log_path:=' + psmRuntimeLogFolder, '_bag_path:=' + bagObjects])
452 
453 def runtimePrepareISM(meshTexturedPath, pubObj, pubVis, pathToBags, scenarios, sceneObjects, samplesOnEdge):
454 
455  # iterate over all scenarios (that means number of samples times 100)
456  for scenario in range(1, scenarios + 1):
457  numberOfSamples = samplesOnEdge * scenario
458 
459  # iterate over all scene objects in the scenario
460  for sceneobject in range(0, sceneObjects + 1):
461  print 'Publishing ' + str(numberOfSamples) + ' samples with ' + str(sceneobject) + ' objects.'
462 
463  # define the id of the scene and the path to the bag file
464  sceneId = str(numberOfSamples).zfill(3) + '_' + str(sceneobject).zfill(2)
465  bagObjects = pathToBags + '/objects/' + sceneId + '.bag'
466 
467  print "Build ISM database."
468 
469  pathToIsmDatabase = pathToBags + '/ism_models/' + sceneId + '.sqlite.ism_test'
470 
471  # Run the database build process.
472  subprocess.call(['rosrun', 'ism', 'recorder_batch', '_objectTopic:=/stereo/objects', '_cameraInfoTopic:=/stereo/left/camera_info', '_window_adjustment:=1', '_sceneName:=' + sceneId, '_capture_interval:=1', '_baseFrame:=/PTU', '_dbfilename:=' + pathToIsmDatabase, '_multiview_recording:=true', '_bag_path:=' + bagObjects])
473 
474  # Train the database build in the last step.
475  subprocess.call(['rosrun', 'ism', 'trainer_batch', '_useClustering:=true', '_staticBreakRatio:=0.01', '_togetherRatio:=0.90', '_maxAngleDeviation:=45' , '_visualization_topic:=/visualization_marker', '_baseFrame:=/PTU', '_dbfilename:=' + pathToIsmDatabase])
476 
477 def runtimePrepareStandaloneISM(meshTexturedPath, pubObj, pubVis, pathToBags, sceneObjects):
478 
479  # iterate over all scene objects in the scenario
480  for sceneobject in range(1, sceneObjects + 1):
481  print 'Creating and learning database for ' + str(sceneobject) + ' objects.'
482 
483  # define the id of the scene and the path to the bag file
484  sceneId = '/run_' + str(sceneobject).zfill(2)
485  bagObjects = pathToBags + '/objects/' + sceneId + '.bag'
486 
487  print "Build ISM database."
488 
489  pathToIsmDatabase = pathToBags + '/ism_models/' + sceneId + '.sqlite.ism_test'
490 
491  # Run the database build process.
492  subprocess.call(['rosrun', 'ism', 'recorder_batch', '_objectTopic:=/stereo/objects', '_cameraInfoTopic:=/stereo/left/camera_info', '_window_adjustment:=1', '_sceneName:=' + sceneId, '_capture_interval:=1', '_baseFrame:=/PTU', '_dbfilename:=' + pathToIsmDatabase, '_multiview_recording:=true', '_bag_path:=' + bagObjects])
493 
494  # Train the database build in the last step.
495  subprocess.call(['rosrun', 'ism', 'trainer_batch', '_useClustering:=true', '_staticBreakRatio:=0.01', '_togetherRatio:=0.90', '_maxAngleDeviation:=45' , '_visualization_topic:=/visualization_marker', '_baseFrame:=/PTU', '_dbfilename:=' + pathToIsmDatabase])
496 
497 def runtimeEvaluateISM(meshTexturedPath, pubObj, pubVis, pathToBags, scenarios, sceneObjects, samplesOnEdge):
498 
499  # iterate over all scenarios (that means number of samples times 100)
500  for scenario in range(1, scenarios + 1):
501  numberOfSamples = samplesOnEdge * scenario
502 
503  # iterate over all scene objects in the scenario
504  for sceneobject in range(0, sceneObjects + 1):
505  print 'Publishing ' + str(numberOfSamples) + ' samples with ' + str(sceneobject) + ' objects.'
506 
507  # define the id of the scene and the path to the bag file
508  sceneId = str(numberOfSamples).zfill(3) + '_' + str(sceneobject).zfill(2)
509  bagObjects = pathToBags + '/objects/' + sceneId + '.bag'
510 
511  print "Execute ISM inference in batch mode to determine runtime."
512 
513  # Create a subfolder for the runtime evaluation results.
514  ismRuntimeLogFolder = pathToBags + '/runtime/ISM/' + sceneId
515  if not os.path.exists(ismRuntimeLogFolder):
516  os.makedirs(ismRuntimeLogFolder)
517 
518  # Create path to test database.
519  ismDatabase = pathToBags + '/ism_models/' + sceneId + '.sqlite.ism_test'
520  ismRuntimeFile = ismRuntimeLogFolder + '/' + sceneId + '.csv'
521 
522  # Execute the ISM helper class to get the runtime values.
523  subprocess.call(['rosrun', 'ism', 'testRunnerExtended', '-d', ismDatabase, '-t', ismTestDatabase, '-c', ismRuntimeFile, '-o', str(sceneobject + 1), '-s', str(numberOfSamples)])
524 
525  # Remove test database.
526  os.remove(ismTestDatabase)
527 
528 def runtimeEvaluateStandaloneISM(meshTexturedPath, pubObj, pubVis, pathToBags, sceneObjects, numberOfSamples):
529 
530  # iterate over all scene objects in the scenario
531  for sceneobject in range(0, sceneObjects + 1):
532  print 'Running runtime evaluation for ' + str(sceneobject) + ' objects.'
533 
534  # define the id of the scene and the path to the bag file
535  sceneId = '/run_' + str(sceneobject).zfill(2)
536  bagObjects = pathToBags + '/objects/' + sceneId + '.bag'
537 
538  print "Execute ISM inference in batch mode to determine runtime."
539 
540  # Create a subfolder for the runtime evaluation results.
541  ismRuntimeLogFolder = pathToBags + '/runtime/ISM/' + sceneId
542  if not os.path.exists(ismRuntimeLogFolder):
543  os.makedirs(ismRuntimeLogFolder)
544 
545  # Create path to test database.
546  ismDatabase = pathToBags + '/ism_models/' + sceneId + '.sqlite.ism_test'
547  ismTestDatabase = ismRuntimeLogFolder + '/test.sqlite'
548  ismRuntimeFile = ismRuntimeLogFolder + '/' + sceneId + '.csv'
549 
550  # Execute the ISM helper class to get the runtime values.
551  subprocess.call(['rosrun', 'ism', 'testRunnerExtended', '-d', ismDatabase, '-t', ismTestDatabase, '-c', ismRuntimeFile, '-o', str(sceneobject + 1), '-s', str(numberOfSamples)])
552 
553  # Remove test database.
554  os.remove(ismTestDatabase)
555 
556 
557 def simulateFalseRecognitionBenachmark(meshTexturedPath, pubObj, pubVis, pathToBags):
558 
559  print "Generating samples for all objects"
560 
561  # create rosbag
562  bag = rosbag.Bag(pathToBags + '/abweichung.bag', 'w')
563 
564  try:
565  # create m samples...
566  for i in range(0, 1000):
567 
568  # ...for a reference object...
569  publishNoisedEvidence(bag, pubObj, pubVis, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 'CoffeeBox', 0, meshTexturedPath + 'coffeebox.dae', 0.05)
570 
571  # ...and another object that positions forms multiple clusters.
572  for pos in range(0, 5):
573  publishNoisedEvidence(bag, pubObj, pubVis, -pos, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 'VitalisSchoko', 1, meshTexturedPath + 'vitalis_schoko.dae', 0.05)
574  finally:
575  bag.close()
576 
577 def main():
578 
579  # path to object meshes
580  meshPath = 'file:///homes/students/gehrung/Developement/ilcasRosPkg/trunk/perception/visual/object_localization/stereo_based/recognition_for_grasping/object_database/'
581  meshTexturedPath = meshPath + "textured_objects/"
582  meshSegmentablePath = meshPath + "segmentable_objects/"
583 
584  # path to bag file directory
585  pathToBags = '/media/data_ext/data/gehrung/evaluation'
586 
587  # init node
588  rospy.init_node('measurement_simulator')
589 
590  # instantiate publishers
591  pubObj = rospy.Publisher('/stereo/objects', AsrObject)
592  pubVis = rospy.Publisher('/stereo/visualization_marker', Marker)
593 
594  # Run one of the various szenarios
595  #simulateFourObjectsSzenario(meshTexturedPath, meshSegmentablePath, pubObj, pubVis)
596  #simulateObjectEvidence(meshTexturedPath, meshSegmentablePath, pubObj, pubVis, 1)
597  #simulateFalseRecognitionBenachmark(meshTexturedPath, pubObj, pubVis, pathToBags)
598 
599  # Runtime benchmark
600  #runtimeCreateSamplesSimple(meshTexturedPath, pubObj, pubVis, pathToBags + '/Laufzeitmessung/simple/', 4, 5, 100)
601  #runtimeCreateSamplesComplex(meshTexturedPath, pubObj, pubVis, pathToBags + '/Laufzeitmessung/complex/', 4, 5, 100)
602 
603  #runtimePreparePSM(meshTexturedPath, pubObj, pubVis, pathToBags + '/Laufzeitmessung/simple', 4, 5, 100, False)
604  #runtimePreparePSM(meshTexturedPath, pubObj, pubVis, pathToBags + '/Laufzeitmessung/complex', 4, 5, 100, True)
605  #runtimePrepareISM(meshTexturedPath, pubObj, pubVis, pathToBags + '/Laufzeitmessung/simple', 4, 5, 100)
606  #runtimePrepareISM(meshTexturedPath, pubObj, pubVis, pathToBags + '/Laufzeitmessung/complex', 4, 5, 100)
607 
608  #runtimeEvaluatePSM(meshTexturedPath, pubObj, pubVis, pathToBags + '/Laufzeitmessung/simple', 4, 5, 100)
609  #runtimeEvaluatePSM(meshTexturedPath, pubObj, pubVis, pathToBags + '/Laufzeitmessung/complex', 4, 5, 100)
610  #runtimeEvaluateISM(meshTexturedPath, pubObj, pubVis, pathToBags + '/Laufzeitmessung/simple', 4, 5, 100)
611  #runtimeEvaluateISM(meshTexturedPath, pubObj, pubVis, pathToBags + '/Laufzeitmessung/complex', 4, 5, 100)
612 
613  # Standalone PSM Evaluation.
614  #runtimePrepareStandalonePSM(meshTexturedPath, pubObj, pubVis, pathToBags + '/Laufzeitmessung/standalone', 6, 100)
615  #runtimeEvaluateStandalonePSM(meshTexturedPath, pubObj, pubVis, pathToBags + '/Laufzeitmessung/standalone', 6, 100)
616 
617  # Compare ISM and PSM.
618  #runtimePrepareStandalonePSM(meshTexturedPath, pubObj, pubVis, pathToBags + '/Laufzeitmessung/kickass', 10, 10)
619  #runtimeEvaluateStandalonePSMKickass(meshTexturedPath, pubObj, pubVis, pathToBags + '/Laufzeitmessung/kickass', 10)
620 
621  #runtimePrepareStandaloneISM(meshTexturedPath, pubObj, pubVis, pathToBags + '/Laufzeitmessung/kickass', 10)
622  runtimeEvaluateStandaloneISM(meshTexturedPath, pubObj, pubVis, pathToBags + '/Laufzeitmessung/kickass', 10, 10)
623 
624 if __name__ == "__main__":
625  main()
def simulateObjectEvidence(meshTexturedPath, meshSegmentablePath, pubObj, pubVis, number)
def rosbagVisualizationMessage(bag, posX, posY, posZ, oriW, oriX, oriY, oriZ, objType, mid, mesh)
def rosbagPdbObjectMessage(bag, posX, posY, posZ, oriW, oriX, oriY, oriZ, objType)
def runtimePrepareStandaloneISM(meshTexturedPath, pubObj, pubVis, pathToBags, sceneObjects)
def runtimePrepareISM(meshTexturedPath, pubObj, pubVis, pathToBags, scenarios, sceneObjects, samplesOnEdge)
def runtimeEvaluateStandalonePSM(meshTexturedPath, pubObj, pubVis, pathToBags, sceneObjects, samplesPerObject)
def runtimeEvaluatePSM(meshTexturedPath, pubObj, pubVis, pathToBags, scenarios, sceneObjects, samplesOnEdge)
def runtimeEvaluateStandalonePSMKickass(meshTexturedPath, pubObj, pubVis, pathToBags, sceneObjects)
def runtimeEvaluateISM(meshTexturedPath, pubObj, pubVis, pathToBags, scenarios, sceneObjects, samplesOnEdge)
def simulateFourObjectsSzenario(meshTexturedPath, meshSegmentablePath, pubObj, pubVis)
def publishPdbObjectMessage(pub, posX, posY, posZ, oriW, oriX, oriY, oriZ, objType)
def publishEvidence(bag, pubObj, pubVis, posX, posY, posZ, oriW, oriX, oriY, oriZ, objType, mid, mesh)
def publishVisualizationMessage(pub, posX, posY, posZ, oriW, oriX, oriY, oriZ, objType, mid, mesh)
def runtimePrepareStandalonePSM(meshTexturedPath, pubObj, pubVis, pathToBags, sceneObjects, samplesPerObject)
def runtimeCreateSamplesComplex(meshTexturedPath, pubObj, pubVis, pathToBags, scenarios, sceneObjects, samplesOnEdge)
def runtimeEvaluatePSMStandalone(meshTexturedPath, pubObj, pubVis, pathToBags, scenarios, sceneObjects, samplesOnEdge)
def runtimePreparePSM(meshTexturedPath, pubObj, pubVis, pathToBags, scenarios, sceneObjects, samplesOnEdge, useComplex)
def runtimeEvaluateStandaloneISM(meshTexturedPath, pubObj, pubVis, pathToBags, sceneObjects, numberOfSamples)
def simulateFalseRecognitionBenachmark(meshTexturedPath, pubObj, pubVis, pathToBags)
def publishNoisedEvidence(bag, pubObj, pubVis, posX, posY, posZ, oriW, oriX, oriY, oriZ, objType, mid, mesh, sigma)
def runtimeCreateSamplesSimple(meshTexturedPath, pubObj, pubVis, pathToBags, scenarios, sceneObjects, samplesOnEdge)


asr_psm
Author(s): Braun Kai, Gehrung Joachim, Heizmann Heinrich, Meißner Pascal
autogenerated on Fri Nov 15 2019 03:57:54