dji-sdk / Mobile-SDK-Android

DJI Mobile SDK for Android: http://developer.dji.com/mobile-sdk/
Other
972 stars 580 forks source link

Altitude rise function is not accurate #1303

Open smpark00 opened 1 month ago

smpark00 commented 1 month ago

Hi. I'm making a simple app to make altitude rise about 1 meter when I press a button. My drone model is DJI-Mavic Pro 2. There is a virtual stick mode in the Sample App for SDK, and I added a button to raise the altitude.

image -> In view_virtual_stick.xml

image

And then, I made a code to call the function gohighOnemeter when the button is pressed. It works, but the elevation to go up is not constant and random (0.4m, 1m, 1.3m, 0.1m.... etc). Sometimes, it doesn't go up even when I press the button. I need help for how can i make the altitude rise accurate. I want to make a drone rise about 1 meter when I press a button.

private void gohighOnemeter(final FlightController flightController) {

    if (flightController.isVirtualStickControlModeAvailable()) {
        VerticalControlMode verticalControlMode = flightController.getVerticalControlMode();
        if (verticalControlMode == VerticalControlMode.VELOCITY) {
            final float ascentSpeed = 2.0f; // going up velocity (m/s)
            final long duration = 1000; // duration
            final long interval = 400; // making interval
            final Handler handler = new Handler();
            final Runnable runnable = new Runnable() {
                @Override
                public void run() {
                    FlightControlData controlData = new FlightControlData(0, 0, 0, ascentSpeed);
                    flightController.sendVirtualStickFlightControlData(controlData, new CommonCallbacks.CompletionCallback() {
                        @Override
                        public void onResult(DJIError djiError) {
                            if (djiError == null) {
                                ToastUtils.setResultToToast("Going up...");
                            } else {
                                DialogUtils.showDialogBasedOnError(null, djiError);
                            }
                        }
                    });
                    handler.postDelayed(this, interval);
                }
            };

            handler.post(runnable);     
            handler.postDelayed(new Runnable() {    //after duration, stop drone going up
                @Override
                public void run() {
                    handler.removeCallbacks(runnable);
                    // after duration making drone's velocity to 0
                    FlightControlData stopControlData = new FlightControlData(0, 0, 0, 0);
                    flightController.sendVirtualStickFlightControlData(stopControlData, new CommonCallbacks.CompletionCallback() {
                        @Override
                        public void onResult(DJIError djiError) {
                            if (djiError == null) {
                                ToastUtils.setResultToToast("Fin");
                            } else {
                                DialogUtils.showDialogBasedOnError(null, djiError);
                            }
                        }
                    });
                }
            }, duration);

        } else {
            ToastUtils.setResultToToast("set mode to VELOCITY");
        }
    } else {
        ToastUtils.setResultToToast("Enable the virtual stick mode");
    }
}

And I want to ask about altitude mode in vertical mode. I think it's easier than velocity mode to go up accurately, but when I set it to altitude mode, my drone goes to the lowest altitude possible. It goes up a little but soon tries going down when I push the button to go up.

dji-dev commented 1 month ago

Agent comment from yating.liao in Zendesk ticket #107355:

From your code, it seems that pressing the button once only sends a single virtual joystick command. The virtual joystick function requires sending remote control commands at a frequency of 5-25hz to continuously move the aircraft according to the virtual joystick commands. Sending the command only once may not achieve your goal.

In fact, in the vertical direction, the virtual joystick provides a POSITION control mode, which allows the aircraft to move to a specific height. Assuming the current height of the aircraft is 0, if you follow the required frequency, set the vertical control mode to POSITION, and the vertical parameter to 2, then the aircraft will ascend to 2 meters and hover.

°°°

smpark00 commented 1 month ago

How can I send 5-25hz to continuously move the aircraft with the virtual joystick command with code? Can I get a code that sends continuous commands?

And I want to make to function with POSITION control mode, but when I turn to POSITION control mode, my drone go down to lowest altitude. How can change my position?? Can I get a example code for this?

dji-dev commented 1 month ago

Agent comment from yating.liao in Zendesk ticket #107355:

Here is an example code for a virtual joystick:https://github.com/dji-sdk/Mobile-SDK-Android/blob/master/Sample%20Code/app/src/main/java/com/dji/sdk/sample/demo/flightcontroller/VirtualStickView.java In POSITION mode, the aircraft descends because if you do not continuously send the position, the aircraft will default to a value of 0, which means the altitude is 0.

°°°

smpark00 commented 1 month ago

I found a clue to solving the problem. Thanks!!

And I have one more question. When I take a picture with Camera Shootmode for a single photo, can I change the file name for the picture file? I want to save the info about the single photo (ex. DJI_0098 -> 24051610m1m)

dji-dev commented 1 month ago

Agent comment from yating.liao in Zendesk ticket #107355:

Sorry, we are unable to modify the name of the photo before generating it. You can add some information after the photo name, but the photo name still needs to maintain its fixed format. Here is the interface for setting the name suffix:https://developer.dji.com/api-reference/android-api/Components/Camera/DJICamera.html#djicamera_camerasettings_setcustomexpandfilename_inline

°°°

smpark00 commented 1 month ago

That method works only in Zenmmuse P1, Zenmuse H20 Series. Then is there any method that can save a json file? (about the altitude or camera angle, battery.... else) I want to take a photo and get some information about the photo's info (like the altitude or camera angle)

dji-dev commented 1 month ago

Agent comment from yating.liao in Zendesk ticket #107355:

The SDK does not provide an interface for storing JSON, but you can retrieve this information using interfaces. For example, you can use the height interface to get the height, the camera attitude interface to get the attitude, and the battery interface to get the battery level.

Actually, height and attitude data are stored in the photo metadata, written in XMP. If you have the photo, you can parse this information using third-party tools.

°°°

smpark00 commented 1 month ago

I found the height and attitude data in the photo metadata. Thanks!

I have one more question. I'd like to know the simple distance, except height, how much I've moved from the drone's starting point. (Except GPS data) I heard that GPS data is not very accurate. I need accurate information on a meter-by-meter basis, so I'm looking for an accurate way to measure distance.

dji-dev commented 1 month ago

Agent comment from yating.liao in Zendesk ticket #107355:

If you are not using other auxiliary functions to improve the positioning of the aircraft, the aircraft can currently only calculate the distance based on the GPS location. The auxiliary function refers to the RTK function, which can improve the positioning accuracy of the aircraft.

°°°