Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.


本页介绍了composite_map_demo的用法, 主要包含对.stcm地图格式的composite map的读写操作


本页内容

Table of Contents
stylesquare


运行环境准备

  • 软件平台

    • Visual Studio 2010  SP1
    • Slamware Windows SDK:Slamware Windows SDK
    • RoboStudio(用于显示地图):Robostudio installer 
    • Sample Code: 

      Info

      使用更高版本的Visual Studio可能会带来编译异常。

      使用Visual Studio 2010(无SP1)可能会因为无法与.Net Framework兼容而报编译错误,此时增加SP1更新包即可解决问题


  • 硬件平台

          (以下任选其一)

    • Slamware SDP mini 
    • Slamware SDP
    • Slamware 套装 (基于Slamware导航方案的用户机器人系统)
    • Zeus/Apollo等底盘系统
编译运行

例程下载

打开samples工程

Win32-例程下载

Image Removed

编译运行

  1. 打开samples工程,右键composite_map_demo,

    打开属性选项,将Slamware SDK 的include目录和lib目录添加到工程

    将此工程设置成StartUp project

    Image Added


    Image Removed

  2. 右键composite_map_demo,

    将此工程设置成StartUp project

    打开属性选项,将Slamware SDK 的include目录和lib目录添加到工程


    Info

    Slamware SDK的include和lib目录无需复制到参考例程目录,只需在Visual Studio里指定路径即可。


    Image Added

  3. 右键composite_map_demo, 打开properties选项,设置Command Arguments
    Image Removed
    格式说明:
    composite_map_demo  [OPTS]  [filename]  <SDP IP Address>
    SDP IP Address           The ip address string of the SLAMWARE SDP
    getstcm filename          download compositeMap
                                         If not specified, the default name map.stms will be used
    setstcm filename          upload compositeMap
    -h                                  Show this message如下图,
    Image Added


  4. 点击F5运行

    • composite_map_demo getstcm map.stcm 192.168.11.1 (从slamware里面读取composite map, 并生成map.stcm)

      可以用Robostudio的地图编辑器来查看生成的地图:
    • composite_map_demo setstcm map.stcm 192.168.11.1(将名为map.stcm的地图上传至slamware)

      可以在Robostudio中连上机器人,可以看到地图已经上传成功

代码描述

  • 从slamware模块下载composite map到客户端
Code Block
languagecpp
firstline1
title获取composite map
linenumberstrue
bool StcmMapWriter(const std::string file_name, SlamwareCorePlatform platform) {
	CompositeMap composite_map = platform.getCompositeMap();
    CompositeMapWriter composite_map_writer;
    std::string error_message;
    bool result = composite_map_writer.saveFile(error_message, file_name, composite_map);
    return result;
}


  •  从客户端上传composite map至slamware模块
Code Block
languagecpp
firstline1
title设置composite map
linenumberstrue
bool StcmMapReader(const std::string file_path, rpos::core::Pose pose, SlamwareCorePlatform platform) {
    CompositeMapReader composite_map_reader;
    std::string error_message;
    boost::shared_ptr<CompositeMap> composite_map(composite_map_reader.loadFile(error_message, file_path));
    if (composite_map) {
        platform.setCompositeMap((*composite_map), pose);	
        return true;
    }
    return false;
}


  • 从composite map中读取虚拟轨道,虚拟墙等信息
Code Block
languagecpp
firstline1
title读取map layer信息
linenumberstrue
    CompositeMapReader composite_map_reader;
    std::string error_message;
    boost::shared_ptr<CompositeMap> composite_map(composite_map_reader.loadFile(error_message, file_path));
    if (composite_map) {
        for (auto it = composite_map->maps().begin(); it != composite_map->maps().end(); ++it) {
            auto layer = *it;
            std::string usage = layer->getUsage();
			std::string type = layer->getType();
			std::cout << "Layer Usage : " << usage << std::endl;
			//get grid map layer
            if (type == GridMapLayer::Type) {
				auto grid_map = boost::dynamic_pointer_cast<GridMapLayer>(layer);
				std::cout << "Map Position : (" << grid_map->getOrigin().x() << " , " << 
					grid_map->getOrigin().y() << ")" <<std::endl;
				std::cout << "Map Resolution : (" << grid_map->getResolution().x() <<  
					" , " << grid_map->getResolution().y() << ")" <<std::endl;
				std::cout << "Map Dimension: (" << grid_map->getDimension().x() << 
					" , " << grid_map->getDimension().y() << ")" <<std::endl;
				std::cout << "Map Data:" << std::endl;
				for (auto it = grid_map->mapData().begin(); it != grid_map->mapData().end(); ++it) {
					std::cout << (int)*it << " " ;				
				}
				std::cout << std::endl << std::endl;			
            }
			//get line map layer
            else if (type == LineMapLayer::Type) {
                auto line_map = boost::dynamic_pointer_cast<LineMapLayer>(layer);
				for (auto it = line_map->lines().begin(); it != line_map->lines().end(); ++it) {
					auto line = it->second;
					std::cout << "start: (" << line.start.x() << " , " << line.start.y() << ")" << std::endl;
					std::cout << "end: (" << line.end.x() << " , " << line.end.y() << ")" << std::endl;
				}
				std::cout << std::endl;
            }
			//get pose map layer
			else if (type == PoseMapLayer::Type) {
				auto pose_map = boost::dynamic_pointer_cast<PoseMapLayer>(layer);
				for (auto it = pose_map->poses().begin(); it != pose_map->poses().end(); ++it) {					
					auto pos = it->second;
					std::cout << "Position : (" << pos.pose.x() << " , " << pos.pose.y() << ")" << std::endl;
				}	
				std::cout << std::endl;
			}
			else if (type == PointsMapLayer::Type) {                
				//TODO: get Points map layer
				std::cout << std::endl;
            }
			else {
				//TODO: get unknown map layer
				std::cout << std::endl;
            }
        }