Skip to main content

1、概述

本教程旨在帮助您基本了解 AUTEL Mobile SDK(MSDK 3.0)的相关功能以及相关接⼝的使⽤。MSDK 3.0 基于 ROS2 通信架构,适用于 EVO III 系列无人机。

MSDK 包含了与飞机各个模块通信的服务,主要包含通用模块、飞行任务模块、AI 服务模块、相机模块、飞行控制模块、飞行参数模块、云台模块、视觉模块以及图传模块,同时也提供飞机连接状态的监听以及遥控器模块的相关功能。下⾯为 MSDK 讲解如何在开发中使用这些功能。

2、Android Studio 配置⼯程

新建⼀个 Android ⼯程,然后导⼊ AAR 包,将 AAR 包复制到⼯程的 libs ⽬录下

repositories {
flatDir {
dirs 'libs'
}
}

在 build.gradle 中添加以下代码

implementation(name: 'autel-msdk2-release_V3.0.*', ext: 'aar')

权限配置,在 AndroidManifest.xml 文件中添加以下权限

说明:SDK AAR 包自身已在 Manifest 中声明了 ACCESS_COARSE_LOCATION、ACCESS_NETWORK_STATE、ACCESS_WIFI_STATE、ACCESS_FINE_LOCATION 等核心权限,打包时会自动合并。以下列出的是开发者应用需要额外关注的权限。

<!-- 网络通信(SDK 核心通信必须) -->
<uses-permission android:name="android.permission.INTERNET" />

<!-- 存储权限(媒体文件下载/日志保存,Android 10 及以下需要) -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

<!-- 录音权限(如需使用 IM 语音消息功能) -->
<uses-permission android:name="android.permission.RECORD_AUDIO" />

<!-- WiFi 管理(调试工具中 WiFi 配置功能使用) -->
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />

注意事项:

  1. ACCESS_FINE_LOCATION 和 ACCESS_COARSE_LOCATION 已由 SDK 声明,但在 Android 6.0+ 需要运行时动态申请,否则 GPS 定位和 Remote ID 功能无法使用。
  2. WRITE_EXTERNAL_STORAGE 在 Android 11+ 已废弃,如需访问所有文件可使用 MANAGE_EXTERNAL_STORAGE(需用户手动授权)。

3、快速开始

3.1 初始化SDK及参数说明​

MSDK 3.0 使用 SDKInitConfig 配置类进行初始化,主要参数如下:

参数类型说明
debugBoolean是否为 Debug 模式,默认 false
storageIAutelStorage?自定义存储组件,不传默认使用 SharedPreferences
logIAutelLog?自定义日志组件,不传默认使用系统 Log 且 release 无 log
renderModeRenderMode?播放器渲染模式,默认 RenderWithYUV
communicateWithRos2Boolean是否按遥控器固件自动适配通信方式,默认 true。一般保持默认即可;已知仅连接旧版固件遥控器时可设 false 以缩短连接等待
singleBoolean?单机/组网识别,null(默认)为自动识别
bLocalDataModeBoolean是否开启本地数据模式(禁止网络访问),默认 false
val config = SDKInitConfig().apply {
debug = BuildConfig.DEBUG
storage = AppStorage()
log = AppLog()
}
SDKManager.get().init(applicationContext, config)

生命周期:必须在 Application.onCreate 中初始化 SDK,不要在 Activity.onDestroy 里调用 SDKManager.destroy()。Android Activity 重建会先创建新页面再销毁旧页面;此时 destroy 会拆掉新页面正在使用的 ROS/KeyManager,表现为视频还在、连接状态掉线、实时请求 Device disconnected / PROTO_RESPONSE_TIMEOUT,且不会自动恢复。destroy() 仅用于进程退出。

3.2 KeyManager相关方法介绍​

3.2.1 getValue​

一般是用来获取飞机上的某个属性,以获取相机设备信息为例:

val key = KeyTools.createKey(CameraKey.KeyCameraDeviceInfo)

DeviceManager.getDeviceManager().getFirstDroneDevice()?.getKeyManager()?.getValue(key,
object : CommonCallbacks.CompletionCallbackWithParam<DeviceInfoBean> {

override fun onSuccess(t: DeviceInfoBean?) {
}

override fun onFailure(error: IAutelCode, msg: String?) {
}
})

