android大疆APP如何实现跟随功能
How to implement follow me function into android dji app
我正在尝试使用 Phantom 3 的 DJI SDK 为 android 设备实现一个简单的跟随我的应用程序。我看到 iOS 上有 swift 的示例代码] 设备,但找不到 android 的任何内容。有没有人有跟随我功能的示例代码或知道我在哪里可以找到它?如果 DJI SDK 没有任何内容,是否有使用 ardupilot 或 dronecode 的示例?
我已经实现了 dji sdk 文档中的相机应用程序,现在想添加 follow me 应用程序。
编辑:这是我到目前为止整理的代码。它看起来如何?如果这可行,我如何让跟随我的任务停止?
私有 FollowMeMissionOperator getFollowMeOperator() {
return DJISDKManager.getInstance().getMissionControl().getFollowMeMissionOperator();
}
//创建跟踪位置的对象
LocationTrack highAccuracyLocationTracker = new LocationTrack(this);
//初始化高度为300f
私人浮动 initHeight = 300f;
//获取用户初始位置
私人位置 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();
}
}
});
}
}
我想确定我理解您的要求,因为有两种 "follow"。
旧的使用您不断发送给飞机的 GPS 坐标,飞机会朝着坐标跟踪。
第二个是ActiveTrack;这是对选定人物或移动物体的视觉跟踪。如果你问的是 ActiveTrack,有一个 Android HERE
的例子
你问的是什么?
旧的跟随(基于 GPS)更容易实施。
任务设置与所有其他任务相同:
创建任务操作员(missionOperator = new FollowMeMissionOperator())
创建 FollowMeMission 类型的实例。 ctor 采用 FollowMeHeading、起始纬度、起始经度和起始高度。 FollowMeHeading 控制飞行器头部指向的位置,可以是 FOWARD_FOLLOW_POSITION 或 CONTROLLED_BY_REMOTE_CONTROLLER
将 FollowMeMission 传递给您在上面创建的 missionOperator.startMission()。
如果对 missionOperator.startMission() 的回调成功,则启动一个线程并传递更新的 GPS 位置,因为您要使用 missionOperator.updateFollowingTarget(new 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();
}
}
});
我正在尝试使用 Phantom 3 的 DJI SDK 为 android 设备实现一个简单的跟随我的应用程序。我看到 iOS 上有 swift 的示例代码] 设备,但找不到 android 的任何内容。有没有人有跟随我功能的示例代码或知道我在哪里可以找到它?如果 DJI SDK 没有任何内容,是否有使用 ardupilot 或 dronecode 的示例?
我已经实现了 dji sdk 文档中的相机应用程序,现在想添加 follow me 应用程序。
编辑:这是我到目前为止整理的代码。它看起来如何?如果这可行,我如何让跟随我的任务停止?
私有 FollowMeMissionOperator getFollowMeOperator() { return DJISDKManager.getInstance().getMissionControl().getFollowMeMissionOperator(); } //创建跟踪位置的对象 LocationTrack highAccuracyLocationTracker = new LocationTrack(this); //初始化高度为300f 私人浮动 initHeight = 300f; //获取用户初始位置 私人位置 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();
}
}
});
}
}
我想确定我理解您的要求,因为有两种 "follow"。
旧的使用您不断发送给飞机的 GPS 坐标,飞机会朝着坐标跟踪。
第二个是ActiveTrack;这是对选定人物或移动物体的视觉跟踪。如果你问的是 ActiveTrack,有一个 Android HERE
的例子你问的是什么?
旧的跟随(基于 GPS)更容易实施。
任务设置与所有其他任务相同:
创建任务操作员(missionOperator = new FollowMeMissionOperator())
创建 FollowMeMission 类型的实例。 ctor 采用 FollowMeHeading、起始纬度、起始经度和起始高度。 FollowMeHeading 控制飞行器头部指向的位置,可以是 FOWARD_FOLLOW_POSITION 或 CONTROLLED_BY_REMOTE_CONTROLLER
将 FollowMeMission 传递给您在上面创建的 missionOperator.startMission()。
如果对 missionOperator.startMission() 的回调成功,则启动一个线程并传递更新的 GPS 位置,因为您要使用 missionOperator.updateFollowingTarget(new 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();
}
}
});