...
- 此sample为 windows console application, 需要在console中用命令行执行,用法为:artifacts_demo <IP address> (注: 此IP地址为slamware模块的IP地址)
或者在属性页面设置Command Arguments 代码功能说明: 删除所有虚拟墙/虚拟轨道、添加虚拟墙、添加虚拟轨道、移动虚拟墙(移动虚拟轨道用法类似)、删除指定虚拟轨道(删除指定虚拟墙用法类似)
Code Block language cpp firstline 1 title 删除所有虚拟轨道/虚拟墙 linenumbers true SlamwareCorePlatform sdp = SlamwareCorePlatform::connect(argv[1], 1445); std::cout << "Clearing existing tracks and walls..." << std::endl; sdp.clearLines(ArtifactUsageVirtualTrack); sdp.clearLines(ArtifactUsageVirtualWall);
Code Block language cpp firstline 1 title 添加虚拟墙 linenumbers true 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 language cpp firstline 1 title 添加虚拟轨道 linenumbers true 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 language cpp firstline 1 title 移动虚拟墙 linenumbers true 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() = it->startP().x() > 0 ? --(it->startP().x()) : ++(it->startP().x()); it->startP().y() = it->startP().y() > 0 ? --(it->startP().y()) : ++(it->startP().y()); it->endP().x() = it->endP().x() > 0 ? --(it->endP().x()) : ++(it->endP().x()); it->endP().y() = it->endP().y() > 0 ? --(it->endP().y()) : ++(it->endP().y()); } sdp.moveLines(ArtifactUsageVirtualWall, get_walls);
Code Block language cpp firstline 1 title 删除指定虚拟轨道 linenumbers true 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;
3. 使用RoboStudio来帮助显示虚拟墙/虚拟轨道(红色为虚拟墙,绿色为虚拟轨道)