3.2.2 setValue​

一般是给飞机设置某个属性,以设置相机工作模式为例:

val key = KeyTools.createKey(CameraKey.KeyCameraWorkMode)

DeviceManager.getDeviceManager().getFirstDroneDevice()?.getKeyManager()?.setValue(key,

CameraWorkModeEnum.PHOTO,

object : CommonCallbacks.CompletionCallback {

override fun onSuccess() {
}

override fun onFailure(code: IAutelCode, msg: String?) {
}
})

3.2.3 performAction​

一般是执行某个动作或者命令,以开始拍照为例:

val key = KeyTools.createKey(CameraKey.KeyStartTakePhoto)

DeviceManager.getDeviceManager().getFirstDroneDevice()?.getKeyManager()?.performAction(key, null,

object : CommonCallbacks.CompletionCallbackWithParam<Void> {

override fun onSuccess(t: Void?) {
}

override fun onFailure(code: IAutelCode, msg: String?) {
}
})

3.2.4 listen​

一般是用来接收飞机上报的一些信息,以相机专业参数信息上报为例:

val key = KeyTools.createKey(CameraKey.KeyProfessionalParamInfo)

val callback = object : CommonCallbacks.KeyListener<ProfessionalParamInfoBean> {

override fun onValueChange( oldValue: ProfessionalParamInfoBean?, newValue: ProfessionalParamInfoBean) {

}

}

DeviceManager.getDeviceManager().getFirstDroneDevice()?.getKeyManager()?.listen(key, callback)

3.2.5 cancelListen​

取消前面注册的监听,以相机专业参数信息上报为例:

val key = KeyTools.createKey(CameraKey.KeyProfessionalParamInfo)

val callback = object : CommonCallbacks.KeyListener<ProfessionalParamInfoBean> {
override fun onValueChange(oldValue: ProfessionalParamInfoBean?,
newValue: ProfessionalParamInfoBean) {

}
}
DeviceManager.getDeviceManager().getFirstDroneDevice()?.getKeyManager()?.cancelListen(key, callback)

3.3 飞机连接状态和相机能力集监听​

MSDK 3.0 通过 IAutelDroneListener 接口监听无人机连接状态和相机能力集变化。所有回调方法均提供默认空实现,开发者只需覆写需要的方法即可。

interface IAutelDroneListener {

/**
* 主服务是否可用
* @param valid true 可用,false 不可用
* @param drone 无人机设备
*/
fun onMainServiceValid(valid: Boolean, drone: IAutelDroneDevice) {}

/**
* 无人机设备连接状态的监听器
* @param connected 已连接
* @param drone 无人机设备
*/
fun onDroneChangedListener(connected: Boolean, drone: IAutelDroneDevice) {}

/**
* 相机能力集变更通知
* @param localFetched true 本地能力集解析成功
* @param remoteFetched true 远程能力集解析成功
* @param drone 无人机设备
*/
fun onCameraAbilityFetchListener(localFetched: Boolean, remoteFetched: Boolean, drone: IAutelDroneDevice) {}

/**
* 无人机设备创建(组网多机模式下新设备加入时回调)
* @param drone 新创建的无人机设备
*/
fun onDroneCreate(drone: IAutelDroneDevice) {}

/**
* 无人机设备销毁(组网多机模式下设备移除时回调)
* @param drone 被销毁的无人机设备
*/
fun onDroneDestroy(drone: IAutelDroneDevice) {}

/**
* 通信模式切换通知
* @param mode 当前通信模式
*/
fun onModemModeChange(mode: ModemModeEnum) {}
}

3.3.1 注册飞机连接状态和相机能力集的监听​

SDKManager.get().getDeviceManager().addDroneListener(this)

3.3.2 获取当前飞机的连接状态​

val connectStatus = DeviceManager.getDeviceManager().isConnected()

3.4 获取相机能力集相关信息​

val cameraSupport = DeviceManager.getFirstDroneDevice()?.getCameraAbilitySetManger()?.getCameraSupport2()

相机能力集是指当前相机具备哪些能力,通过 ICameraSupport2 接口返回,该接口提供了相机参数范围查询等能力。

