map_server包提供了一個(gè)**map_server
**ROS Node, 該node通過(guò)ROS Service方式提供地圖數(shù)據(jù)。 該包還提供了map_saver
命令行utility, 使用該工具可將動(dòng)態(tài)創(chuàng)建的地圖保存成文件。
1 Map format
使用該包中提供的工具可以操控的地圖被存儲(chǔ)在2個(gè)文件中。 一個(gè)是YAML格式的文件描述地圖meta-data并命名image文件腿准。另一個(gè)image文件用來(lái)編碼occupancy-data乡小。
1.1 Image format
image用不同的像素顏色描述世界中每個(gè)cell的占用狀態(tài)翅溺。白色像素表示free,黑色像素表示occupied, 其它顏色像素表示unknown诀黍。 彩色圖和灰度圖都可以袋坑,但是多數(shù)是灰度圖。在YAML文件中使用閾值來(lái)區(qū)分3種類別眯勾。
當(dāng)image中像素與閾值參數(shù)比較時(shí)候枣宫,需要先按照公式occ = (255 - color_avg) / 255.0
計(jì)算占用概率, 這里color_avg是用8位數(shù)表示的來(lái)自于所有通道的平均值。例如吃环,如果image是24-bit顏色也颤,擁有0x0a0a0a顏色
的像素,其概率是0.96郁轻,這意味著幾乎完全占用翅娶。
如果像素顏色是0xeeeeee,則占用概率是
0.07, 這意味著幾乎沒(méi)有被占用好唯。
當(dāng)使用ROS消息通信時(shí)候竭沫,這種占用被表示為范圍[0,100]之內(nèi)的一個(gè)整數(shù), 0的意思是完全free, 100的意思是完全occupied, -1表示完全unknown骑篙。
Image data被 SDL_Image庫(kù)讀取蜕提, 依賴在特定平臺(tái)上SDL_Image將提供什么東西,SDL_Image相應(yīng)支持格式也會(huì)有差異靶端。一般來(lái)講贯溅,多數(shù)常用image格式都已經(jīng)被支持了。一個(gè)必須要注意的例外是PNG格式在OS X平臺(tái)上不能被支持躲查。
1.2 YAML format
以下是YAML格式的一個(gè)示例:
image: testmap.pngresolution: 0.1origin: [0.0, 0.0, 0.0]occupied_thresh: 0.65free_thresh: 0.196negate: 0
需要的字段:
image : 指定包含occupancy data的image文件路徑; 可以是絕對(duì)路徑,也可以是相對(duì)于YAML文件的對(duì)象路徑
resolution : 地圖分辨率译柏,單位是meters / pixel
origin : The 2-D pose of the lower-left pixel in the map, 表示為 (x, y, yaw), 這里yaw是逆時(shí)針旋轉(zhuǎn)角度(yaw=0意味著沒(méi)有旋轉(zhuǎn))镣煮。目前多數(shù)系統(tǒng)忽略yaw值。
occupied_thresh : 像素的占用概率比該閾值大被看做完全占用
free_thresh : 像素的占用概率比該閾值小被看做完全free
negate : Whether the white/black free/occupied semantics should be reversed (interpretation of thresholds is unaffected)
2 Command-line Tools
2.1 map_server(地圖服務(wù)器)
map_server
是一個(gè)ROS node鄙麦,可以從磁盤讀取地圖并使用ROS service提供地圖典唇。 目前實(shí)現(xiàn)的map_server可將地圖中的顏色值轉(zhuǎn)化成三種占用值: free (0), occupied (100), and unknown (-1). 未來(lái)可用0~100之間的不同值指示占用度。
2.1.1 命令語(yǔ)法
map_server <map.yaml>
2.1.2 示例
rosrun map_server map_server mymap.yaml
注意:map data可以通過(guò)指定topic或者 service來(lái)提取胯府。service的方式最后可能要被廢棄介衔。
2.1.3 發(fā)布的主題
map_metadata
(nav_msgs/MapMetaData)Receive the map metadata via this latched topic.
map
(nav_msgs/OccupancyGrid)Receive the map via this latched topic.
2.1.4 服務(wù)
static_map
(nav_msgs/GetMap)Retrieve the map via this service.
2.1.5 參數(shù)
~frame_id
(string
, default: "map"
) The frame to set in the header of the published map.
2.2 map_saver(地圖保存器)
map_saver
可以把地圖保存到磁盤。 例如:from a SLAM mapping service.2.2.1 命令語(yǔ)法
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.
2.2.2 命令示例
rosrun map_server map_saver -f mymap
2.2.3 訂閱的主題
map
(nav_msgs/OccupancyGrid) Map will be retrieved via this latched topic