本文整理汇总了Python中nav_msgs.msg.OccupancyGrid.data[y*w+x]方法的典型用法代码示例。如果您正苦于以下问题:Python OccupancyGrid.data[y*w+x]方法的具体用法?Python OccupancyGrid.data[y*w+x]怎么用?Python OccupancyGrid.data[y*w+x]使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nav_msgs.msg.OccupancyGrid
的用法示例。
在下文中一共展示了OccupancyGrid.data[y*w+x]方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: OptimizeOccupancyGrid
# 需要导入模块: from nav_msgs.msg import OccupancyGrid [as 别名]
# 或者: from nav_msgs.msg.OccupancyGrid import data[y*w+x] [as 别名]
def OptimizeOccupancyGrid(data):
## Tuning Constants
maxUnknownPercent = 0.50#% # Used to speed up the condensing step
global holster, newmap, newMapPub, w,h
# Set newmap meta data
newres = 0.20 #.2m = radius of robot
oldRes = data.info.resolution
w = math.trunc(data.info.width*oldRes/newres)
h = math.trunc(data.info.height*oldRes/newres)
#Calculate new origin
x = data.info.origin.position.x
y = data.info.origin.position.y
origin = Point(x, y,0)
newPose = Pose(origin, data.info.origin.orientation )
## Create new map to send
newHeader = Header(1,rospy.get_rostime(),'map')
metaData = MapMetaData(rospy.get_rostime(), newres,w, h, newPose )
newmap = OccupancyGrid( newHeader, metaData, [])
newmap.data = [-1]*w*h #clear the list
cellsPerSide = newres/oldRes
if cellsPerSide % 1 >= 0.5:
cellsPerSide = int(math.ceil(cellsPerSide)) # idk... its usually 3.9999
else:
cellsPerSide = int(math.trunc(cellsPerSide))
for x in range(w):
for y in range(h):
######### Function to compress map cells
newVal = cellShrinker(x,y, cellsPerSide, maxUnknownPercent)
newmap.data[y*w + x] = math.trunc(newVal)
expandedMap = [-1]*w*h #clear the list
for x in range(w):
for y in range(h):
expandedMap[y*w + x] = expandCell(x,y )
newMapPub.publish(newmap)