Versions Compared

Key

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

本页介绍了get_sensor_value的用法, 包含当前所有传感器的类型,安装位置,触发状态等。



本页内容

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 套装 (基于Slamware导航方案的用户机器人系统)

...

      • Apollo/Ares/Athena等底盘系统


例程下载

Win32-例程下载


编译运行

...

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

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

    Info

...

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


    Image Added

  2. 右键get_sensor_value,

...

  1. 在Debugging页面中command Arguments处输入 192.168.11.1 
    格式说明:get_sensor_value <IP address> 
    Image Modified

  2. 点击F5运行
  3. Console输出为(

...

  1. 下图中,

...

  1. sensor id为 1的bumper是触发状态,值为0)

...

  1. Image Added


代码描述

  • 代码功能说明: 获取传感器数据

    Code Block
    languagecpp
    firstline1
    title获取传感器数据
    linenumberstrue

...

  • SlamwareCorePlatform sdp = SlamwareCorePlatform::connect(

...

  • ip_address, 1445);
    

...

  • std::cout <<"SDK Version: " << sdp.getSDKVersion() << std::endl;
    

...

  • std::cout <<"SDP Version: " << sdp.getSDPVersion() << std::endl;
    

...

  • std::vector<ImpactSensorInfo> sensors;
    

...

  • bool result = sdp.getSensors(sensors);
    
    

...

  • if (result)

...

  • 
    {
    

...

  •     for (std::vector<ImpactSensorInfo>::iterator it = sensors.begin();

...

  • it != sensors.end(); ++it)
        {
    

...

  •         std::cout << "Sensor id : " << it->id << std::endl;
    

...

  •         if (it-

...

  • >coreSensorType == 

...

  • SensorTypeBumper)
            std::cout << "Sensor 

...

  • coreSensorType: Bumper" << std::endl;
    

...

  •         else if (it-

...

  • >coreSensorType == 

...

  • SensorTypeCliff)
    

...

  •         std::cout << "Sensor 

...

  • coreSensorType: Cliff" << std::endl;
    

...

  •         else if (it-

...

  • >coreSensorType == 

...

  • SensorTypeSonar)
    

...

  •         std::cout << "Sensor 

...

  • coreSensorType: Sonar" << std::endl;

...

  • 
            else if (it->coreSensorType == SensorTypeMagTapeDetector)
            std::cout << "Sensor coreSensorType: MagTapeDetector" << std::endl;
            else
            return 1;
     
            if (it->type == ImpactSensorTypeAnalog)
    

...

  •         std::cout << "Sensor Type: Analog" << std::endl;
    

...

  •         else if (it->type == ImpactSensorTypeDigital)
    

...

  •         std::cout << "Sensor Type: Digital" << std::endl;

...

  • 
            else
            return 1;
    

...

  • 
            std::cout << "Sensor Position: ( " <<  it->pose.x() << " , " << it->pose.y() << " , " << 

...

  • it->pose.z() << " ) ;  Yaw = " << it->pose.yaw() << std::endl;
    

...

  •         
            ImpactSensorValue value;
    

...

  •         sdp.getSensorValue(it->id, value);
    

...

  •         std::cout << "Sensor Value : " << value.value<< std::endl;
         

...

  •    std::cout<<std::endl;
        }
    }