本页介绍了Speed regulation的用法, 如何调用setsystemparameter()接口调节机器人速度。


本页内容


运行环境准备

  • 软件平台

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

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

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

  • 硬件平台

          (以下任选其一)

      • Slamware SDP mini 
      • Slamware 套装 (基于Slamware导航方案的用户机器人系统)
      • Apollo/Ares/Athena等底盘系统

例程下载

Win32-例程下载


编译运行

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


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

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



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


  4. 点击F5运行
  5. 可以连上Robostudio查看地图及机器人的运动


代码描述

  • 机器人会以低中高三档以及一个自定义的速度,在正方形四条边循环运动,高中低三档速度的具体值取决于固件。

    调节速度
     		SlamwareCorePlatform sdp = SlamwareCorePlatform::connect(ip_address, 1445);
    		std::cout <<"SDK Version: " << sdp.getSDKVersion() << std::endl;
    		std::cout <<"SDP Version: " << sdp.getSDPVersion() << std::endl;
    		rpos::actions::MoveAction action = sdp.getCurrentAction();
    		
    		rpos::core::Location location1(1,0);
    		rpos::core::Location location2(-1,0);
    		rpos::core::Location location3(-1,2);
                    rpos::core::Location location4(1,2);
    		while (true)
    		{
    			if (action)
    				action.cancel();
    
    			action = sdp.moveTo(location1, false,true);
    			if (action.getStatus() == rpos::core::ActionStatusError)
    				std::cout << "Action Failed: " << action.getReason() << std::endl;
    			bool bRet2 =sdp.setSystemParameter(SYSPARAM_ROBOT_SPEED, SYSVAL_ROBOT_SPEED_HIGH);
    			std::cout <<"Robot is moving to: (" << location1.x() <<" , "<<location1.y()<<") on speed"<< " HIGH" << std::endl;
    			action.waitUntilDone();
    		
    		
    			action = sdp.moveTo(location2, false,true);
    			if (action.getStatus() == rpos::core::ActionStatusError)
    				std::cout << "Action Failed: " << action.getReason() << std::endl;
    			bool bRet3 =sdp.setSystemParameter(SYSPARAM_ROBOT_SPEED, SYSVAL_ROBOT_SPEED_LOW);
    			std::cout <<"Robot is moving to: (" << location2.x() <<" , "<<location2.y()<<") on speed"<< " LOW" << std::endl;
    			action.waitUntilDone();
    		
    		
    			action = sdp.moveTo(location3, false,true);
    			if (action.getStatus() == rpos::core::ActionStatusError)
    				std::cout << "Action Failed: " << action.getReason() << std::endl;
    			bool bRet1 =sdp.setSystemParameter(SYSPARAM_ROBOT_SPEED, SYSVAL_ROBOT_SPEED_MEDIUM);
    			std::cout <<"Robot is moving to: (" << location3.x() <<" , "<<location3.y()<<") on speed"<< " MEDIUM" << std::endl;
    			action.waitUntilDone();
    
    
    			action = sdp.moveTo(location4, false,true);
    			if (action.getStatus() == rpos::core::ActionStatusError) 
    				std::cout << "Action Failed: " << action.getReason() << std::endl; 
    			bool bRet1 =sdp.setSystemParameter(SYSPARAM_ROBOT_SPEED, "0.3m/s"); 
    			std::cout <<"Robot is moving to: (" << location4.x() <<" , "<<location4.y()<<") on speed"<< " 0.3m/s" << std::endl; action.waitUntilDone();
    		 }