interface ICameraSupport2 {

companion object {
const val TAG = "ICameraSupport-"
}

/**
* 返回当前支持的有效视频分辨率和帧率列表
* @param lensType lens type enum
* @param flightMode flight mode enum
* @param modeEnum recording mode enum
* @return video resolution frame data list
*/
fun getResolutionAndFrameRate(
lensType: LensTypeEnum,
flightMode: FightModeEnum?,
modeEnum: RecordModeEnum?
): List<VideoResolutionFrameBean>


/**
* 返回支持HDR对应的相片分辨率列表
* @param lensType lens type enum
* @param flightMode flight mode enum
* @param photoFormat photo output format enum
* @param modeEnum camera mode enum
* @return list of all photo resolution list
*/
fun getHDRSupportPhoto(
lensType: LensTypeEnum,
flightMode: FightModeEnum,
photoFormat: PhotoFormatEnum,
modeEnum: CameraModeEnum
): List<PhotoResolutionEnum>


/**
* 返回当前有效的相机模式(CameraModeEnum).
* @param lensType lens type enum
* @param flightMode flight mode enum and by default manual
* @param modeEnum take photo mode enum and by default unknown
* @return camera mode list
*/
fun getCameraModeRange(
lensType: LensTypeEnum,
flightMode: FightModeEnum,
modeEnum: TakePhotoModeEnum
): ArrayList<CameraModeEnum>

/**
* 返回手动变焦的 min max step的数值范围 "Default": {"Min": 1,"Max": 50,"Step": 1 }
* @param lensType lens type enum
* @return range with min, max and step value
*/
fun getManualFocus(
lensType: LensTypeEnum
): RangeStepIntValue?

/**
* 返回相机变焦的尺寸
* @param lensType lens type enum
* @return range with min, max and step value
*/
fun getPhotoZoom(
lensType: LensTypeEnum,
videoZoomType: VideoZoomTypeEnum
): RangeStepValue?

/**
* 返回视频变焦的尺寸
* @param lensType lens type enum
* @param videoZoomType video zoom type and by default as Default enum
* @return range with min, max and step value
*/
fun getVideoZoom(
lensType: LensTypeEnum,
videoZoomType: VideoZoomTypeEnum
): RangeStepValue?

/**
* 返回水印和时间戳的取值列表
* @param lensType lens type enum
* @param photoFormat photo output format enum
* @return time stamp in integer value
*/
fun getWatermarkTimestamp(
lensType: LensTypeEnum,
photoFormat: PhotoFormatEnum
): Int

/**
* 返回当前有效的相机曝光模式(ExposureModeEnum).
* @param lensType lens type enum
* @return Exposure modes in list
*/
fun getExposureModeRange(
lensType: LensTypeEnum
): ArrayList<ExposureModeEnum>

/**
* 返回当前有效的曝光补偿范围(ExposureExposureCompensationEnum).
* @param lensType lens type enum
* @return exposure compensations in list
*/
fun getExposureCompensationRange(
lensType: LensTypeEnum
): ArrayList<ExposureExposureCompensationEnum>

/**
* 返回当前有效的相机ISO范围 (ImageISOEnum).
* @param lensType lens type enum
* @param isPhoto photo or not defined with boolean
* @param pattern camera pattern enum and by default Manual flight
* @param modeEnum Take photo mode enum by default Unknown
* @return image ISO enums list
*/
fun getImageISOList(
lensType: LensTypeEnum,
isPhoto: Boolean,
pattern: Int = PatternModeEnum.MANUAL.value,
modeEnum: TakePhotoModeEnum
): ArrayList<ImageISOEnum>


/**
* 返回当前有效的相机ISO模式列表 (ISOModeEnum).
* @param lensType lens type enum
* @return image ISO enums list
*/
fun getPhotoISOModeRange(
lensType: LensTypeEnum
): List<ISOModeEnum>

/**
* 返回当前有效的相机ISO模式列表 (ISOModeEnum).
* @param lensType lens type enum
* @return ISOModeEnum list
*/
fun getVideoISOModeRange(
lensType: LensTypeEnum
): List<ISOModeEnum>

/**
* 返回当前有效的相机快门速度范围
* @param lensType lens type enum
* @param isPhoto photo or not
* @param modeEnum take photo mode enum and by default unknown
* @return ShutterSpeedEnums list
*/
fun getShutterList(
lensType: LensTypeEnum,
isPhoto: Boolean,
fps: Int,
modeEnum: TakePhotoModeEnum
): ArrayList<ShutterSpeedData>


/**
* 返回当前相机光圈可设置的范围
* @param lensType lens type enum
* @return Lris enum list
*/
fun getApertureRange(
lensType: LensTypeEnum
): List<Double>

/**
* 返回当前相机视频格式可选择的范围
* @param lensType lens type enum
* @return video format enum list
*/
fun getVideoFileFormatRange(
lensType: LensTypeEnum
): List<VideoFormatEnum>

/**
* 返回当前相机录像时拍照间隔的可选择的范围
* @param lensType lens type enum
* @return video piv enum list
*/
fun getPicInVideoIntervalRange(
lensType: LensTypeEnum
): List<VideoPivEnum>

/**
* 返回当前相机视频标准可选择的范围
* @param lensType lens type enum
* @return video standard
*/
fun getVideoStandardRange(
lensType: LensTypeEnum
): List<VideoStandardEnum>

/**
* 返回当前相机拍照图片格式可选择范围.
* @param lensType lens type enum
* @param modeEnum take photo mode state
* @return photo formatted enum list
*/
fun getPhotoFileFormatRange(
lensType: LensTypeEnum,
modeEnum: TakePhotoModeEnum,
photoResolution: PhotoResolutionEnum
): List<PhotoFormatEnum>

/**
* 返回当前相机快拍张数可选择范围
* @param lensType lens type enum
* @return count list send
*/
fun getPhotoBurstCountRange(
lensType: LensTypeEnum
): List<Int>

/**
* 返回当前相机AEB拍摄张数可选择范围.
* @param lensType lens type enum
* @return photo count list send
*/
fun getPhotoAEBCaptureCountRange(
lensType: LensTypeEnum
): List<Int>

/**
* 返回当前相机定时拍摄时间可选择范围.
* @param lensType lens type enum
* @return lens type list
*/
fun getPhotoIntervalParamRange(
lensType: LensTypeEnum
): List<Int>


/**
* 返回当前相机白平衡可选择范围.
* @param lensType lens type enum
* @return white balances enum list
*/
fun getWhiteBalanceList(
lensType: LensTypeEnum
): ArrayList<WhiteBalanceEnum>


/**
* 返回当前相机白平衡自定义色温值范围.
* @param lensType lens type enum
* @return range step int value
*/
fun getCustomColorTemperatureRange(
lensType: LensTypeEnum
): RangeStepIntValue?


/**
* 返回当前相机透雾模式范围.
* @param lensType lens type enum
* @return defog mode enum list
*/
fun getDehazeModeRange(
lensType: LensTypeEnum
): List<DefogModeEnum>


/**
* 返回当前相机透雾使能状态可选择范围.
* @param lensType lens type enum
* @return defog mode enum list
*/
fun getDehazeSettingSwitchRange(
lensType: LensTypeEnum
): List<DefogEnum>

/**
* 返回当前相机透雾使能状态可选择范围.
* @param lensType lens type enum
* @return defog mode enum list
*/
fun getDehazeSettingSwitchMergeRange(
lensType: LensTypeEnum
): List<DefogEnum>

/**
* 返回当前相机抗闪烁模式可选择范围.
* @param lensType lens type enum
* @return anti flicker range list
*/
fun getAntiFlickerRange(
lensType: LensTypeEnum
): List<Int>

/**
* transferMode 是图传的清晰度: 1 是流畅 720p, 2是高清 1080p, 3是超高清 2.7K
* @param lensType lens type enum
* @return video transmission mode enum list
*/
fun getTransferMode(
lensType: LensTypeEnum
): List<VideoTransMissionModeEnum>

/**
* 返回当前相机图像分辨率可选择范围.
* @param lensType lens type enum
* @param flightMode flight mode enum
* @param modeEnum take photo mode enum and by default unknown
* @return photo resolution enum list
*/
fun getPhotoResolution(
lensType: LensTypeEnum,
flightMode: FightModeEnum,
modeEnum: TakePhotoModeEnum
): List<PhotoResolutionEnum>


/**
* 返回当前相机图像分辨率可选择范围.无对应枚举 返回UNKNOWN后 重新获取相册分辨率列表
* @param lensType lens type enum
* @param flightMode flight mode enum
* @param modeEnum take photo mode enum and by default unknown
* @return photo resolution list
*/
fun getPhotoResolutionTwice(
lensType: LensTypeEnum ,
flightMode: FightModeEnum,
modeEnum: TakePhotoModeEnum
): List<PhotoResolution>


/**
* 回当前相机锐度可选择范围.
* @param lensType lens type enum
* @param modeEnum take photo mode enum and by default unknown
* @return list of integer
*/
fun getSharpnessRange(
lensType: LensTypeEnum,
modeEnum: TakePhotoModeEnum
): List<Int>

/**
* 返回当前相机对比度可选择范围.
* @param lensType lens type enum
* @param modeEnum take photo mode enum and by default unknown
* @return list of integer
*/
fun getContrastRange(
lensType: LensTypeEnum,
modeEnum: TakePhotoModeEnum
): List<Int>

/**
* 返回当前相机饱和度可选择范围.
* @param lensType lens type enum
* @param modeEnum take photo mode enum and by default unknown
* @return list of integer
*/
fun getSaturationRange(
lensType: LensTypeEnum,
modeEnum: TakePhotoModeEnum
): List<Int>

/**
* 返回当前相机对焦模式可选择范围.
* @param lensType lens type enum
* @param modeEnum take photo mode enum and by default unknown
* @return list of integer
*/
fun getLensFocusModeRange(
lensType: LensTypeEnum ,
modeEnum: CameraModeEnum
): List<Int>

/**
* 返回当前相机支持的热成像伪彩信息.
* @param lensType lens type enum
* @return thermal color enum list
*/
fun supportedIrColor(
lensType: LensTypeEnum
): List<ThermalColorEnum>


/**
* 返回热成像图测温模式.
* @param lensType lens type enum
* @return IR temp mode enum
*/
fun getThermalIRTempMode(
lensType: LensTypeEnum
): List<IRTempModeEnum>

/**
* 返回热成像图像模式.
* @param lensType lens type enum
* @return Ir image mode object
*/
fun getThermalIrImageMode(
lensType: LensTypeEnum
): IrImageMode?


/**
* 返回热成像图像增强.
* @param lensType lens type enum
* @return range step int value object
*/
fun getThermalIrImageEnhance(
lensType: LensTypeEnum
): RangeStepIntValue?


/**
* 返回热成像图像去噪.
* @param lensType lens type enum
* @return list of integer
*/
fun getThermalIrNr(
lensType: LensTypeEnum
): MutableList<Int>

/**
* 返回热成像图像去噪.
* @param lensType lens type enum
* @return Ir gain object
*/
fun getIrGain(
lensType: LensTypeEnum
): IrGain?


/**
* 返回热成像等温线.
* @param lensType lens type enum
* @return list of integer
*/
fun getIrIsoThermMode(
lensType: LensTypeEnum
): List<Int>


/**
* 返回热成像温度告警.
* @param lensType lens type enum
* @return IR hot cold value
*/
fun getIrTempAlarm(
lensType: LensTypeEnum
): IRHotColdValue?

/**
* 是否支持红外温宽拉伸
* @param lensType lens type enum
* @return support temp. span weather or not
*/
fun isIrTempSpanEnable(
lensType: LensTypeEnum
): Boolean

/**
* 返回红外温宽拉伸范围
* @param lensType lens type enum
* @return IR temp high low range value
*/
fun getIrTempSpanRange(
lensType: LensTypeEnum
): IRTempSpanValue?

/**
* 返回热成像辐射.
* @param lensType lens type enum
* @return range step int value object
*/
fun getIrNrEmit(
lensType: LensTypeEnum
): RangeStepIntValue?

/**
* 返回当前相机支持的视频文件压缩标准.
* @param lensType lens type enum
* @return video compress standard enum
*/
fun getVideoFileCompressionStandard(
lensType: LensTypeEnum
): List<VideoCompressStandardEnum>

/**
* 返回当前相机支持的存储类型.
* @param lensType lens type enum
* @return storage type enums list
*/
fun getStorageType(
lensType: LensTypeEnum
): List<StorageTypeEnum>

/**
* @return 镜头是否支持AI
*/
fun getAiServiceEnabled(
lensType: LensTypeEnum
): Boolean

/**
* @param lensType lens type enum
* @return 可切换的Ircut范围列表.
*/
fun getIrcutSwitchRange(
lensType: LensTypeEnum
): List<IrcutSwitchEnum>?


/**
* @return 当前云台是否支持热熔和
*/
fun isSupportFusion(): Boolean

/**
* getting version of camera
*/
fun getVersion(): String

/**
* 相机HFov
*/
fun getHFov(lensType: LensTypeEnum):Float?
/**
* 相机VFov
*/
fun getVFov(lensType: LensTypeEnum):Float?

/**
* 相机FocalLength
*/
fun getFocalLength(lensType: LensTypeEnum):Float?

/**
* 相机 AFAE 锁是否支持
*/
fun isAFAELockSupport(lensType: LensTypeEnum): Boolean

/**
* 相机拍照时间
*/
fun getTakePhotoCostTime(): Int

/**
* 当前镜头是否支持专业参数设置
*/
fun isPROSettingsSupport(lensType: LensTypeEnum): Boolean

/**
* 激光灯模式
*/
fun getLaserLightMode(): LaserLightModeEnum

/**
* 镜头是否支持加热除雾功能
* @param lensType 如果为 null 则查询整体是否支持,一般与长焦挂钩
*/
fun isLensDehazeSupport(lensType: LensTypeEnum?): Boolean

/**
* 镜头加热除雾最大时长(秒)
*/
fun getLensDehazeMaxTime(lensType: LensTypeEnum?): Int

/**
* 是否支持红外超分辨率
*/
fun isIRSuperSolutionSupport(lensType: LensTypeEnum? = null): Boolean

/**
* 是否支持数字变焦
*/
fun isDigitalZoomSupport(lensType: LensTypeEnum): Boolean

/**
* 当前镜头是否支持选择镜头拍照、录像
*/
fun isLensStorageSupport(lensType: LensTypeEnum): Boolean

/**
* 是否支持机械快门
*/
fun isMechanicalShutterSupport(lensType: LensTypeEnum): Boolean

}

