1.说明
根据大疆开放的api,集成一个rtk定位的功能到我们的软件,两种方式
1.1有一个移动站,基站,让app去连接移动基站,获取gps定位信息
1.2用千寻的网络账号,自定义网络,来获取gps信息
2.效果图:我把项目代码单独抽了rtk功能的代码,运行,测试的效果图,可以拿到gps数据,但是对频有点问题,没有解决
3.下载地址:https://github.com/wrs13634194612/DJIRTK
4.代码
1.打开rtk模块
mRtk.setRtkEnabled(isChecked, new CommonCallbacks.CompletionCallback() {@Overridepublic void onResult(DJIError djiError) {}});
2.获取rtk模块的状态,打开或关闭
mRtk.getRtkEnabled(new CommonCallbacks.CompletionCallbackWith<Boolean>() {@Overridepublic void onSuccess(Boolean aBoolean) {//这个东西用来判断是否成功开启RTK//String description2 = "AZ=启用RTK模块: " + aBoolean;// NettyClient.getInstance().sendMsgToServer(description2);getActivity().runOnUiThread(new Runnable() {@Overridepublic void run() {tv_rtk_status.setText(String.valueOf(aBoolean)); //??这玩意能不能记住我的状态呢}});}
3.设置信号源,移动站或者自定义网络
主要有这几种:根据需求 自行选择
NONE | Not using any reference station source. |
BASE_STATION | RTK is using the D-RTK 2 base station as the reference station. |
CUSTOM_NETWORK_SERVICE | RTK is using third-party network service as the reference station. The network service should use NTRIP(Networked Transport of RTCM via Internet Protocol). |
NETWORK_RTK | Default virtual reference station solution to provide cm level accurate position. The frame can be either WGS84 or CGCS 2000. Please note that this default solution can only be used in China. Please add the "djinetworkrtkhelper" to the project via gradle: implementation 'com.dji:library-networkrtk-helper:1.0' It is only supported by Phantom 4 RTK. |
UNKNOWN | Unknown reference station source. |
//设置信号源 移动站mRtk.setReferenceStationSource(ReferenceStationSource.BASE_STATION, new CommonCallbacks.CompletionCallback() {@Overridepublic void onResult(DJIError djiError) {}});
4.查看一下当前的信号源是什么
mRtk.addReferenceStationSourceCallback(new ReferenceStationSource.Callback() {@Overridepublic void onReferenceStationSourceUpdate(ReferenceStationSource referenceStationSource) {// String description3 = "AC=设置RTK信号源-移动站rtk: " + referenceStationSource.toString();// NettyClient.getInstance().sendMsgToServer(description3); tv_rtk_sourcegetActivity().runOnUiThread(new Runnable() {@Overridepublic void run() {tv_rtk_source.setText(String.valueOf(referenceStationSource));}});}});
5.拿飞机gps数据,实时刷新
mRtk.setStateCallback(new RTKState.Callback() {@Overridepublic void onUpdate(RTKState rtkState) {// String description2 = String.valueOf(rtkState.isRTKBeingUsed());changertkstate(rtkState);String description ="A=RTKBeingUsed是否正在使用rtk: " + rtkState.isRTKBeingUsed() + "\n"+ "B=distanceToHomePointDataSource到本站数据源的距离: " + rtkState.getDistanceToHomePointDataSource() + "\n"+ "C=TakeoffAltitudeRecorded,true表示飞机起飞时飞行控制器记录了高度\n: " + rtkState.isTakeoffAltitudeRecorded() + "\n" +"DA=DistanceToHomePointDataSource起始点数据源: " + rtkState.getDistanceToHomePointDataSource() + "\n" +"DA=DistanceToHomePointDataSource起始点数据源Two: " + rtkState.getHomePointDataSource() +"DB=HomePointLocation起始点位置: " + rtkState.getHomePointLocation() + "\n" +"DC=SatelliteCount,GPS或RTK卫星计数: " + rtkState.getSatelliteCount() + "\n"+ "E=TakeOffAltitude起飞高度: " + rtkState.getTakeOffAltitude() + "\n"+ "F=DistanceToHomePoint离家点的距离: " + rtkState.getDistanceToHomePoint() + "\n" +"G=PositioningSolution描述了用于确定定位的方法: " + rtkState.getPositioningSolution() + "\n"+ "H=Error错误信息: " + rtkState.getError() + "\n"+ "I=HeadingValid航向有效性: " + rtkState.isHeadingValid() + "\n" +"J=Heading移动站度数: " + rtkState.getHeading() + "\n"+ "K=HeadingSolution确定精度的方法: " + rtkState.getHeadingSolution() + "\n"+ "L=MobileStationLocation指示RTK位置数据: " + rtkState.getMobileStationLocation() + "\n" +"M=MobileStationAltitude移动台接收器相对于地面系统位置的高度: " + rtkState.getMobileStationAltitude() + "\n"+ "N=MobileStationStandardDeviation以米为单位的定位精度的标准偏差: " + rtkState.getMobileStationStandardDeviation().getStdLatitude()+ "," + rtkState.getMobileStationStandardDeviation().getStdLongitude() + "," + rtkState.getMobileStationStandardDeviation().getStdAltitude() + "\n"+ "O=FusionMobileStationLocation移动台的融合位置: " + rtkState.getFusionMobileStationLocation() + "\n" +"P=FusionMobileStationAltitude移动台的融合高度: " + rtkState.getFusionMobileStationAltitude() + "\n"+ "Q=FusionHeading移动台的融合航向: " + rtkState.getFusionHeading() + "\n"+ "R=BaseStationLocation基站的位置坐标: " + rtkState.getBaseStationLocation() + "\n" +"S=BaseStationAltitude基站在海平面以上的高度: " + rtkState.getBaseStationAltitude() + "\n"+ "T=MobileStationReceiver1GPSInfo单个RTK接收器GPS信息,卫星计数: " + rtkState.getMobileStationReceiver1GPSInfo().getSatelliteCount() + "\n"+ "U=MobileStationReceiver1BeiDouInfo单个RTK接收器北斗信息,卫星计数: " + rtkState.getMobileStationReceiver1BeiDouInfo().getSatelliteCount() + "\n" +"V=MobileStationReceiver1GLONASSInfo 每个接收器连接到单个天线: " + rtkState.getMobileStationReceiver1GLONASSInfo().getSatelliteCount() + "\n"+ "W=MobileStationReceiver1GalileoInfo每个接收器连接到单个天线: " + rtkState.getMobileStationReceiver1GalileoInfo().getSatelliteCount() + "\n"+ "X=MobileStationReceiver2GPSInfo移动台2GPS信息: " + rtkState.getMobileStationReceiver2GPSInfo().getSatelliteCount() + "\n" +"Y=MobileStationReceiver2BeiDouInfo移动台2北斗信息: " + rtkState.getMobileStationReceiver2BeiDouInfo().getSatelliteCount() + "\n"+ "Z=MobileStationReceiver2GLONASSInfo移动台信息: " + rtkState.getMobileStationReceiver2GLONASSInfo().getSatelliteCount() + "\n"+ "ZA=MobileStationReceiver2GalileoInfo移动台信息: " + rtkState.getMobileStationReceiver2GalileoInfo().getSatelliteCount() + "\n" +"ZB=BaseStationReceiverGPSInfo: " + rtkState.getBaseStationReceiverGPSInfo().getSatelliteCount() + "\n"+ "ZC=BaseStationReceiverBeiDouInfo: " + rtkState.getBaseStationReceiverBeiDouInfo().getSatelliteCount() + "\n"+ "ZD=BaseStationReceiverGLONASSInfo: " + rtkState.getBaseStationReceiverGLONASSInfo().getSatelliteCount() + "\n" +"ZE=BaseStationReceiverGalileoInfo: " + rtkState.getBaseStationReceiverGalileoInfo().getSatelliteCount() + "\n"+ "ZF=MobileStationReceiver1GPSInfo: " + rtkState.getMobileStationReceiver1GPSInfo().getSatelliteCount() + "\n"+ "ZG=MobileStationReceiver1BeiDouInfo: " + rtkState.getMobileStationReceiver1BeiDouInfo().getSatelliteCount() + "\n";// NettyClient.getInstance().sendMsgToServer(description);}});
6.获取基站的电池,移动站是否连接,主要看你能不能拿到移动站的电压,能拿到那就是连上了,拿不到就是没连上
if (ModuleVerificationUtil.isBaseStationAvailable()) {mBaseStation = ((Aircraft) DJISampleApplication.getProductInstance()).getBaseStation();mBaseStation.addBaseStationBatteryStateUpdatedCallback(baseStationBatteryState -> {String description5 ="电压: " + baseStationBatteryState.getVoltage()+ ",电流" + baseStationBatteryState.getCurrent()+ ",电池剩余" + baseStationBatteryState.getCapacityPercent()+ ",温度: " + baseStationBatteryState.getTemperature();// NettyClient.getInstance().sendMsgToServer(description5);changeDescription2(baseStationBatteryState);});mBaseStation.addBaseStationStateUpdatedCallback(new BaseStationState.Callback() {@Overridepublic void onUpdateBaseStationState(BaseStationState baseStationState) {//添加回调以接收最新的基站状态。 仅受Phantom 4 RTK和M200系列v2支持String description6 ="电压: " + baseStationState.isAllowedToUse()+ ",基站位置类型" + baseStationState.getBaseStationLocationType();getActivity().runOnUiThread(new Runnable() {@Overridepublic void run() {tv_tem5.setText(description6);}});}});}
到这里,移动站的连接就差不多结束了,接下来看看自定义网络的连接
1.切换信号源到网络rtk
//设置信号源 网络RTKmRtk.setReferenceStationSource(ReferenceStationSource.CUSTOM_NETWORK_SERVICE, new CommonCallbacks.CompletionCallback() {@Overridepublic void onResult(DJIError djiError) {}});
2.查看当前信号源:
mRtk.addReferenceStationSourceCallback(new ReferenceStationSource.Callback() {@Overridepublic void onReferenceStationSourceUpdate(ReferenceStationSource referenceStationSource) {String description3 = "AC=设置RTK信号源-网络rtk: " + referenceStationSource.toString();// NettyClient.getInstance().sendMsgToServer(description3);}});
3.设置千寻账号,没有的自己去注册,需要付费
NetworkServiceSettings里面
getServerAddress 地址
getPort 端口号
getUserName 用户名
getPassword 密码
getMountPoint 域名 可以直接设置,测试的时候我是直接写死的数据,实际应用,需要有一个输入框,动态改变数据
if (ModuleVerificationUtil.isNetRtkAvailable()) {mRTKNetworkServiceProvider = DJISDKManager.getInstance().getRTKNetworkServiceProvider();ipString = etip.getText().toString();mRTKNetworkServiceProvider.setCustomNetworkSettings(new NetworkServiceSettings.Builder().userName("testuser").password("admin123").ip("10.0.19.105").port(9102).mountPoint("MMPT32_GGB").build()); //设置千寻网络地址String description4 = "AD=网络服务的设置IP: "+ mRTKNetworkServiceProvider.getCustomNetworkSettings().getServerAddress()+ ",端口号:" + mRTKNetworkServiceProvider.getCustomNetworkSettings().getPort()+ ",用户名:" + mRTKNetworkServiceProvider.getCustomNetworkSettings().getUserName()+ ",密码:" + mRTKNetworkServiceProvider.getCustomNetworkSettings().getPassword()+ ",域名:" + mRTKNetworkServiceProvider.getCustomNetworkSettings().getMountPoint();// NettyClient.getInstance().sendMsgToServer(description4);}
4.开启网络服务:
if (ModuleVerificationUtil.isNetRtkAvailable()) {mRTKNetworkServiceProvider = DJISDKManager.getInstance().getRTKNetworkServiceProvider();mRTKNetworkServiceProvider.startNetworkService(new CommonCallbacks.CompletionCallback() {@Overridepublic void onResult(DJIError djiError) {// 启动作为参考站的网络服务// String description5 = "AE=启用网络服务: " + djiError.toString();// NettyClient.getInstance().sendMsgToServer(description5);}});}
5.获取连接状态,如果 description5 这个值能拿到 TRANSMITTING 的话,就表示连接成功,就可以拿到数据了
if (ModuleVerificationUtil.isNetRtkAvailable()) {mRTKNetworkServiceProvider = DJISDKManager.getInstance().getRTKNetworkServiceProvider();mRTKNetworkServiceProvider.addNetworkServiceStateCallback(new NetworkServiceState.Callback() {@Overridepublic void onNetworkServiceStateUpdate(NetworkServiceState networkServiceState) {String description5 = String.valueOf(networkServiceState.getChannelState());// NettyClient.getInstance().sendMsgToServer(description5);changeDescription(description5);}});}
NetworkServiceChannelState
DISABLED | The network service is not started.未连接 |
NETWORK_NOT_REACHABLE | The network is not reachable from the mobile device. |
AIRCRAFT_DISCONNECTED | The aircraft is not connected. |
LOGIN_FAILURE | SDK cannot login with the provided username and password. Check getError . |
TRANSMITTING | Data is transmitting through the channel. 表示连接上 |
DISCONNECTED | The channel is disconnected and the server is not reachable now. Check getError . 连接失败 |
ACCOUNT_ERROR | User account error. Check getError . |
SERVER_NOT_REACHABLE | Unable to connect to server. |
CONNECTING | Connecting to server. |
SERVICE_SUSPENSION | The account for network RTK plan A has been expired, please activate plan B. |
INVALID_REQUEST | The invalid request is rejected by the server. |
UNKNOWN | Unknown. |
需要源码的,自行下载
end