Reputation: 176
I'm trying to rotate my phantom 3 using the Sdk 3.0.1 but without success,
My code:
DJIFlightController flightController = ((DJIAircraft) mProduct).getFlightController();
flightController.enableVirtualStickControlMode(new DJICompletionCallback() {
@Override
public void onResult(DJIError error) {
if (error == null) {
showToast("enableVirtualStickControlMode: success");
} else {
showToast(error.getDescription());
}
}
});
try {
sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
showToast("Set yaw control mode to angle");
flightController.setHorizontalCoordinateSystem(DJIFlightControllerDataType.DJIVirtualStickFlightCoordinateSystem.Body);
flightController.setRollPitchControlMode(DJIFlightControllerDataType.DJIVirtualStickRollPitchControlMode.Angle);
flightController.setVerticalControlMode(DJIFlightControllerDataType.DJIVirtualStickVerticalControlMode.Velocity);
flightController.setYawControlMode(DJIFlightControllerDataType.DJIVirtualStickYawControlMode.Angle);
try {
sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
DJIFlightControllerDataType.DJIVirtualStickFlightControlData flightControlData =
new DJIFlightControllerDataType.DJIVirtualStickFlightControlData(0, 0, 45, 0);
flightController.sendVirtualStickFlightControlData(flightControlData, new DJICompletionCallback() {
@Override
public void onResult(DJIError error) {
if (error == null) {
showToast("Rotation: success");
} else {
showToast(error.getDescription());
}
}
});
try {
sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
flightController.disableVirtualStickControlMode(new DJICompletionCallback() {
@Override
public void onResult(DJIError error) {
if (error == null) {
showToast("disableVirtualStickControlMode: success");
} else {
showToast(error.getDescription());
}
}
});
I get the message "Rotation: success" but the aircraft don't move. Am I doing something wrong? I really appreciate any help.
Upvotes: 1
Views: 707
Reputation: 121
I got this problem before. The performance is wired, if you just invoke sendVirtualStickFlightControlData
once. I have sent an e-mail to DJI support, they suggest me to invoke this method in such frequency, 5Hz. I tested it and everything was fine.
Something like:
Timer timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
mFlightController.sendVirtualStickFlightControlData(flightControlData, new DJICompletionCallback() {
@Override
public void onResult(DJIError error) {
if (error == null) {
showToast("Rotation: success");
} else {
showToast(error.getDescription());
}
}
});
}
}, 0, 200);
Upvotes: 4