当前位置: 首页>>代码示例>>Python>>正文


Python OccupancyGrid.data方法代码示例

本文整理汇总了Python中nav_msgs.msg.OccupancyGrid.data方法的典型用法代码示例。如果您正苦于以下问题:Python OccupancyGrid.data方法的具体用法?Python OccupancyGrid.data怎么用?Python OccupancyGrid.data使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在nav_msgs.msg.OccupancyGrid的用法示例。


在下文中一共展示了OccupancyGrid.data方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: publish

# 需要导入模块: from nav_msgs.msg import OccupancyGrid [as 别名]
# 或者: from nav_msgs.msg.OccupancyGrid import data [as 别名]
    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,代码行数:34,代码来源:nodes.py

示例2: map_message

# 需要导入模块: from nav_msgs.msg import OccupancyGrid [as 别名]
# 或者: from nav_msgs.msg.OccupancyGrid import data [as 别名]
    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,代码行数:28,代码来源:gpmaps.py

示例3: setUp

# 需要导入模块: from nav_msgs.msg import OccupancyGrid [as 别名]
# 或者: from nav_msgs.msg.OccupancyGrid import data [as 别名]
        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:,项目名称:,代码行数:32,代码来源:

示例4: updateCoverage

# 需要导入模块: from nav_msgs.msg import OccupancyGrid [as 别名]
# 或者: from nav_msgs.msg.OccupancyGrid import data [as 别名]
    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,代码行数:28,代码来源:robot_perception.py

示例5: to_message

# 需要导入模块: from nav_msgs.msg import OccupancyGrid [as 别名]
# 或者: from nav_msgs.msg.OccupancyGrid import data [as 别名]
    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,代码行数:29,代码来源:mapper.py

示例6: atlaas_grid

# 需要导入模块: from nav_msgs.msg import OccupancyGrid [as 别名]
# 或者: from nav_msgs.msg.OccupancyGrid import data [as 别名]
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,代码行数:27,代码来源:rosgrid.py

示例7: load_map

# 需要导入模块: from nav_msgs.msg import OccupancyGrid [as 别名]
# 或者: from nav_msgs.msg.OccupancyGrid import data [as 别名]
    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,代码行数:30,代码来源:point_2_world.py

示例8: pubMap

# 需要导入模块: from nav_msgs.msg import OccupancyGrid [as 别名]
# 或者: from nav_msgs.msg.OccupancyGrid import data [as 别名]
 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,代码行数:27,代码来源:octomapSub.py

示例9: occ_grid_cb

# 需要导入模块: from nav_msgs.msg import OccupancyGrid [as 别名]
# 或者: from nav_msgs.msg.OccupancyGrid import data [as 别名]
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,代码行数:27,代码来源:map_reduction.py

示例10: read_map

# 需要导入模块: from nav_msgs.msg import OccupancyGrid [as 别名]
# 或者: from nav_msgs.msg.OccupancyGrid import data [as 别名]
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,代码行数:31,代码来源:mapNode.py

示例11: handleSearchedCombinedMessage

# 需要导入模块: from nav_msgs.msg import OccupancyGrid [as 别名]
# 或者: from nav_msgs.msg.OccupancyGrid import data [as 别名]
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,代码行数:29,代码来源:findFrontierCells.py

示例12: updateCombined

# 需要导入模块: from nav_msgs.msg import OccupancyGrid [as 别名]
# 或者: from nav_msgs.msg.OccupancyGrid import data [as 别名]
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,代码行数:31,代码来源:searchedCombine.py

示例13: viz_data

# 需要导入模块: from nav_msgs.msg import OccupancyGrid [as 别名]
# 或者: from nav_msgs.msg.OccupancyGrid import data [as 别名]
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,代码行数:35,代码来源:astar.py

示例14: run

# 需要导入模块: from nav_msgs.msg import OccupancyGrid [as 别名]
# 或者: from nav_msgs.msg.OccupancyGrid import data [as 别名]
 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,代码行数:61,代码来源:localization.py

示例15: ExpandMap

# 需要导入模块: from nav_msgs.msg import OccupancyGrid [as 别名]
# 或者: from nav_msgs.msg.OccupancyGrid import data [as 别名]
def ExpandMap(occupancyGrid):

	lowerResGrid = OccupancyGrid(occupancyGrid.header, occupancyGrid.info, [])

	oldWidth = occupancyGrid.info.width

	lowerResGrid.info.resolution = .1
	lowerResGrid.info.width = int(math.floor(float(occupancyGrid.info.width)/2))
	lowerResGrid.info.height = int(math.floor(float(occupancyGrid.info.height)/2))

	width = lowerResGrid.info.width
	height = lowerResGrid.info.height

	lowerResGrid.data = [-1]*width*height

	for i in range (0, height):
		for j in range (0, width):
			if occupancyGrid.data[(j*2) + (oldWidth * i*2)] >= 1 or \
				occupancyGrid.data[(j*2) + (oldWidth * ((i*2)+1))] >= 1 or \
				occupancyGrid.data[(j*2)+1 + (oldWidth * i*2)] >= 1 or \
				occupancyGrid.data[(j*2)+1 + (oldWidth * ((i*2)+1))] >= 1:
				lowerResGrid.data[j + (width * i)] = 100
			elif occupancyGrid.data[(j*2) + (oldWidth * i*2)] == 0 and \
				occupancyGrid.data[(j*2) + (oldWidth * ((i*2)+1))] == 0 and \
				occupancyGrid.data[(j*2)+1 + (oldWidth * i*2)] == 0 and \
				occupancyGrid.data[(j*2)+1 + (oldWidth * ((i*2)+1))] == 0:
				lowerResGrid.data[j + (width * i)] = 0
			else:
				lowerResGrid.data[j + (width * i)] = -1

	expandedGrid = OccupancyGrid(lowerResGrid.header, lowerResGrid.info, lowerResGrid.data)

	expandedData = list(lowerResGrid.data)

	print "expanding"
	for i in range (0, height):
		for j in range (0, width):
			if (lowerResGrid.data[j + (width * i)] >= 1):
				for k in range (j - 2, j + 3):
					for l in range (i - 2, i + 3):
						if (k > 0 and k < width and l > 0 and l < height):
							expandedData[k + (width * l)] = 100

	expandedGrid.data = tuple(expandedData)
	print "expanded"
	return expandedGrid, lowerResGrid
开发者ID:jbmorse,项目名称:catkin_ws,代码行数:48,代码来源:ObstacleExpansion.py


注:本文中的nav_msgs.msg.OccupancyGrid.data方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。