You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 7 Next »

本页介绍了 GetPowerStatus 的用法, 包含底盘当前的充电状态、电池电量、回坞状态等信息。


本页内容


运行环境准备

  • 软件平台

    • Android Studio 3.1.3
    • Slamware Android SDK: slamware_sdk_android.2.6.0_rtm.20180820.tar.gz
    • RoboStudio(用于显示地图):Robostudio installer
    • Sample Code: 

      使用不同版本的Android Studio可能会带来编译异常,请自行下载相关库和修改build.gradle配置文件,本例程基于Slamware Android SDK 2.6.0 进行开发,若想尝试更高的SDK版本,请直接替换工程中的 slamware_sdk_android.jar 和 librpsdk.so 文件。

  • 硬件平台

          (以下任选其一)

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

编译运行

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


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


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




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


  4. 点击F5运行
  5. Console输出为


代码描述

  • 获取电量/充电状态

    获取电量/充电状态
    /* 与底盘连接 */
    AbstractSlamwarePlatform robotPlatform = DeviceManager.connect("10.0.130.71", 1445);
    
    /* 获取版本信息 */
    sdkVersion.setText(robotPlatform.getSDKVersion());
    
    try {
        /* 获取Slamware ID */
        deviceID.setText(robotPlatform.getDeviceId());
    
        /* 获取电源状态相关信息 */
        PowerStatus powerStatus = robotPlatform.getPowerStatus();
    
        /* 是否正在充电 */
        if(powerStatus.isCharging() == true) {
            chargingStatus.setText("正在充电");
        } else {
            chargingStatus.setText("未在充电");
        }
    
        /* 是否DC connected */
        if(powerStatus.isDCConnected() == true) {
            dcConnected.setText("已连接");
        } else {
            dcConnected.setText("未连接");
        }
    
        /* 剩余电池电量 */
        batteryPercentage.setText(powerStatus.getBatteryPercentage() + "%");
    
        /* 是否回到充电桩 */
        if(powerStatus.getDockingStatus() == DockingStatus.OnDock) {
            dockStatus.setText("已回桩");
        } else if (powerStatus.getDockingStatus() == DockingStatus.NotOnDock) {
            dockStatus.setText("未回桩");
        } else {
            dockStatus.setText("未知状态");
        }
    
        /* 睡眠状态 */
        switch (powerStatus.getSleepMode()) {
            case Awake:
                sleepMode.setText("Awake");
                break;
            case WakingUp:
                sleepMode.setText("WakingUp");
                break;
            case Asleep:
                sleepMode.setText("Asleep");
                break;
            case Unknown:
                sleepMode.setText("Unknown");
                break;
                default:
                    break;
        }
    
    
  • No labels