3.5 飞机状态信息缓存​

val stateData = DeviceManager.getFirstDroneDevice()?.getTestData()

飞机状态信息缓存主要用来保存飞机的一些重要信息,这些信息会不断刷新,主要保存在 DroneStateData 中。开发者可通过 getTestData() 获取当前缓存的飞机状态数据。

data class DroneStateData(
/** 云台数据(按云台类型分组)*/
var gimbalDataMap: MutableMap<GimbalTypeEnum, GimbalData> = mutableMapOf(),
/** 视觉避障信息缓存 */
var visionObsacleData: VisionObstacleData = VisionObstacleData(),
/** SDCard 缓存 */
var sdcardData: SDCardData = SDCardData(),
/** MMC 机载闪存缓存 */
var emmcData: EmmcData = EmmcData(),
/** 龙鱼相关参数缓存 */
var dragonFishData: DragonFishData = DragonFishData()
) {
/** 获取对应云台类型的 GimbalData */
fun getGimbalData(gimbalType: GimbalTypeEnum): GimbalData?

/** 获取对应云台类型的 CameraData */
fun getCameraData(gimbalType: GimbalTypeEnum): CameraData?

/** 获取对应云台类型和镜头类型的镜头相关参数 */
fun getLensCameraData(gimbalType: GimbalTypeEnum, lensTypeEnum: LensTypeEnum): CameraBaseData?
}

