Android Question [Solved] DJI - Read GimbalPitch

schimanski

Well-Known Member
Licensed User
Longtime User
Is it possible to read out the current gimbal pitch of the dji drone?
Thanks for help!
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Were you able to run the DJI example:?

It should be possible with JavaObject.
Start with:
Het the gimbal object with:
B4X:
Dim aircraftjo As JavaObject = aircraft
Dim gimbal As JavaObject = aircraftjo.RunMethod("getGimbal", Null)
If gimbal.IsInitialized Then
 
End If

You then need to call "setStateCallback with an event created with JavaObject.CreateEventFromUI with this class: "dji.common.gimbal.GimbalState$Callback".

The event raised will include a GimbalState parameter - args(0).
 
Upvote 0

schimanski

Well-Known Member
Licensed User
Longtime User
Thank you! The following code seems to run:

B4X:
    Dim aircraftjo As JavaObject = aircraft
    Dim gimbal As JavaObject = aircraftjo.RunMethod("getGimbal", Null)
    If gimbal.IsInitialized Then
        Dim cc As Object = gimbal.CreateEventFromUI("dji.common.gimbal.GimbalState$Callback", "callback", Null)
        gimbal.RunMethod("setStateCallback", Array As Object(cc))
        Wait For (gimbal) callback_Event (MethodName As String, Args() As Object)
        Log(Args(0))
    Else
        Log("Gimbal not available.")
    End If

The result is:
B4X:
dji.common.gimbal.GimbalState@88a75585

But how is it possibel to read out the field in Args(0)?
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

schimanski

Well-Known Member
Licensed User
Longtime User
I tried to use the SDK Documentation, but

Dim gimbalstate As JavaObject = Args(0)

does not get me any further. I see, that the log of Args(0) changes with changing the gimbal-position. I'm too stupid to read out the information of the pitch in plaintextšŸ„µ
 
Upvote 0

schimanski

Well-Known Member
Licensed User
Longtime User
Ok, I have it. Thank you for your efforts!
Short info: The gimbalPitch ist the pitch in relation to the horizon. So it is not necessary to offset it with the pitch of the drone.

B4X:
    Dim aircraftjo As JavaObject = aircraft
    Dim gimbal As JavaObject = aircraftjo.RunMethod("getGimbal", Null)
    If gimbal.IsInitialized Then
        Dim cc As Object = gimbal.CreateEventFromUI("dji.common.gimbal.GimbalState$Callback", "callback", Null)
        gimbal.RunMethod("setStateCallback", Array As Object(cc))
        Wait For (gimbal) callback_Event (MethodName As String, Args() As Object)
        Dim gimbalstate As JavaObject= Args(0)
        Dim attitude As JavaObject = gimbalstate.RunMethod("getAttitudeInDegrees", Null)
        Dim Pitch As Float = attitude.RunMethod("getPitch", Null)
        Log("GimbalPitch:" & Pitch)
    Else
        Log("Gimbal not available.")
    End If
 
Upvote 0
Top