Versions Compared

Key

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

本页介绍了artifacts_demo的用法, 包含虚拟墙/虚拟轨道的删除,添加与移动功能。



本页内容

Table of Contents


运行环境准备

  • 软件平台

    • 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 SDPSlamware 套装 (基于Slamware导航方案的用户机器人系统)
      • ZeusApollo/Ares/Apollo等底盘系统Athena等底盘系统


例程下载

Win32-例程下载



编译运行

  1. 打开samples工程,右键artifacts_demo, 将此工程设置成StartUp project


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

    Info

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


    Image AddedImage Removed

  3. 右键artifacts_demo, 在Debugging页面中command Arguments处输入 192.168.11.1
    格式说明:artifacts_demo <IP address> 


  4. 点击F5运行
  5. 此时RoboStudio的显示过程为
    Multimedia
    date// 虚拟轨道的删除、添加与移动
    namebandicam 2017-12-13 18-21-31-346.mp4


  6. Console输出为
    Image RemovedImage Added

  7. 选择console中输出的虚拟轨道ID来删除一条轨道,视频中输入ID为3


代码描述

  • 删除所有虚拟墙/虚拟轨道
Code Block
languagecpp
firstline1
title删除所有虚拟轨道/虚拟墙
linenumberstrue
		SlamwareCorePlatform sdp = SlamwareCorePlatform::connect(argv[1], 1445);
        std::cout << "Clearing existing tracks and walls..." << std::endl;
		sdp.clearLines(ArtifactUsageVirtualTrack);
		sdp.clearLines(ArtifactUsageVirtualWall);
  • 添加虚拟墙
Code Block
languagecpp
firstline1
title添加虚拟墙
linenumberstrue
		std::cout << "Adding virtual walls..." << std::endl;
		std::vector<Line> walls;
		//add a 8 * 8 virtual wall square
		walls.push_back(Line(Point(-4, -4), Point(-4, 4)));
		walls.push_back(Line(Point(-4, 4), Point(4, 4)));
	    walls.push_back(Line(Point(4, 4), Point(4, -4)));
		walls.push_back(Line(Point(4, -4), Point(-4, -4)));	
		sdp.addLines(ArtifactUsageVirtualWall, walls);	
  • 添加虚拟轨道
Code Block
languagecpp
firstline1
title添加虚拟轨道
linenumberstrue
		std::cout << "Adding virtual tracks..." << std::endl;
		std::vector<Line> tracks;
		//add a 2 * 2 virtual track square
		tracks.push_back(Line(Point(-1, -1), Point(-1, 1)));
		tracks.push_back(Line(Point(-1, 1), Point(1, 1)));
		tracks.push_back(Line(Point(1, 1), Point(1, -1)));
		tracks.push_back(Line(Point(1, -1), Point(-1, -1)));	
		sdp.addLines(ArtifactUsageVirtualTrack, tracks);
  • 移动虚拟墙(移动虚拟轨道用法类似)
Code Block
languagecpp
firstline1
title移动虚拟墙
linenumberstrue
		std::cout << "Moving vitual walls..." << std::endl;
		//sleep 5 seconds for displaying purpose only, not necessary
		boost::this_thread::sleep_for(boost::chrono::milliseconds(5000)); 
		std::vector<Line> get_walls = sdp.getLines(ArtifactUsageVirtualWall);
		//shrink virtual wall square from 8 * 8 to 6 *6
		for (std::vector<Line>::iterator it = get_walls.begin() ; it != get_walls.end(); ++it) {	
            it->startP().x() *= 0.75f; 
            it->startP().y() *= 0.75f;
		}
		sdp.moveLines(ArtifactUsageVirtualWall, get_walls);
  • 删除指定虚拟轨道(删除指定虚拟墙用法类似)
Code Block
languagecpp
firstline1
title删除指定虚拟轨道
linenumberstrue
		std::cout << "Get all tracks..." << std::endl;
		std::vector<Line> get_tracks = sdp.getLines(ArtifactUsageVirtualTrack);
		for (std::vector<Line>::iterator it = get_tracks.begin() ; it != get_tracks.end(); ++it) {
			std::cout << "ID: " << it->id() << std::endl;
			std::cout << "Start from (" << it->startP().x() << " , " << it->startP().y() << ") " << "to (" 
				      << it->endP().x() << " , " << it->endP().y() << " ) " << std::endl;		
		}

		std::cout << "Delete track by ID, please enter track ID:" << std::endl;
		int id;
	    bool is_found = false;
		std::cin >> id ;
		for (std::vector<Line>::iterator it = get_tracks.begin() ; it != get_tracks.end(); ++it) {
			if (id == it->id()) {
				sdp.removeLineById(ArtifactUsageVirtualTrack, id);
				is_found = true;
				break;
			}
		}
		if(!is_found)
			std::cout << "Wrong ID" << std::endl;