注意: MSDK 3.0 中 DroneStateData 已简化,部分旧版字段(如 flightControlData、rtkControlData、droneWarningData 等)已移除或迁移至其他管理器。建议开发者通过对应模块的 Key 监听机制获取实时数据。

3.6 AutelKeyInfo和AutelActionKeyInfo介绍​

3.6.1 AutelKeyInfo​

包含了单个接口属性和能力,下面以图像曝光(Double)Key 为例:

参数说明:component.value 指该 Key 所属模块(相机、飞控、云台等);

CameraKeyConstants.ImageExposure 指 Key 的唯一标识字段;

AutelDoubleConvert 为 protobuf 与业务类型之间的转换类,对应数据类型 Double;

canGet(true).canSet(true) 表示 Key 具备的能力:canGet/canSet/canPerformAction/canListen 分别对应 KeyManager 的 getValue、setValue、performAction、监听。

/** 图像曝光参数(需区分镜头) */
val KeyImageExposure: AutelKeyInfo<Double> = AutelKeyInfo(
component.value,
CameraKeyConstants.ImageExposure,
AutelDoubleConvert()
).canGet(true).canSet(true)

3.6.2 AutelActionKeyInfo​

AutelActionKeyInfo是AutelKeyInfo的子类,包含了AutelKeyInfo的能力,不同之处是这个类有两个泛型,分别表示请求参数类型和响应数据类型,以开始录像为例:

