大疆RTK網絡和移動站連接

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() {
                        @Override
                        public void onResult(DJIError djiError) {

                        }
                    });

2.獲取rtk模塊的狀態,打開或關閉


                    mRtk.getRtkEnabled(new CommonCallbacks.CompletionCallbackWith<Boolean>() {

                        @Override
                        public void onSuccess(Boolean aBoolean) {
                            //這個東西用來判斷是否成功開啓RTK
                            //String description2 = "AZ=啓用RTK模塊: " + aBoolean;
                            //  NettyClient.getInstance().sendMsgToServer(description2);
                            getActivity().runOnUiThread(new Runnable() {
                                @Override
                                public 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() {
                        @Override
                        public void onResult(DJIError djiError) {

                        }
                    });

4.查看一下當前的信號源是什麼

    mRtk.addReferenceStationSourceCallback(new ReferenceStationSource.Callback() {
                        @Override
                        public void onReferenceStationSourceUpdate(ReferenceStationSource referenceStationSource) {
                            // String description3 = "AC=設置RTK信號源-移動站rtk: " + referenceStationSource.toString();
                            //  NettyClient.getInstance().sendMsgToServer(description3);  tv_rtk_source
                            getActivity().runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    tv_rtk_source.setText(String.valueOf(referenceStationSource));
                                }
                            });
                        }
                    });

5.拿飛機gps數據,實時刷新

       mRtk.setStateCallback(new RTKState.Callback() {
                            @Override
                            public 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() {
                            @Override
                            public void onUpdateBaseStationState(BaseStationState baseStationState) {
                                //添加回調以接收最新的基站狀態。 僅受Phantom 4 RTK和M200系列v2支持
                                String description6 =
                                        "電壓: " + baseStationState.isAllowedToUse()
                                                + ",基站位置類型" + baseStationState.getBaseStationLocationType();
                                getActivity().runOnUiThread(new Runnable() {
                                    @Override
                                    public void run() {
                                        tv_tem5.setText(description6);
                                    }
                                });
                            }
                        });


                    }

到這裏,移動站的連接就差不多結束了,接下來看看自定義網絡的連接

1.切換信號源到網絡rtk

  //設置信號源  網絡RTK
                    mRtk.setReferenceStationSource(ReferenceStationSource.CUSTOM_NETWORK_SERVICE, new CommonCallbacks.CompletionCallback() {
                        @Override
                        public void onResult(DJIError djiError) {

                        }
                    });

2.查看當前信號源:

      mRtk.addReferenceStationSourceCallback(new ReferenceStationSource.Callback() {
                        @Override
                        public 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() {
                        @Override
                        public 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() {
                            @Override
                            public 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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章