ros:map_sever

map_server provides the map_server ROS Node, which offers map data as a ROS Service. It also provides the map_saver command-line utility, which allows dynamically generated maps to be saved to file.

Map format
Maps manipulated by the tools in this package are stored in a pair of files. The YAML file describes the map meta-data, and names the image file. The image file encodes the occupancy data.

YAML format
The YAML format is best explained with a simple, complete example:

image: testmap.png
resolution: 0.1
origin: [0.0, 0.0, 0.0]
occupied_thresh: 0.65
free_thresh: 0.196
negate: 0
Required fields:

image : Path to the image file containing the occupancy data; can be absolute, or relative to the location of the YAML file

resolution : Resolution of the map, meters / pixel

origin : The 2-D pose of the lower-left pixel in the map, as (x, y, yaw), with yaw as counterclockwise rotation (yaw=0 means no rotation). Many parts of the system currently ignore yaw.

occupied_thresh : Pixels with occupancy probability greater than this threshold are considered completely occupied.

free_thresh : Pixels with occupancy probability less than this threshold are considered completely free.

negate : Whether the white/black free/occupied semantics should be reversed (interpretation of thresholds is unaffected)

Optional parameter:

mode : Can have one of three values: trinary, scale, or raw. Trinary is the default. More information on how this changes the value interpretation is in the next section.

Value Interpretation
Given a pixel that has a COLOR value x in the range [0, 256), how should we interpret this value when put into the ROS message? First we convert integer x to a floating point number p depending on the interpretation of the negate flag from the yaml.

If negate is false, p = (255 - x) / 255.0. This means that black (0) now has the highest value (1.0) and white (255) has the lowest (0.0).

If negate is true, p = x / 255.0. This is the non-standard interpretation of images, which is why it is called negate, even though the math indicates that x is not negated. Nomenclature is hard.

Trinary
The standard interpretation is the trinary interpretation, i.e. interpret all values so that the output ends up being one of three values.

If p > occupied_thresh, output the value 100 to indicate the cell is occupied.
If p < free_thresh, output the value 0 to indicate the cell is free.
Otherwise, output -1 a.k.a. 255 (as an unsigned char), to indicate that the cell is unknown.

Scale
This tweaks the above interpretation to allow for more output values than trinary.

As before if p > occupied_thresh, output the value 100. If p < free_thresh, output the value 0.

Otherwise, output 99 * (p - free_thresh) / (occupied_thresh - free_thresh)

This will allow you to output a full gradient of values ranging from [0, 100]. To output -1, simply use the alpha channel of a png, where any transparency will be interpreted as unknown.

Raw
This mode will output x for each pixel, so output values are [0, 255].

Command-line Tools

map_server
map_server is a ROS node that reads a map from disk and offers it via a ROS service.
The current implementation of the map_server converts color values in the map image data into ternary occupancy values: free (0), occupied (100), and unknown (-1). Future versions of this tool may use the values between 0 and 100 to communicate finer gradations of occupancy.

Usage

map_server <map.yaml>
Example

rosrun map_server map_server mymap.yaml
Note that the map data may be retrieved via either latched topic (meaning that it is sent once to each new subscriber), or via service. The service may eventually be phased out.

Published Topics
map_metadata (nav_msgs/MapMetaData)
Receive the map metadata via this latched topic.
map (nav_msgs/OccupancyGrid)
Receive the map via this latched topic.
Services
static_map (nav_msgs/GetMap)
Retrieve the map via this service.
Parameters
~frame_id (string, default: “map”)
The frame to set in the header of the published map.

map_saver
map_saver saves a map to disk, e.g., from a SLAM mapping service.
Usage

rosrun map_server map_saver [-f mapname]
map_saver retrieves map data and writes it out to map.pgm and map.yaml. Use the -f option to provide a different base name for the output files.

Example

rosrun map_server map_saver -f mymap

Subscribed Topics
map (nav_msgs/OccupancyGrid)
Map will be retrieved via this latched topic.

简单地说,map_server 提供了获取地图数据和保存地图数据的方法;获取地图数据通过map_server节点实现,保存数据通过map_saver节点订阅/map话题实现。

当运行出现下面错误时,可以通过rqt_graph看节点之间是否连通,需要注意的是,map_saver订阅的是/map 话题;
rosrun map_server map_saver -f mymap
[ INFO] [1541980723.161416738]: Waiting for the map

这些代码行似乎是用于初始化ROS(Robot Operating System)中的发布者(Publisher)对象。ROS是一个用于机器人软件开发的灵活框架,它提供了一种标准的方法来进行通信和服务。在这个上下文中,`ros::Publisher` 是ROS中用于向特定话题(topic)发布消息的类。 每个 `ros::Publisher` 对象都关联着一个特定的话题,这个话题是节点间交换消息的通道。例如: - `right_rectangles`:这个发布者可能用于发布与右方矩形相关的信息,比如在一个视觉处理系统中,可能包含了右视图中检测到的所有矩形的位置和尺寸等信息。 - `left_rectangles`:与 `right_rectangles` 类似,但可能用于发布左视图中的矩形信息。 - `right_yoloPub`:可能用于发布右视图中使用YOLO(You Only Look Once)算法检测到的目标检测信息。 - `left_yoloPub`:同 `right_yoloPub`,但用于左视图的目标检测信息。 在ROS中,发布者创建后需要指定它们将要发布的消息类型,以及它们将要发布到的话题名。例如,如果它们用于发布标准的ROS消息类型如 `std_msgs::String` 或者自定义的消息类型,那么在使用这些发布者之前,需要将它们与相应的消息类型和话题名绑定。 例如: ```cpp right_rectangles = nh.advertise<geometry_msgs::PolygonStamped>("right_rectangles_topic", 1000); left_rectangles = nh.advertise<geometry_msgs::PolygonStamped>("left_rectangles_topic", 1000); right_yoloPub = nh.advertise<yolo_msgs::Detection>("right_yolo_topic", 1000); left_yoloPub = nh.advertise<yolo_msgs::Detection>("left_yolo_topic", 1000); ``` 在这个例子中,`nh` 是一个 `ros::NodeHandle` 对象,它用于节点与ROS系统的交互。`advertise` 方法用于创建发布者并将其绑定到特定的话题上,同时设置发布消息的缓存大小。这里 `geometry_msgs::PolygonStamped` 和 `yolo_msgs::Detection` 分别是用于矩形和YOLO目标检测信息的消息类型。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值