我正在尝试使用用于Phantom 3的DJI SDK为android设备实现一个简单的Follow me应用程序。我看到在iOS设备上有swift的示例代码,但找不到适用于android的任何内容。有人有没有跟随我功能的示例代码,或者知道在哪里可以找到它?如果DJI SDK没有任何功能,是否有使用ardupilot或dronecode的示例?
我已经从dji sdk文档中实现了camera应用程序,现在想添加Follow me应用程序。
编辑:这是到目前为止我编写的代码。看起来如何?如果这行得通,我该如何停止跟随我的任务?
私有FollowMeMissionOperator getFollowMeOperator(){ 返回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();
}
}
});
}
}
答案 0 :(得分:0)
我想确保我理解您的要求,因为有两种类型的“关注”。
年龄较大的飞机会使用您连续发送给飞机的GPS坐标,并且飞机会朝着该坐标跟踪。
第二个是ActiveTrack;这是对选择人员或移动物体的视觉跟踪。如果您询问有关ActiveTrack的信息,那么有一个Android HERE
示例您要问什么?
答案 1 :(得分:0)
较早的追踪(基于GPS)是较容易实现的方式。
任务设置与所有其他任务相同:
创建任务运营商(missionOperator = new FollowMeMissionOperator())
创建类型为FollowMeMission的实例。 ctor采用FollowMeHeading,起始纬度,起始经度和起始高度。 FollowMeHeading控制飞机的头部指向的位置,可以为FOWARD_FOLLOW_POSITION或CONTROLLED_BY_REMOTE_CONTROLLER
将FollowMeMission传递给您在上面创建的missionOperator.startMission()。
如果对MissionOperator.startMission()的回调成功,则启动一个线程并使用taskOperator.updateFollowingTarget(new LocationCoordinate2D(latitude,longitude),callback)方法传递要移动飞机的更新GPS位置
要停止关注call 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();
}
}
});