通过虚拟摇杆控制DJI Mavic Enterprise

时间:2019-05-15 06:56:35

标签: android dji-sdk

我正在尝试使用命令def ajax_create_answer(request): id_model = int(request.POST.get('id_model')) data = {} form_ans = inlineformset_factory( Item , Answer , fields=('content','right', 'skills','waitings','knowledges',) , extra= 4 ) print(form_ans) template = 'learning/show_vf_multiples.html' html = render_to_string(template, context ) data['html'] = html return JsonResponse(data) 控制无人机。 要使无人机向左移动,请使用以下代码。

sendVirtualStickFlightControlData

但是,无人机向左移动然后急剧下降。

这种无人机行为的原因是什么?

2 个答案:

答案 0 :(得分:0)

我不知道为什么它急剧下降,因为您没有改变油门值。确保在使用前启用虚拟棍子。它可能与您需要设置最大值有关。这段代码对我来说很好。

    /* controllers virtual sticks command and triggers drone movement */
    private void sendVirtualStickCommands(final float pX, final float pY, final float pZ, final float pYaw){

        //maximum amounts
        float verticalJoyControlMaxSpeed = 2;
        float yawJoyControlMaxSpeed = 30;
        float pitchJoyControlMaxSpeed = 10;
        float rollJoyControlMaxSpeed = 10;

        //set yaw, pitch, throttle, roll
        float mYaw = (float)(yawJoyControlMaxSpeed * pYaw);
        float mThrottle = (float)(verticalJoyControlMaxSpeed * pZ);
        float mPitch = (float)(pitchJoyControlMaxSpeed * pX);
        float mRoll = (float)(rollJoyControlMaxSpeed * pY);

        if (mFlightController != null){
            //if virtual sticks are enabled, send the command, otherwise turn them on
            if (virtualSticksEnabled){
                mFlightController.sendVirtualStickFlightControlData(
                        new FlightControlData(
                                mPitch, mRoll, mYaw, mThrottle
                        ), new CommonCallbacks.CompletionCallback() {
                            @Override
                            public void onResult(DJIError djiError) {
                                if (djiError!=null){
                                    setResultToToast(djiError.getDescription());
                                }
                            }
                        }
                );
            } else {
                setResultToToast("flight controller virtual mode off");
                //if not enabled, enable
                mFlightController.setVirtualStickModeEnabled(true, new CommonCallbacks.CompletionCallback() {
                    @Override
                    public void onResult(DJIError djiError) {
                        if (djiError != null){
                            setResultToToast(djiError.getDescription());
                        }else
                        {
                            setResultToToast("Enable Virtual Stick Success");
                            virtualSticksEnabled = true;
                            sendVirtualStickCommands(pX, pY, pZ, pYaw);

                        }
                    }
                });
            }

        } else{
            setResultToToast("Flight Controller Null");
        }

    }

然后,朝一个方向移动:

sendVirtualStickCommands(0.1f, 0, 0, 0);//move right
sendVirtualStickCommands(-0.1f, 0, 0, 0);//move left
sendVirtualStickCommands(0, 0.1f, 0, 0);//move forward
sendVirtualStickCommands(0, -0.1f, 0, 0);//move backwards
sendVirtualStickCommands(0, 0, 0.1f, 0);//move upwards
sendVirtualStickCommands(0, 0, -0.1f, 0);//move downwards

答案 1 :(得分:0)

尝试

mFlightController.setRollPitchControlMode(RollPitchControlMode.VELOCITY);
mFlightController.setYawControlMode(YawControlMode.ANGULAR_VELOCITY);
mFlightController.setVerticalControlMode(VerticalControlMode.POSITION);
mFlightController.setRollPitchCoordinateSystem(FlightCoordinateSystem.BODY);

并设置mThrottle >= 0.0f

VerticalControlMode.POSITION中,mThrottle是您要设置的离地面高度的飞行高度。 例如,mThrottle = 2.0f意味着将无人机移动到离地面2米的地方。设置所需的高度,如果mThrottle = 0f,则无人机将升起或“下降”。