/** 开始录像 */
val KeyStartRecord: AutelActionKeyInfo<Void, Void> = AutelActionKeyInfo(component.value, CameraKeyConstants.StartRecord,

AutelEmptyConvert(), AutelEmptyConvert()).canPerformAction(true).canRetry(true)

3.7 飞机各个模块的 Key 概览​

MSDK 3.0 将飞机功能按模块划分为多个 Key 类,每个 Key 类包含该模块的所有可操作属性和命令。以下是外部 SDK 中可用的全部 Key 模块:

模块Key 类说明调试工具可见
相机CameraKey拍照、录像、变焦、红外温度、水印、存储等✅
云台GimbalKey云台角度控制、校准、工作模式✅
图传链路AirLinkKey频段切换、对频、信号强度✅
AI 服务AIServiceKeyAI 模型管理、外部模型接入✅
飞行控制FlightControlKey起飞、降落、返航、Home 点设置✅
飞行任务FlightMissionKey航点任务、兴趣点飞行、速度控制✅
飞行参数FlightPropertyKey限高限远、档位、灵敏度、传感器校准✅
通用CommonKey状态上报、校准、LED 灯、告警、设备信息✅
视觉/避障VisionKey避障动作、MIF 视觉开关✅
遥控器RemoteControllerKey遥控器状态、按键、GPS、校准✅
AI 跟踪AITrackingKey智能跟踪、目标锁定✅
远程识别RemoteIDKey无人机 ID、操作员 ID(合规)✅
任务管理MissionManagerKey电子围栏、降落模式、工作场景✅
雷达RadarPropertyKey雷达检测、标定✅
RTKRtkPropertKeyRTK 定位开关、GPGGA 数据✅
NTRIPNtripAccountKeyNTRIP RTK 差分服务配置✅
LTELteModuleKey4G LTE 模块配置✅
负载PayloadKeyTracer、投掷器、喊话器、补光灯✅
数据安全HardwareDataSecurityKey日志清除、数据清除✅

