本文整理汇总了Python中nav_msgs.msg.OccupancyGrid类的典型用法代码示例。如果您正苦于以下问题:Python OccupancyGrid类的具体用法?Python OccupancyGrid怎么用?Python OccupancyGrid使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了OccupancyGrid类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: map_message
def map_message(self):
""" Return a nav_msgs/OccupancyGrid representation of this map. """
grid_msg = OccupancyGrid()
grid_msg.header.stamp = rospy.Time.now()
grid_msg.header.frame_id = "map"
grid_msg.info.resolution = self.occ_map.map_res
grid_msg.info.width = self.occ_map.width
grid_msg.info.height = self.occ_map.height
grid_msg.info.origin = Pose(Point(self.occ_map.map_limit[0], self.occ_map.map_limit[2], 0),
Quaternion(0, 0, 0, 1))
flat_grid = copy.deepcopy(self.map.reshape((self.occ_map.map_size,)))
for i in range(self.occ_map.map_size):
if flat_grid[i] > self.occ_map.prob_occ:
flat_grid[i] = 100
elif flat_grid[i] < self.occ_map.prob_free:
flat_grid[i] = 0
else:
flat_grid[i] = -1
flat_grid = np.round(flat_grid)
flat_grid = flat_grid.astype(int)
grid_msg.data = list(flat_grid)
return grid_msg
开发者ID:MaaniGhaffari,项目名称:gp_occ_mapping,代码行数:26,代码来源:gpmaps.py
示例2: setUp
def setUp(self):
og = OccupancyGrid()
og.info.resolution = 0.5
og.info.height = 20
og.info.width = 20
og.info.origin.position.x = 0.0
og.info.origin.position.y = 0.0
og.info.origin.position.y = 0.0
og.info.origin.orientation.z = 0.0
og.info.origin.orientation.w = 0.0
og.info.origin.orientation.x = 0.0
og.info.origin.orientation.y = 0.0
mapArray = np.array([0] * 400)
mapArray.shape = (20, 20)
for xi in range(20):
for yi in range(20):
if xi < 3 or xi > 15:
mapArray[xi, yi] = 100
if yi < 3 or yi > 15:
mapArray[xi, yi] = 100
if yi < 10 and xi > 10:
mapArray[xi, yi] = 75
mapArray.shape = 400
og.data = list(mapArray)
self.mapData = MapData(og)
开发者ID:,项目名称:,代码行数:30,代码来源:
示例3: occ_grid_cb
def occ_grid_cb(data):
global p,ready,first
rospy.loginfo("map_reduction.py:occ_grid_cb() /ready_for_wps: %s",str(ready))
if not ready.data:
return
nav_map = OccupancyGrid()
w,h = data.info.width,data.info.height
pt = data.data
p = array(pt).reshape(w,h)#.T #<-- Transposes
if not 'grid_loc' in globals():
return
x,y = grid_loc.position.x, grid_loc.position.y
nav_map.info = data.info
if not 'size' in globals():
size = 64
if 'rtl' in globals() and rtl:
##Intelligently set mapsize, scale map, and send waypoints to home
pass
nav_map.info.width = size
nav_map.info.height = size
tmp_map = p[int(x)-size/2:int(x)+size/2,int(y)-size/2:int(y)+size/2]
if first:
tmp_map[:,:size/2] = 100
nav_map.data = tmp_map.flatten()
nav_map_pub.publish(nav_map)
开发者ID:UAVMasterLabs,项目名称:offboard_control,代码行数:25,代码来源:map_reduction.py
示例4: updateCoverage
def updateCoverage(self):
# Reinitialize coverage map
ogm_shape = self.ogm.shape
self.coverage = numpy.zeros(ogm_shape)
# YOUR CODE HERE ------------------------------------------------------
# Update the coverage field using the self.robot_path veriable.
# We suppose that in every pose the robot covers an area of 2m x 2m
# around it
# 0 is for the uncovered, 100 is for the covered
# PS. Try to make it fast :)
# PS2. Do not have coverage values on obstacles or unknown space!
# If done correctly, the coverage will appear purple in rviz
# ---------------------------------------------------------------------
# Publishing coverage ogm to see it in rviz
coverage_ogm = OccupancyGrid()
coverage_ogm.header.frame_id = "map"
coverage_ogm.info = self.ogm_info
coverage_ogm.data = numpy.zeros(self.ogm_info.width * self.ogm_info.height)
for i in range(0, self.ogm_info.width):
for j in range(0, self.ogm_info.height):
coverage_ogm.data[i + self.ogm_info.width * j] = self.coverage[i][j]
self.coverage_publisher.publish(coverage_ogm)
开发者ID:ApostolosPournaras,项目名称:autonomous_systems_architectures,代码行数:26,代码来源:robot_perception.py
示例5: processOccupancyGrid
def processOccupancyGrid(gridMessage, scaleFactor, cacheEmptyCells):
grid = OccupancyGrid(gridMessage.data, gridMessage.info.height, gridMessage.info.width, gridMessage.info.resolution,
(gridMessage.info.origin.position.x, gridMessage.info.origin.position.y))
grid.scale(scaleFactor, cacheEmptyCells=cacheEmptyCells)
grid.expandObstacles()
return grid
开发者ID:aaravrav142,项目名称:Turtlebot_Navigation,代码行数:7,代码来源:mapping.py
示例6: to_message
def to_message(self):
""" Return a nav_msgs/OccupancyGrid representation of this map. """
grid_msg = OccupancyGrid()
# Set up the header.
grid_msg.header.stamp = rospy.Time.now()
grid_msg.header.frame_id = "map"
# .info is a nav_msgs/MapMetaData message.
grid_msg.info.resolution = self.resolution
grid_msg.info.width = self.width
grid_msg.info.height = self.height
# Rotated maps are not supported... quaternion represents no
# rotation.
grid_msg.info.origin = Pose(Point(self.origin_x, self.origin_y, 0),
Quaternion(0, 0, 0, 1))
# Flatten the numpy array into a list of integers from 0-100.
# This assumes that the grid entries are probalities in the
# range 0-1. This code will need to be modified if the grid
# entries are given a different interpretation (like
# log-odds).
flat_grid = self.grid.reshape((self.grid.size,)) * 100
grid_msg.data = list(np.round(flat_grid))
return grid_msg
开发者ID:pscho,项目名称:phantomx_arm,代码行数:27,代码来源:mapper.py
示例7: atlaas_grid
def atlaas_grid(filepath, var_threshold=0.1, stamp=None, frame_id="/map"):
""" Usage:
atlaas.merge("atlaas.*x*.tif", "out.tif")
if os.path.isfile("out.tif"):
atlaas_grid("out.tif")
"""
g = gdal2(filepath)
bnp = g.bands[g.names["N_POINTS"]]
bma = g.bands[g.names["Z_MAX"]]
bme = g.bands[g.names["Z_MEAN"]]
bva = g.bands[g.names["VARIANCE"]]
data = numpy.where(bva > var_threshold, bma, bme)
delta = data.max() - data.min()
ddis = (100.0 * (data - data.min()) / delta).astype("uint8")
ddis[bnp < 1] = 0 # no points, unknown
og = OccupancyGrid()
og.data = ddis.flatten()
if stamp:
og.header.stamp = stamp
og.header.frame_id = frame_id
og.info.resolution = g.scale_x
og.info.height, og.info.width = data.shape
og.info.origin.position.x, og.info.origin.position.y = g.u2c(g.utm_x, g.utm_y)
og.info.origin.orientation.x = 1 # flip to transform UTM-ROS (scale_y < 0)
return og
开发者ID:pierriko,项目名称:atlaas,代码行数:25,代码来源:rosgrid.py
示例8: load_map
def load_map(fp):
ogrid = OccupancyGrid()
step = None
offset = None
yaml_file = fp + ".yaml"
csv_file = fp + ".csv"
with open(yaml_file, "r") as infile:
for k, v in yaml.load(infile.read()).iteritems():
if k == "Header":
ogrid.header = v
elif k == "MapMetaData":
ogrid.info = v
step = v.resolution
offset = (v.origin.position.x, v.origin.position.y)
elif k == "GridFile":
print "GridFile: ", v
else:
print "Unexpected k : ", k
raise TypeError("Unexpected key type in yaml file: " + yaml_file)
ogrid.data = list(np.loadtxt(csv_file, dtype=np.int8, delimiter=","))
print "Map loaded"
return ogrid, step, offset
开发者ID:kekraft,项目名称:contamination_stack,代码行数:28,代码来源:point_2_world.py
示例9: updateCombined
def updateCombined():
global data0
global data1
global data2
global mapData
global searchedCombinePub
rospy.wait_for_message('robot_0/robotSearched', OccupancyGrid, timeout=None)
rospy.wait_for_message('robot_1/robotSearched', OccupancyGrid, timeout=None)
rospy.wait_for_message('robot_2/robotSearched', OccupancyGrid, timeout=None)
mapMsg=OccupancyGrid()
while not rospy.is_shutdown():
map0 = numpy.array(data0.data)
map1 = numpy.array(data1.data)
map2 = numpy.array(data2.data)
combined = numpy.minimum(map0,map1)
combined = numpy.minimum(combined,map2)
mapMsg.header.stamp=rospy.Time.now()
mapMsg.header.frame_id=mapData.header.frame_id
mapMsg.info.resolution=mapData.info.resolution
mapMsg.info.width=mapData.info.width
mapMsg.info.height=mapData.info.height
mapMsg.info.origin=mapData.info.origin
mapMsg.data=combined.tolist()
searchedCombinePub.publish(mapMsg)
rospy.sleep(1.0)
开发者ID:bripappas,项目名称:Gen2_Platforms,代码行数:29,代码来源:searchedCombine.py
示例10: pubMap
def pubMap(self):
# Publish updated map
grid_msg = OccupancyGrid()
grid_msg.header.stamp = rospy.Time.now()
grid_msg.header.frame_id = "map"
# .info is a nav_msgs/MapMetaData message.
grid_msg.info.resolution = self.resolution
grid_msg.info.width = self.map_info.width
grid_msg.info.height = self.map_info.height
# Rotated maps are not supported... quaternion represents no
# rotation.
grid_msg.info.origin = Pose(Point(self.map_origin[0], self.map_origin[1], 0),Quaternion(0, 0, 0, 1))
# Flatten the numpy array into a list of integers from 0-100.
# This assumes that the grid entries are probalities in the
# range 0-1. This code will need to be modified if the grid
# entries are given a different interpretation (like
# log-odds).
flat_grid = self.grid.reshape((self.grid_map.size,)) * 100
grid_msg.data = list(np.round(flat_grid))
self._map_data_pub.publish(grid_msg.info)
self._map_pub.publish(grid_msg)
return grid_msg
开发者ID:ResByte,项目名称:graph_slam,代码行数:25,代码来源:octomapSub.py
示例11: read_map
def read_map(data):
global workingOnMap
workingOnMap = True
print "manually reducing map resolution"
# change the map's resolution
newOccGrid, newMapHeight, newMapWidth = increaseMapResolution(data)
# expand the obstacles
newOccGrid = expandObstacles(newOccGrid, desiredMapRes, newMapWidth, newMapHeight)
# publish the new grid
newPublishedGrid = OccupancyGrid()
newPublishedGrid.info.resolution = desiredMapRes
newPublishedGrid.info.origin.position.x= data.info.origin.position.x
newPublishedGrid.info.origin.position.y= data.info.origin.position.y
newPublishedGrid.info.width = newMapWidth
newPublishedGrid.info.height = newMapHeight
newPublishedGrid.data = tuple(newOccGrid)
print "publishing map"
scaledMapPub.publish(newPublishedGrid)
# publish the amount that the obstacles were expanded by
expansionVal = Float64()
expansionVal.data = expansionWidth
obstacleExpansionDimensionPub.publish(expansionVal)
workingOnMap = False
开发者ID:mandi1267,项目名称:final_project_adkins_caracappa,代码行数:29,代码来源:mapNode.py
示例12: handleSearchedCombinedMessage
def handleSearchedCombinedMessage(data):
global findFrontierPub
#get map dimensions data
width=data.info.width
height=data.info.height
searchedMap = data.data
frontier = [0] * (width * height)
for h in range(height):
for w in range(width):
if searchedMap[h*width+w] == -1:
frontier[h*width+w]=-1
if searchedMap[h*width+w] == 100:
if isFrontier(searchedMap,h,w,height,width):
frontier[h*width+w]=100
mapMsg=OccupancyGrid()
mapMsg.header.stamp=rospy.Time.now()
mapMsg.header.frame_id=data.header.frame_id
mapMsg.info.resolution=data.info.resolution
mapMsg.info.width=width
mapMsg.info.height=height
mapMsg.info.origin=data.info.origin
mapMsg.data=frontier
findFrontierPub.publish(mapMsg)
开发者ID:bripappas,项目名称:Gen2_Platforms,代码行数:27,代码来源:findFrontierCells.py
示例13: publish
def publish(self, publisher, real = False):
costGrid = OccupancyGrid()
costGrid.header.frame_id = self.frame_id
costGrid.header.stamp = rospy.Time.now()
costGrid.info = self.map_info
temparr = copy.deepcopy(self.data) #protect ourselves from volitility
if not real:
# map cost_map to between 0 and 127 for fancy colors in rviz
maxVal = max(temparr)
minVal = float('inf')
for cost in temparr:
if not (cost == 0) and (cost < minVal): minVal = cost
minVal *= 1.01
factor = 90.0/(maxVal - minVal)
if(maxVal == minVal): return
# costGrid.data = [(int((i - minVal) * factor) if (i != 0) else 0) for i in cost_map.data]
costGrid.data = []
for i in temparr:
if(i!=0):
costGrid.data.append(int((i - minVal) * factor))
else:
costGrid.data.append(0)
else: costGrid.data = temparr
publisher.publish(costGrid)
开发者ID:LoganTutt,项目名称:rbe3002,代码行数:32,代码来源:nodes.py
示例14: viz_data
def viz_data(grid, closed):
# Visualize DATA
global pub
global grid_res, grid_transform
occ_msg = OccupancyGrid()
occ_msg.info.resolution = grid_res
occ_msg.info.width = len(grid.nodelist)
occ_msg.info.height = len(grid.nodelist[0])
occ_msg.header.frame_id = "map"
occ_msg.info.origin.position.x = grid_transform[0, 3]
occ_msg.info.origin.position.y = grid_transform[1, 3]
quaternion = tf.transformations.quaternion_from_matrix(grid_transform)
occ_msg.info.origin.orientation.x = quaternion[0]
occ_msg.info.origin.orientation.y = quaternion[1]
occ_msg.info.origin.orientation.z = quaternion[2]
occ_msg.info.origin.orientation.w = quaternion[3]
occ_data = [0] * (occ_msg.info.width * occ_msg.info.height)
width = occ_msg.info.width
height = occ_msg.info.height
# occ_data[width * start.x + start.y] = 100
# occ_data[width * goal.x + goal.y] = 100
top_cost = 1
for node in closed:
if node.g_cost > top_cost:
top_cost = node.g_cost
for node in closed:
cost = node.g_cost / top_cost
cost *= 225
if cost > 99:
cost -= 228
occ_data[width * node.x + node.y] = cost
occ_msg.data = occ_data
pub.publish(occ_msg)
开发者ID:jkuszmaul,项目名称:RBE3002,代码行数:33,代码来源:astar.py
示例15: run
def run(self):
while self.is_looping():
navigation_tf_msg = TFMessage()
try:
motion_to_robot = almath.Pose2D(self.motion.getRobotPosition(True))
localization = self.navigation.getRobotPositionInMap()
exploration_path = self.navigation.getExplorationPath()
except Exception as e:
navigation_tf_msg.transforms.append(self.get_navigation_tf(almath.Pose2D()))
self.publishers["map_tf"].publish(navigation_tf_msg)
self.rate.sleep()
continue
if len(localization) > 0 and len(localization[0]) == 3:
navigation_to_robot = almath.Pose2D(localization[0][0], localization[0][1], localization[0][2])
navigation_to_motion = navigation_to_robot * almath.pinv(motion_to_robot)
navigation_tf_msg.transforms.append(self.get_navigation_tf(navigation_to_motion))
self.publishers["map_tf"].publish(navigation_tf_msg)
if len(localization) > 0:
if self.publishers["uncertainty"].get_num_connections() > 0:
uncertainty = Marker()
uncertainty.header.frame_id = "/base_footprint"
uncertainty.header.stamp = rospy.Time.now()
uncertainty.type = Marker.CYLINDER
uncertainty.scale = Vector3(localization[1][0], localization[1][1], 0.2)
uncertainty.pose.position = Point(0, 0, 0)
uncertainty.pose.orientation = self.get_ros_quaternion(
almath.Quaternion_fromAngleAndAxisRotation(0, 0, 0, 1))
uncertainty.color = ColorRGBA(1, 0.5, 0.5, 0.5)
self.publishers["uncertainty"].publish(uncertainty)
if self.publishers["map"].get_num_connections() > 0:
aggregated_map = None
try:
aggregated_map = self.navigation.getMetricalMap()
except Exception as e:
print("error " + str(e))
if aggregated_map is not None:
map_marker = OccupancyGrid()
map_marker.header.stamp = rospy.Time.now()
map_marker.header.frame_id = "/map"
map_marker.info.resolution = aggregated_map[0]
map_marker.info.width = aggregated_map[1]
map_marker.info.height = aggregated_map[2]
map_marker.info.origin.orientation = self.get_ros_quaternion(
almath.Quaternion_fromAngleAndAxisRotation(-1.57, 0, 0, 1))
map_marker.info.origin.position.x = aggregated_map[3][0]
map_marker.info.origin.position.y = aggregated_map[3][1]
map_marker.data = aggregated_map[4]
self.publishers["map"].publish(map_marker)
if self.publishers["exploration_path"].get_num_connections() > 0:
path = Path()
path.header.stamp = rospy.Time.now()
path.header.frame_id = "/map"
for node in exploration_path:
current_node = PoseStamped()
current_node.pose.position.x = node[0]
current_node.pose.position.y = node[1]
path.poses.append(current_node)
self.publishers["exploration_path"].publish(path)
self.rate.sleep()
开发者ID:lsouchet,项目名称:naoqi_bridge,代码行数:59,代码来源:localization.py
示例16: get_message
def get_message(self):
ogrid = OccupancyGrid()
ogrid.header = navigator_tools.make_header(frame="enu")
ogrid.info.resolution = self.resolution
ogrid.info.height, ogrid.info.width = self.grid.shape
ogrid.info.origin = self.origin
grid = np.copy(self.grid)
ogrid.data = np.clip(grid.flatten() - 1, -100, 100).astype(np.int8)
return ogrid
开发者ID:uf-mil,项目名称:Navigator,代码行数:10,代码来源:start_gate.py
示例17: pub_grid
def pub_grid(self, *args):
grid = self.grid_drawer.img
ogrid = OccupancyGrid()
ogrid.header.frame_id = '/enu'
ogrid.header.stamp = rospy.Time.now()
ogrid.info = self.map_meta_data
ogrid.data = np.subtract(np.flipud(grid).flatten(), 1).astype(np.int8).tolist()
self.ogrid_pub.publish(ogrid)
开发者ID:mattlangford,项目名称:Navigator,代码行数:10,代码来源:ogrid_draw.py
示例18: publishCombined
def publishCombined(self):
#Enter Main Loop
while not rospy.is_shutdown():
#Convert to Numpy Arrays
map = []
for i in range(0, self.numRobots):
map.append(numpy.array(self.searchedData[i].data))
combined2 = map[0]
if self.numRobots > 1:
#Find Minimum of all maps
for i in range(1, self.numRobots):
combined2 = numpy.minimum(combined2,map[i])
#Pack Occupancy Grid Message
mapMsg=OccupancyGrid()
mapMsg.header.stamp=rospy.Time.now()
mapMsg.header.frame_id=self.mapData.header.frame_id
mapMsg.info.resolution=self.mapData.info.resolution
mapMsg.info.width=self.mapData.info.width
mapMsg.info.height=self.mapData.info.height
mapMsg.info.origin=self.mapData.info.origin
mapMsg.data=combined2.tolist()
#Convert combined Occupancy grid values to grayscal image values
combined2[combined2 == -1] = 150 #Unknown -1->150 (gray)
combined2[combined2 == 100] = 255 #Not_Searched 100->255 (white)
#Searched=0 (black)
#Calculate percentage of open area searched
numNotSearched = combined2[combined2==255].size
numSearched = combined2[combined2==0].size
percentSearched = 100*float(numSearched)/(numNotSearched+numSearched)
percentSearchedMsg = Float32()
percentSearchedMsg.data = percentSearched
self.percentPub.publish(percentSearchedMsg)
#Pack Image Message
imageMsg=Image()
imageMsg.header.stamp = rospy.Time.now()
imageMsg.header.frame_id = self.mapData.header.frame_id
imageMsg.height = self.mapData.info.height
imageMsg.width = self.mapData.info.width
imageMsg.encoding = 'mono8'
imageMsg.is_bigendian = 0
imageMsg.step = self.mapData.info.width
imageMsg.data = combined2.tolist()
#Publish Combined Occupancy Grid and Image
self.searchedCombinePub.publish(mapMsg)
self.imagePub.publish(imageMsg)
#Update Every 0.5 seconds
rospy.sleep(1.0)
开发者ID:bripappas,项目名称:Gen2_Platforms,代码行数:55,代码来源:combineSearchSpace.py
示例19: to_message
def to_message(self):
""" Return a nav_msgs/OccupancyGrid representation of this map. """
grid_msg = OccupancyGrid()
grid_msg.header.stamp = rospy.Time.now()
grid_msg.header.frame_id = "map"
grid_msg.info.resolution = self.resolution
grid_msg.info.width = self.width
grid_msg.info.height = self.height
grid_msg.info.origin = Pose(Point(self.origin_x, self.origin_y, 0), Quaternion(0, 0, 0, 1))
grid_msg.data = self._numpy_to_data()
return grid_msg
开发者ID:JoeyNeidigh,项目名称:robo_cleanup,代码行数:11,代码来源:map_utils.py
示例20: convert_to_occ_grid
def convert_to_occ_grid(self):
res = OccupancyGrid()
res.header.stamp = rospy.Time.now()
res.header.frame_id = "odom_combined"
res.info.resolution = 0.1
res.info.width = 1000
res.info.height = 1000
res.info.origin.position.x = -50
res.info.origin.position.y = -50
res.data = self.grid
return res
开发者ID:anyfilatov,项目名称:Everything,代码行数:11,代码来源:graph_slam_.py
注:本文中的nav_msgs.msg.OccupancyGrid类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论