6 from configuration
import *
10 from configuration
import *
12 from general_ros
import *
19 state_acquisition = imp.load_source(
"*", scene_exploration_path +
"/src/common/state_acquisition.py")
20 nbvSettingsFilePath = next_best_view_path +
"/param/next_best_view_settings_sim.yaml" 27 dataMap =
getYaml(nbvSettingsFilePath)
28 dataMap[
"minIterationSteps"] = 15
29 dataMap[
"epsilon"] = 0.000000001
30 dataMap[
"spaceSamplerId"] = 1
31 dataMap[
"radius"] = 0.05
32 dataMap[
"enableGA"] =
False 33 dataMap[
"cacheResults"] =
False 34 dataMap[
"sampleSizeUnitSphereSampler"] = 2000
35 saveYaml(nbvSettingsFilePath, dataMap,
True)
38 dataMap =
getYaml(nbvSettingsFilePath)
39 dataMap[
"minIterationSteps"] = 15
40 dataMap[
"epsilon"] = 0.000000001
41 dataMap[
"spaceSamplerId"] = 1
42 dataMap[
"radius"] = 0.05
43 dataMap[
"enableGA"] =
False 44 dataMap[
"cacheResults"] =
True 45 dataMap[
"sampleSizeUnitSphereSampler"] = 2000
46 saveYaml(nbvSettingsFilePath, dataMap,
True)
49 dataMap =
getYaml(nbvSettingsFilePath)
50 dataMap[
"minIterationSteps"] = 1
51 dataMap[
"epsilon"] = 0.01
52 dataMap[
"spaceSamplerId"] = 1
53 dataMap[
"radius"] = 0.2
54 dataMap[
"enableGA"] =
False 55 dataMap[
"cacheResults"] =
False 56 dataMap[
"sampleSizeUnitSphereSampler"] = 384
57 saveYaml(nbvSettingsFilePath, dataMap,
True)
60 dataMap =
getYaml(nbvSettingsFilePath)
61 dataMap[
"minIterationSteps"] = 1
62 dataMap[
"epsilon"] = 0.01
63 dataMap[
"spaceSamplerId"] = 1
64 dataMap[
"radius"] = 0.2
65 dataMap[
"enableGA"] =
False 66 dataMap[
"cacheResults"] =
True 67 dataMap[
"sampleSizeUnitSphereSampler"] = 384
68 saveYaml(nbvSettingsFilePath, dataMap,
True)
71 dataMap =
getYaml(nbvSettingsFilePath)
72 dataMap[
"minIterationSteps"] = 5
73 dataMap[
"epsilon"] = 0.01
74 dataMap[
"spaceSamplerId"] = 5
75 dataMap[
"radius"] = 0.2
76 dataMap[
"enableGA"] =
True 77 dataMap[
"cacheResults"] =
True 78 dataMap[
"sampleSizeUnitSphereSampler"] = 384
79 saveYaml(nbvSettingsFilePath, dataMap,
True)
82 bkp =
getYaml(nbvSettingsFilePath)
83 setOptimalParameters()
88 saveYaml(nbvSettingsFilePath, bkp,
True)
93 return state_acquisition.get_camera_pose_cpp()
97 getRobotState = state_acquisition.GetRobotState()
98 robotState = getRobotState.get_robot_state()
100 rospy.wait_for_service(
'/nbv/set_init_robot_state')
101 set_init_state = rospy.ServiceProxy(
'/nbv/set_init_robot_state', SetInitRobotState)
102 set_init_state(robotState)
105 get_nbv = rospy.ServiceProxy(
'/nbv/next_best_view', GetNextBestView)
108 return get_nbv(current_camera_pose)
114 nbv_update = rospy.ServiceProxy(
'/nbv/update_point_cloud', UpdatePointCloud)
115 return nbv_update(pose, obj_types)
118 get_pc = rospy.ServiceProxy(
"/nbv/get_point_cloud", GetAttributedPointCloud)
122 pointCloudFile = open(logDir +
"/PointCloud/PointCloud_" + str(idx),
"rb")
123 viewportsFile = open(logDir +
"/PointCloud/Viewports_" + str(idx),
"rb")
124 return (pickle.load(pointCloudFile), pickle.load(viewportsFile))
130 set_pc = rospy.ServiceProxy(
"/nbv/set_point_cloud", SetAttributedPointCloud)
131 return set_pc(pointcloud, viewports)
134 fileContent =
getFile(logDir +
"/nbv_results.csv")
135 if fileContent
is None:
137 count = fileContent.count(
"utility:")
142 fileName = logDir +
"/nbv_results.csv" 144 csvReader = csv.reader(f, delimiter =
" ", quotechar =
"|")
145 nbvsTuples = list(csvReader)
146 nbvs = map(
lambda x: yaml.load(x[1]), nbvsTuples)
149 print(
"file does not exist")
154 if type(nbv)
is not dict:
155 point = copy.deepcopy(nbv.resulting_pose.position)
156 orientation = copy.deepcopy(nbv.resulting_pose.orientation)
158 pointDict = nbv[
"resulting_pose"][
"position"]
159 point = Point(pointDict[
"x"], pointDict[
"y"], pointDict[
"z"])
160 orientationDict = nbv[
"resulting_pose"][
"orientation"]
161 orientation = Quaternion(orientationDict[
"x"], orientationDict[
"y"], orientationDict[
"z"], orientationDict[
"w"])
162 return Pose(point, orientation)
166 if type(nbv)
is dict:
167 robotState = nbv[
"robot_state"]
168 return ((robotState[
"x"], robotState[
"y"], math.degrees(robotState[
"rotation"])), (math.degrees(robotState[
"pan"]), math.degrees(robotState[
"tilt"])))
170 robotState = nbv.robot_state
171 return ((robotState.x, robotState.y, math.degrees(robotState.rotation)), (math.degrees(robotState.pan), math.degrees(robotState.tilt)))
174 nbvPositions = map(
lambda nbvResult: nbvResult[
"resulting_pose"][
"position"], nbvs)
175 nbvNPPos = map(
lambda p: np.array([p[
"x"], p[
"y"], p[
"z"]]), nbvPositions)
177 for i
in range(0, len(nbvNPPos) - 1):
178 sum += np.linalg.norm(nbvNPPos[i] - nbvNPPos[i+1])
182 if type(pose)
is not list:
184 rate_viewports = rospy.ServiceProxy(
"/nbv/rate_viewports", RateViewports)
188 oldPos = (basePos, ptuPos)
194 print(str((basePos, ptuPos)))
200 pub = rospy.Publisher(
"/nbv/viewportsVisualization", MarkerArray, queue_size=10)
203 if type(poses)
is not list:
205 viewportMarkers = MarkerArray()
210 newMarker.color.r = 1.0
211 newMarker.color.a = 1.0
212 newMarker.scale.x = 0.05
213 newMarker.scale.y = 0.05
214 newMarker.scale.z = 0.05
215 lowerPoint = copy.deepcopy(pose.position)
217 upperPoint = copy.deepcopy(pose.position)
218 newMarker.points.append(lowerPoint)
219 newMarker.points.append(upperPoint)
220 newMarker.header.frame_id =
"/map" 221 newMarker.ns =
"viewports" 222 newMarker.id = 0 + i * 2
223 newMarker.type = Marker.LINE_LIST
224 newMarker.action = Marker.ADD
225 viewportMarkers.markers.append(newMarker)
228 newMarker.color.r = 1.0
229 newMarker.color.a = 1.0
230 newMarker.scale.x = 0.5
231 newMarker.scale.y = 0.05
232 newMarker.scale.z = 0.05
233 newMarker.pose.position = pose.position
235 newMarker.pose.orientation = pose.orientation
236 newMarker.header.frame_id =
"/map" 237 newMarker.ns =
"viewports" 238 newMarker.id = 1 + i * 2
239 newMarker.type = Marker.ARROW
240 newMarker.action = Marker.ADD
241 viewportMarkers.markers.append(newMarker)
244 pub.publish(viewportMarkers)
247 if type(nbvs)
is not list:
def restartPanes(windowAndPanes)
def setOldcacheParameters()
def nbvUpdateFromNBV(nbv)
def moveBase(x, y, rotation)
def getPCAndViewportsFromLog(logDir, idx)
def setOptcacheParameters()
def getNumberOfNBVs(logDir)
def setPositionAndOrientation(positionAndOrientation)
def getPositionAndOrientationFromNBV(nbv)
def getCurrentCameraPose()
def restartAndWaitForNBV()
def setPCAndViewportsFromLog(logDir, idx)
def waitForAllModules(silence=False)
def getTotalDistance(nbvs)
def getOptimalNBV(logDir, idx, positionAndOrientation)
def saveYaml(file, dataMap, flow_style=False)
def nbvUpdate(pose, obj_types)
def setPC(pointcloud, viewports)