问题
I am trying to create a FollowMeMission using the DJI Phantom 4 by providing custom coordinates, similar to this post Custom coordinates on Follow me Mission DJI Mobile SDK for android
My current code looks like this:
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();
}
I even added a 2.5 sec sleep before calling startMission() as advised in this topic http://forum.dev.dji.com/thread-33716-1-1.html
What happens is, i invoke FollowMe() and after 2.5 sec i get the message "Mission Start: Successfull", but without any callback from updateFollowingTarget(). Then nothing happens, the drone stays where it is.
What am i doing wrong? Is the way i use updateFollowingTarget() and startMission() even right?
回答1:
The causes on this issue are:
1. We need use timer to updateFollowingTarget in a given frequency.
2. The moving object (following target) need provide its dynamic location.
Please refer to below code to refine it for your case:
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();
}
}
来源:https://stackoverflow.com/questions/48404526/custom-follow-me-mission-dji-android-sdk