如何在android studio上增加万向节角度?

时间:2017-04-20 02:03:14

标签: java android-studio angle dji-sdk gimbal

我一直在研究这种万向节代码,现在试图让我的DJI Matrice 100无人机上的相机万向节在每次按下按钮方向时轻微移动。我尝试使用for和while循环来增加角度值,但它似乎只读取循环内部的角度而不是循环本身。有没有人有任何建议如何让万向节增加角度onClick? 这是万向节旋转的代码。 (注意:我测试的for循环行被注释掉了。上次测试了while循环。):

   private void rotateGimbalToMin (Button button) {

    DJIGimbal gimbal = getGimbalInstance();
    if (gimbal == null){
        return;
    }

    Object key = getCorrespondingKeyWithButton(button);
    Number minValue = ((DJIParamMinMaxCapability)(gimbal.gimbalCapability().get(key))).getMin();

    if (key == DJIGimbalCapabilityKey.AdjustPitch){ //down
        //for(double anglex = 0; anglex >= -180;anglex+= -20) {
        while(anglex != -180){
            mPitchRotation.direction = DJIGimbalRotateDirection.Clockwise;
            mPitchRotation.angle = -20; //TODO minValue.floatValue()
            anglex+= -20;
        }
    }

    if(key == DJIGimbalCapabilityKey.AdjustYaw){ //left
        //for(double anglex = 0; anglex <= 180; anglex+=20) {//test for loop
        while(anglex != 180){
            mYawRotation.direction = DJIGimbalRotateDirection.Clockwise;
            mYawRotation.angle = 20; //TODO minValue.floatValue()
            anglex+=20;
        }
    }

    sendRotateGimbalCommand();
}

private void rotateGimbalToMax(Button button) {

    DJIGimbal gimbal = getGimbalInstance();
    if (gimbal == null){
        return;
    }

    Object key = getCorrespondingKeyWithButton(button);
    Number maxValue = ((DJIParamMinMaxCapability)(gimbal.gimbalCapability().get(key))).getMax();

    if (key == DJIGimbalCapabilityKey.AdjustPitch){ //up
        //for(double anglex = 0; anglex <= 40; anglex+=20) {//test for loop
            while(anglex != 40){
            mPitchRotation.direction = DJIGimbalRotateDirection.Clockwise;
            mPitchRotation.angle = 10; //TODO maxValue.floatValue()
                this.anglex+=10;
        }
    }

    if(key == DJIGimbalCapabilityKey.AdjustYaw){ //right
        //for(double anglex = 0; anglex >= -180; anglex+=-20) {
        while(anglex != -180){
            mYawRotation.direction = DJIGimbalRotateDirection.Clockwise;
            mYawRotation.angle = -20; //TODO maxValue.floatValue()
            anglex+= -20;
        }
    }

//        if(key == DJIGimbalCapabilityKey.AdjustRoll){
//            mRollRotation.direction = DJIGimbalRotateDirection.Clockwise;
//            mRollRotation.angle = maxValue.floatValue();
//        }

    sendRotateGimbalCommand();
}

以下是OnClick代码:

@Override
public void onClick(View v) {

    switch (v.getId()) {
        case R.id.btn_capture:{
            captureAction();
            break;
        }
        case R.id.btn_shoot_photo_mode:{
            switchCameraMode(DJICameraSettingsDef.CameraMode.ShootPhoto);
            break;
        }
        case R.id.btn_record_video_mode:{
            switchCameraMode(DJICameraSettingsDef.CameraMode.RecordVideo);
            break;
        }
        case R.id.btn_goLeft:{
            rotateGimbalToMax((Button)v);
            break;
        }
        case R.id.btn_goRight:{
            rotateGimbalToMin((Button) v);
            break;
        }
        case R.id.btn_goDown:{
            rotateGimbalToMin((Button) v);
            break;
        }
        case R.id.btn_goUp:{
            rotateGimbalToMax((Button) v);
            break;
        }
        case R.id.btn_reset:{
            mPitchRotation.angle = 0;
            mYawRotation.angle = 0;
        default:
            break;
    }
}

0 个答案:

没有答案