如何实现跟随我的功能到android dji应用程序

问题描述 投票:0回答:2

我正在尝试使用DJI SDK为Phantom 3实现一个简单的跟随我的Android设备应用程序。我看到在iOS设备上有swift的示例代码但是找不到任何东西用于android。有没有人有跟随我的功能的示例代码或知道我在哪里可以找到它?如果DJI SDK没有任何内容,那么有使用ardupilot或dronecode的例子吗?

我已经从dji sdk文档中实现了相机应用程序,现在想添加我的应用程序。

编辑:这是我到目前为止编写的代码。它看起来怎么样?如果这样可行,我如何让我的任务停止?

private FollowMeMissionOperator getFollowMeOperator(){return DJISDKManager.getInstance()。getMissionControl()。getFollowMeMissionOperator(); } //创建跟踪位置的对象LocationTrack highAccuracyLocationTracker = new LocationTrack(this); //初始化高度为300f private float initHeight = 300f; //获取用户私有的初始位置location movingObjectLocation = highAccuracyLocationTracker.getLocation();

private void followMeStart() {
    //check if status of aircraft is ready to execute
    if (getFollowMeOperator().getCurrentState().toString().equals(FollowMeMissionState.READY_TO_EXECUTE.toString())) {
        //if ready, create new mission that points aircraft in direction of object using the latitude and longitude of user and the initial height.
        FollowMeMission missionOne = new FollowMeMission(FollowMeHeading.TOWARD_FOLLOW_POSITION, movingObjectLocation.getLatitude(), movingObjectLocation.getLongitude(), initHeight);
        //starts the new mission just created
        getFollowMeOperator().startMission(missionOne, new CommonCallbacks.CompletionCallback() {
            @Override
            public void onResult(DJIError djiError) {

                // If there is no error then start the location thread
                if (djiError == null) {

                    Thread locationUpdateThread = new Thread(new Runnable() {
                        @Override
                        public void run() {

                            while (!Thread.currentThread().isInterrupted()) {

                                final Location newLocation = highAccuracyLocationTracker.getLocation();

                                getFollowMeOperator().updateFollowingTarget(new LocationCoordinate2D(newLocation.getLatitude(), newLocation.getLongitude()), new CommonCallbacks.CompletionCallback() {
                                    @Override
                                    public void onResult(DJIError djiError) {
                                        if (djiError != null) {
                                            Toast.makeText(getApplicationContext(), getFollowMeOperator().getCurrentState().toString(), Toast.LENGTH_SHORT).show();
                                        }
                                    }
                                });

                                try {
                                    Thread.sleep(100);
                                } catch (InterruptedException e) {
                                    // The exception clears the interrupt flag so I'll refresh the flag otherwise the thread keeps running
                                    Thread.currentThread().interrupt();
                                }
                            }
                        }
                    });

                    locationUpdateThread.start();
                }
            }
        });
    }
}
dji-sdk
2个回答
0
投票

旧的跟随(基于GPS)是更容易实现。

任务设置与所有其他任务相同:

  • 创建任务操作员(missionOperator = new FollowMeMissionOperator())
  • 创建FollowMeMission类型的实例。 ctor采用FollowMeHeading,开始纬度,开始经度和开始高度。 FollowMeHeading控制飞机头部指向的位置,可以是FOWARD_FOLLOW_POSITION或CONTROLLED_BY_REMOTE_CONTROLLER
  • 将FollowMeMission传递给您在上面创建的missionOperator.startMission()。
  • 如果对missionOperator.startMission()的回调成功,则启动线程并传递更新的GPS位置,以便使用missionOperator.updateFollowingTarget(新的LocationCoordinate2D(纬度,经度),回调)方法移动飞机
  • 停止跟随调用missionOperator.stopMission()

希望这可以帮助!

示例代码(我没有包含读取设备位置的代码,但下面的代码可以使用。

注意:代码没有完整的错误处理但功能正常。

    private FollowMeMissionOperator missionOperator = new FollowMeMissionOperator();

private FollowMeMission followMeInitSettings = new FollowMeMission(FollowMeHeading.TOWARD_FOLLOW_POSITION, locationCoordinate3D.getLatitude(), locationCoordinate3D.getLongitude(), locationCoordinate3D.getAltitude());

missionOperator.startMission(followMeInitSettings, new CommonCallbacks.CompletionCallback() {
                            @Override
                            public void onResult(DJIError djiError) {

                                if (djiError == null) {

                                        locationUpdateThread = new Thread(new Runnable() {
                                            @Override
                                            public void run() {

                                                while (!Thread.currentThread().isInterrupted()) {

                                                    final Location newLocation = highAccuracyLocationTracker.getLocation();

                                                    missionOperator.updateFollowingTarget(new LocationCoordinate2D(newLocation.getLatitude(), newLocation.getLongitude()), new CommonCallbacks.CompletionCallback() {
                                                        @Override
                                                        public void onResult(DJIError djiError) {
                                                            if (djiError != null) {
                                                                MyApplication.getGlobalSettings().getDebugLogger().writeLine("Follow.updateTarget failed: " + djiError.getDescription());
                                                            }
                                                        }
                                                    });

                                                    try {
                                                        Thread.sleep(100);
                                                    } catch (InterruptedException e) {
                                                        // The exception clears the interrupt flag so I'll refresh the flag otherwise the thread keeps running
                                                        Thread.currentThread().interrupt();
                                                    }
                                                }
                                            }
                                        });

                                        locationUpdateThread.start();
                                    }
                                }
                        });

0
投票

我想确定我理解你的要求,因为有两种类型的“跟随”。

较旧的坐标使用您连续发送到飞机的GPS坐标,飞机跟踪坐标。

第二个是ActiveTrack;这是对选择人或移动物体的视觉跟踪。如果你问的是ActiveTrack,有一个Android HERE的例子

你问的是哪一个?

© www.soinside.com 2019 - 2024. All rights reserved.