dji-sdk / Mobile-SDK-Android

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

Combine drone telemetry and gimbal telemetry #1153

Open fatbringer opened 2 years ago

fatbringer commented 2 years ago

Hi ! I am looking to combine the onUpdate functions for both the drone telemetry and gimbal telemetry, such that whenever they are updated, the values can be shown on the screen

How may i combine these 2 functions ? Since both uses the onUpdate function ? Drone telemetry. Currently i have found from the sdk and written code like this below.

       if (ModuleVerificationUtil.isFlightControllerAvailable()) {
            mFlightController = ((Aircraft) DJISampleApplication.getProductInstance()).getFlightController();

            mFlightController.setStateCallback(new FlightControllerState.Callback() {
                @Override
                public void onUpdate(@NonNull FlightControllerState djiFlightControllerCurrentState) {

                    droneLocationLat = djiFlightControllerCurrentState.getAircraftLocation().getLatitude();
                    droneLocationLng = djiFlightControllerCurrentState.getAircraftLocation().getLongitude();
                    droneAltitude = djiFlightControllerCurrentState.getAircraftLocation().getAltitude();

                    dronePitch = djiFlightControllerCurrentState.getAttitude().pitch;
                    droneRoll = djiFlightControllerCurrentState.getAttitude().roll;
                    droneYaw = djiFlightControllerCurrentState.getAttitude().yaw;
                    droneVeloX = djiFlightControllerCurrentState.getVelocityX();
                    droneVeloY = djiFlightControllerCurrentState.getVelocityY();
                    droneVeloZ = djiFlightControllerCurrentState.getVelocityZ();
}

Gimbal telemetry. I see this inside PushGimbalDataView.java in the example app.

        if (ModuleVerificationUtil.isGimbalModuleAvailable()) {
            DJISampleApplication.getProductInstance().getGimbal().setStateCallback(new GimbalState.Callback() {
                @Override
                public void onUpdate(@NonNull GimbalState gimbalState) {
                    stringBuffer.delete(0, stringBuffer.length());

                    stringBuffer.append("PitchInDegrees: ").
                            append(gimbalState.getAttitudeInDegrees().getPitch()).append("\n");
                    stringBuffer.append("RollInDegrees: ").
                            append(gimbalState.getAttitudeInDegrees().getRoll()).append("\n");
                    stringBuffer.append("YawInDegrees: ").
                            append(gimbalState.getAttitudeInDegrees().getYaw()).append("\n");

                    showStringBufferResult();
                }

Can i combine them under the same OnUpdate ? Or do it have to be different OnUpdate ?

=============== Question: How do i find the camera's FOV and current zoom level ??

dji-dev commented 2 years ago

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

We can only read the latest status of the gimbal or drone in the respective callbacks, and then update the screen information in a method Although the callback method is both onUpdate, this method belongs to a different class, so there is no way to merge these two methods into one in the code.

°°°

fatbringer commented 2 years ago

@dji-dev can i use the callbacks to update a variable, then access the variable elsewhere from within the same class ?

Eg i assign dronePitch = djiFlightControllerCurrentState.getAttitude().pitch; , where dronePitch is a private float

Thereafter, in another function, i format dronePitch into another string, then display the new string in stringBuffer ?

dji-dev commented 2 years ago

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

Yes, you can do that. This is how we go about implementing screen information updates at sample as well.It's like this.
image.png

°°°

fatbringer commented 2 years ago

@dji-dev how can i find the camera's current FOV and zoom level ? I don't need to set the value, but i want to read the current value of the FOV and number of times zoomed

dji-dev commented 2 years ago

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

What kind of drone are you using? If it is a drone that supports zoom, you can get the current focal length by getHybridZoomFocalLength or getDigitalZoomFactor.If it is a drone that does not support zoom, you can find out the fixed focal length of the camera in the parameters of the corresponding model. You should also be able to find out the FOV values on the UAV parameters page.

°°°

fatbringer commented 2 years ago

@dji-dev i am using Mavic 2 enterprise advanced. I am also looking to use for M210 and M300

dji-dev commented 2 years ago

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

The M2EA's visible camera supports zoom, you can get the current focal length with lens.getHybridZoomFocalLength. the M210 and M300 can carry different cameras, so you need to judge according to the camera. You can determine if the zoom is supported by isHybridZoomSupported.

°°°

fatbringer commented 2 years ago

@dji-dev thank you.

may i know where in the API i can find how to move the gimbal ??

I can only find gimbal max and min. What if i want to move it to an intermediate angle ? Like 35 degrees ?

dji-dev commented 2 years ago

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

You can use gimbal.rotate to pass in the specified angle.

°°°

kenargo commented 2 years ago

Please look at the Gimbal class, it contains everything you need; hint, you don’t move the gimbal, you rotate it.

It is best if you learn how to use the available documentation, posting questions for common operations documented and included in the example will not lead to an efficient development on your part.

From: ykn96 @.> Sent: Wednesday, July 13, 2022 5:35 AM To: dji-sdk/Mobile-SDK-Android @.> Cc: Subscribed @.***> Subject: Re: [dji-sdk/Mobile-SDK-Android] Combine drone telemetry and gimbal telemetry (Issue #1153)

@dji-dev https://github.com/dji-dev thank you.

may i know where in the API i can find how to move the gimbal ??

I can only find gimbal max and min. What if i want to move it to an intermediate angle ? Like 35 degrees ?

— Reply to this email directly, view it on GitHub https://github.com/dji-sdk/Mobile-SDK-Android/issues/1153#issuecomment-1183167807 , or unsubscribe https://github.com/notifications/unsubscribe-auth/ADHP4OCZUAMYGQXKAGIJU53VT2ZY7ANCNFSM52SBIWOA . You are receiving this because you are subscribed to this thread. https://github.com/notifications/beacon/ADHP4OHZWKFFA44F7E5FDJDVT2ZY7A5CNFSM52SBIWOKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOI2C3KPY.gif Message ID: @. @.> >