自定义跟我走任务 DJI Android SDK
Custom Follow Me Mission DJI Android SDK
我正在尝试通过提供自定义坐标使用 DJI Phantom 4 创建 FollowMeMission,类似于此 post Custom coordinates on Follow me Mission DJI Mobile SDK for android
我当前的代码如下所示:
private double lat = 48.5561726;
private double lng = 12.1138481;
private float initHeight = 10f;
private LocationCoordinate2D location;
if (getFollowMeMissionOperator().getCurrentState().toString().equals(FollowMeMissionState.READY_TO_EXECUTE.toString())){
getFollowMeMissionOperator().updateFollowingTarget(new LocationCoordinate2D(lat + 0.0001d, lng), new CommonCallbacks.CompletionCallback() {
@Override
public void onResult(DJIError djiError) {
setResultToToast("Mission updateFollowingTarget: " + (djiError == null ? "Successfully" : djiError.getDescription()));
}
});
//Toast.makeText(getApplicationContext(), "updateFollowingTarget...", Toast.LENGTH_SHORT).show();
Log.println(Log.INFO,"FOLLOW", "Before");
try{
Thread.sleep(2500);
}catch (InterruptedException e){
setResultToToast("InterruptedException!" + e.getMessage());
}
getFollowMeMissionOperator().startMission(FollowMeMission.getInstance().initUserData(lat + 0.0001d , lng, initHeight), new CommonCallbacks.CompletionCallback() {
@Override
public void onResult(DJIError djiError) {
setResultToToast("Mission Start: " + (djiError == null ? "Successfully" : djiError.getDescription()));
}});
}
else{
Toast.makeText(getApplicationContext(), getFollowMeMissionOperator().getCurrentState().toString(), Toast.LENGTH_SHORT).show();
}
我什至按照本主题中的建议在调用 startMission() 之前添加了 2.5 秒的睡眠 http://forum.dev.dji.com/thread-33716-1-1.html
发生的事情是,我调用 FollowMe() 并在 2.5 秒后收到消息 "Mission Start: Successfull",但没有来自 updateFollowingTarget() 的任何回调。然后什么也没有发生,无人机原地不动
我做错了什么?我使用 updateFollowingTarget() 和 startMission() 的方式是否正确?
出现这个问题的原因是:
1.我们需要使用定时器以给定的频率更新FollowingTarget。
2.移动物体(跟随目标)需要提供它的动态位置。
请参考以下代码针对您的情况进行优化:
private float initHeight = 10f;
private LocationCoordinate2D movingObjectLocation;
private AtomicBoolean isRunning = new AtomicBoolean(false);
private Subscription timmerSubcription;
private Observable<Long> timer =Observable.timer(100, TimeUnit.MILLISECONDS).observeOn(Schedulers.computation()).repeat();
private void followMeStart(){
if (getFollowMeMissionOperator().getCurrentState().toString().equals(FollowMeMissionState.READY_TO_EXECUTE.toString())){
//ToDo: You need init or get the location of your moving object which will be followed by the aircraft.
getFollowMeMissionOperator().startMission(FollowMeMission.getInstance().initUserData(movingObjectLocation.getLatitude() , movingObjectLocation.getLongitude(), initHeight), new CommonCallbacks.CompletionCallback() {
@Override
public void onResult(DJIError djiError) {
setResultToToast("Mission Start: " + (djiError == null ? "Successfully" : djiError.getDescription()));
}});
if (!isRunning.get()) {
isRunning.set(true);
timmerSubcription = timer.subscribe(new Action1<Long>() {
@Override
public void call(Long aLong) {
getFollowMeMissionOperator().updateFollowingTarget(new LocationCoordinate2D(movingObjectLocation.getLatitude(),
movingObjectLocation.getLongitude()),
new CommonCallbacks.CompletionCallback() {
@Override
public void onResult(DJIError error) {
isRunning.set(false);
}
});
}
});
}
} else{
Toast.makeText(getApplicationContext(), getFollowMeMissionOperator().getCurrentState().toString(), Toast.LENGTH_SHORT).show();
}
}
我正在尝试通过提供自定义坐标使用 DJI Phantom 4 创建 FollowMeMission,类似于此 post Custom coordinates on Follow me Mission DJI Mobile SDK for android
我当前的代码如下所示:
private double lat = 48.5561726;
private double lng = 12.1138481;
private float initHeight = 10f;
private LocationCoordinate2D location;
if (getFollowMeMissionOperator().getCurrentState().toString().equals(FollowMeMissionState.READY_TO_EXECUTE.toString())){
getFollowMeMissionOperator().updateFollowingTarget(new LocationCoordinate2D(lat + 0.0001d, lng), new CommonCallbacks.CompletionCallback() {
@Override
public void onResult(DJIError djiError) {
setResultToToast("Mission updateFollowingTarget: " + (djiError == null ? "Successfully" : djiError.getDescription()));
}
});
//Toast.makeText(getApplicationContext(), "updateFollowingTarget...", Toast.LENGTH_SHORT).show();
Log.println(Log.INFO,"FOLLOW", "Before");
try{
Thread.sleep(2500);
}catch (InterruptedException e){
setResultToToast("InterruptedException!" + e.getMessage());
}
getFollowMeMissionOperator().startMission(FollowMeMission.getInstance().initUserData(lat + 0.0001d , lng, initHeight), new CommonCallbacks.CompletionCallback() {
@Override
public void onResult(DJIError djiError) {
setResultToToast("Mission Start: " + (djiError == null ? "Successfully" : djiError.getDescription()));
}});
}
else{
Toast.makeText(getApplicationContext(), getFollowMeMissionOperator().getCurrentState().toString(), Toast.LENGTH_SHORT).show();
}
我什至按照本主题中的建议在调用 startMission() 之前添加了 2.5 秒的睡眠 http://forum.dev.dji.com/thread-33716-1-1.html
发生的事情是,我调用 FollowMe() 并在 2.5 秒后收到消息 "Mission Start: Successfull",但没有来自 updateFollowingTarget() 的任何回调。然后什么也没有发生,无人机原地不动
我做错了什么?我使用 updateFollowingTarget() 和 startMission() 的方式是否正确?
出现这个问题的原因是:
1.我们需要使用定时器以给定的频率更新FollowingTarget。
2.移动物体(跟随目标)需要提供它的动态位置。
请参考以下代码针对您的情况进行优化:
private float initHeight = 10f;
private LocationCoordinate2D movingObjectLocation;
private AtomicBoolean isRunning = new AtomicBoolean(false);
private Subscription timmerSubcription;
private Observable<Long> timer =Observable.timer(100, TimeUnit.MILLISECONDS).observeOn(Schedulers.computation()).repeat();
private void followMeStart(){
if (getFollowMeMissionOperator().getCurrentState().toString().equals(FollowMeMissionState.READY_TO_EXECUTE.toString())){
//ToDo: You need init or get the location of your moving object which will be followed by the aircraft.
getFollowMeMissionOperator().startMission(FollowMeMission.getInstance().initUserData(movingObjectLocation.getLatitude() , movingObjectLocation.getLongitude(), initHeight), new CommonCallbacks.CompletionCallback() {
@Override
public void onResult(DJIError djiError) {
setResultToToast("Mission Start: " + (djiError == null ? "Successfully" : djiError.getDescription()));
}});
if (!isRunning.get()) {
isRunning.set(true);
timmerSubcription = timer.subscribe(new Action1<Long>() {
@Override
public void call(Long aLong) {
getFollowMeMissionOperator().updateFollowingTarget(new LocationCoordinate2D(movingObjectLocation.getLatitude(),
movingObjectLocation.getLongitude()),
new CommonCallbacks.CompletionCallback() {
@Override
public void onResult(DJIError error) {
isRunning.set(false);
}
});
}
});
}
} else{
Toast.makeText(getApplicationContext(), getFollowMeMissionOperator().getCurrentState().toString(), Toast.LENGTH_SHORT).show();
}
}