我正在尝试使用适用于 Phantom 3 的 DJI SDK 为 android 设备实现一个简单的跟随我应用程序。我看到 iOS 设备上有 swift 的示例代码,但找不到任何适用于 android 的东西。有没有人有任何跟随我功能的示例代码或知道我在哪里可以找到它?如果没有 DJI SDK 的任何内容,是否有使用 ardupilot 或无人机代码的示例?
我已经从 dji sdk 文档中实现了相机应用程序,现在想添加跟随我应用程序。
编辑:这是我迄今为止整理的代码。它看起来怎么样?如果这可行,我如何让跟随我的任务停止?
私人 FollowMeMissionOperator getFollowMeOperator() { return DJISDKManager.getInstance().getMissionControl().getFollowMeMissionOperator(); } //创建跟踪位置的对象 LocationTrack highAccuracyLocationTracker = new LocationTrack(this); //初始化高度为300f private float initHeight = 300f; //获取用户private 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();
}
}
});
}
}