每个 Key 类的完整 Key 列表、数据类型定义、操作能力和组播支持情况,请参考 KeyValue 使用教程。各模块 Key 的使用方式与 3.2 节介绍的 getValue/setValue/performAction/listen 方法一致。

3.8 遥控器相关功能介绍​

遥控器相关命令发送,和飞机一样都是通过 KeyManager 发送命令,只是获取 KeyManager 的方式不同,以查询遥控器设备信息为例:

val remoteKeyManager =
DeviceManager.getFirstRemoterDevice()?.getKeyManager()

remoteKeyManager?.performAction(
KeyTools.createKey(RemoteControllerKey.KeyRcDeviceInfo),
null,
object : CommonCallbacks.CompletionCallbackWithParam<List<DroneVersionItemBean>> {
override fun onSuccess(t: List<DroneVersionItemBean>?) {
}

override fun onFailure(error: IAutelCode, msg: String?) {
}
}
)

3.9 注意事项​

  1. Key 的能力判断:performAction、setValue、getValue 不能直接通过事件名称来判断,需要根据对应模块的 Key 来判断。例如只有 canGet(true) 的时候,才可以调用 getValue 方法;只有 canPerformAction(true) 的时候,才可以调用 performAction 方法。

  2. ROS2 Key:MSDK 3.0 推荐使用 ros2Supported = true 的 Key(调试工具默认展示这些 Key)。从 2.5 迁移且仍引用旧 Key 字段时,SDK 会自动兼容,一般无需改代码(见迁移指南 §5)。

  3. 设备获取:通过 DeviceManager.getFirstDroneDevice() 获取无人机设备前,请确保设备已连接。可通过 IAutelDroneListener.onDroneChangedListener 监听连接状态变化。

  4. 线程安全:Key 的回调默认在子线程执行,如需更新 UI,请切换到主线程。