android SDK gimbal move on Mavic Mini
2988 3 2021-3-30
Uploading and Loding Picture ...(0/1)
o(^-^)o
cprest1n
lvl.1
United States
Offline

Hi, I am trying to make the camera gimbal move via the SDK. I have tried several isolated tests and I get different errors but no success.

I am running the FPV demo and modifying it to try some gimbal stuff. The camera surface is working to get camera feedback from the drone.


First I checked the capabilities map and I get these responses:


ADJUST_PITCH  supported
ADJUST_PITCH_UPWARDS supported
ADJUST_YAW not supported
ADJUST_ROLL not supported


So I should be able to change the pitch.


I have tried various combinations of parameters. I am using 2.0 as my PITCH_DELTA


These params produce callback "success" but no measured or visible change.//        rBuilder.pitch(PITCH_DELTA);
//        rBuilder.mode(RotationMode.RELATIVE_ANGLE);
//        rBuilder.time(0.5);
This is closest to what is in the demo at https://github.com/dji-sdk/Mobile-SDK-Android/blob/master/Sample%20Code/app/src/main/java/com/dji/sdk/sample/demo/gimbal/MoveGimbalWithSpeedView.java



These produce rotate gimbal error "Execution of this process has timed out"

Rotation.Builder rBuilder = new Rotation.Builder().pitch(PITCH_DELTA)
                .mode(RotationMode.SPEED)
                .yaw(Rotation.NO_ROTATION)
                .roll(Rotation.NO_ROTATION)
//                .time(0);
                .time(0.5);

Note that I tried time 0 and time 0.5

These produce rotate gimbal error "Param Illegal":
       Rotation.Builder rBuilder = new Rotation.Builder().pitch(PITCH_DELTA)
                .mode(RotationMode.ABSOLUTE_ANGLE)
                .yaw(Rotation.NO_ROTATION)
                .roll(Rotation.NO_ROTATION)
.time(0.5);
Does anyone have any notes on what I'm doing wrong or a code snippet that can move the pitch of the gimbal on a Mavic Mini?





2021-3-30
Use props
cprest1n
lvl.1
United States
Offline

side note: why is this bb software so brutal for formatting? All we need is one font for posts and a block mode for code. I've tried editing it three time and what you put in the edit box is not what comes out.... .arggh.
2021-3-30
Use props
cprest1n
lvl.1
United States
Offline

If anyone else gets in this trap, the key is to look at the omnibus sample app Gimbal  Capabilities screen, NOT the Gimbal Move screen which doesn't work on my device.

Here's some fairly clean gimbal move code that works:

    private void changePitch(boolean up) {


        Gimbal gimbal = FPVDemoApplication.getGimbalInstance();
        if (gimbal == null) return;


        Number rotValue;
        if (up) {
            rotValue = ((DJIParamMinMaxCapability) (gimbal.getCapabilities().get(CapabilityKey.ADJUST_PITCH))).getMax();
        } else {
            rotValue = ((DJIParamMinMaxCapability) (gimbal.getCapabilities().get(CapabilityKey.ADJUST_PITCH))).getMin();
        }


        Log.d("TAG", "rotation Value for cap-driven min/max " + rotValue);


        Rotation.Builder builder = new Rotation.Builder().mode(RotationMode.ABSOLUTE_ANGLE).time(2);
        builder.pitch(rotValue.floatValue());


        final Rotation rotation = builder.build();
        gimbal.rotate(rotation, new CommonCallbacks.CompletionCallback(){
            @Override
            public void onResult(DJIError djiError) {
                if (djiError == null) {
                    Log.d("TAG", "rotate gimbal success");
                    showToast("rotate gimbal success");
                }else {
                    Log.d("TAG", "rotate gimbal error " + djiError.getDescription());
                    showToast(djiError.getDescription());
                }
            }
        });
    }

2021-4-16
Use props
peteredoc
lvl.2
Flight distance : 204140 ft
United States
Offline

THANK YOU!  Confirming that this also works on a Mini 2.

I was trying to do this but getting `Rotation.  Error?  Param Illegal(255)` on the callback in `product.gimbal.rotate(rotation) {println("Rotation.  Error?  $it")}`.

Turned out that was because I was not using the `.mode(RotationMode.ABSOLUTE_ANGLE)` in `val rotation = Rotation.Builder().mode(RotationMode.ABSOLUTE_ANGLE).pitch(pitchDeg).yaw(yawDeg).build()`

Only remaining thing I'm trying to figure out is - is there a way to get the current pitch?  There doesn't seem to be any function like Gimbal.getPitch().

Edit: Answer to that last question is -
1) add a property to store latest gimbal state: private var latestGimbalState: GimbalState? = null
2) add a listener on startup to write to that property: DJISDKManager.getInstance().gimbal.setStateCallback { latestGimbalState = it }
3) Query latestGimbalState?.attitudeInDegrees.pitch to get the "current" (really the "latest received") pitch (or null if none received yet)



2022-7-26
Use props
Advanced
You need to log in before you can reply Login | Register now

Credit Rules