# 大疆自主降落无人机会议纪要

#### 进展

* 完成视频流数据的解析和降落点的检测，但是还存在一些问题
* 完成了控制器的设计，方同学需重新审核一下即可进行模拟器测试

#### 未解决问题

* 相机自动对焦之后会导致参数变化，导致需要重新标定参数，但是自主降落只是功能



```java
    //    配置速度控制指令发送
    private static BaseProduct product;
    private float virtualroll = 0f;
    private float virtualpitch = 0f;
    private float virtualyaw = 0f;
    private float virtualthrottle = 0f;
    private Timer sendVirtualStickDataTimer;
    private SendVirtualStickDataTask sendVirtualStickDataTask;

    //设置虚拟摇杆
    FlightController flightController = getFlightController();

    public static synchronized BaseProduct getProductInstance() {
        product = DJISDKManager.getInstance().getProduct();
        return product;
    }

    public static boolean isAircraftConnected() {
        return getProductInstance() != null && getProductInstance() instanceof Aircraft;
    }

    public static synchronized Aircraft getAircraftInstance() {
        if (!isAircraftConnected()) {
            return null;
        }
        return (Aircraft) getProductInstance();
    }

    public static FlightController getFlightController() {
        Aircraft aircraft = getAircraftInstance();
        if (aircraft != null) {
            return aircraft.getFlightController();
        }
        return null;
    }

    public static boolean isProductModuleAvailable() {
        return (null != getProductInstance());
    }

    public static boolean isAircraft() {
        return getProductInstance() instanceof Aircraft;
    }

    public static boolean isFlightControllerAvailable() {
        return isProductModuleAvailable() && isAircraft() && (null != getAircraftInstance()
                .getFlightController());
    }
    private class SendVirtualStickDataTask extends TimerTask {

        @Override
        public void run() {
            if (isFlightControllerAvailable()) {
                getAircraftInstance()
                        .getFlightController()
                        .sendVirtualStickFlightControlData(new FlightControlData(virtualpitch,
                                        virtualroll,
                                        virtualyaw,
                                        virtualthrottle),
                                new CommonCallbacks.CompletionCallback() {
                                    @Override
                                    public void onResult(DJIError djiError) {

                                    }
                                });
            }
        }
    }
//    完成配置速度控制指令发送


//开始发送速度控制指令
    private void start_auto_landing(){
        if(flightController == null){
            if(flightController == null)Toast.makeText(MainActivity.this,"无人机未连接请连接无人机后重新打开app",Toast.LENGTH_SHORT).show();
        }else{
            long starttime = System.currentTimeMillis();
            Toast.makeText(this,"开始任务",Toast.LENGTH_SHORT).show();
            flightController.setVirtualStickModeEnabled(true, new CommonCallbacks.CompletionCallback() {
                @Override
                public void onResult(DJIError djiError) {
                    if (djiError != null) {
                        Toast.makeText(MainActivity.this,"err->"+djiError.toString(),Toast.LENGTH_SHORT).show();
                    }
                }
            });
            flightController.setFlightOrientationMode(FlightOrientationMode.AIRCRAFT_HEADING, new CommonCallbacks.CompletionCallback() {
                @Override
                public void onResult(DJIError djiError) {
                    Toast.makeText(MainActivity.this,"err->"+djiError.toString(),Toast.LENGTH_SHORT).show();

                }
            });
            flightController.setVirtualStickAdvancedModeEnabled(true);//打开虚拟摇杆高级模式
            flightController.setRollPitchControlMode(RollPitchControlMode.VELOCITY);//设置rollpitch控制为速度
            flightController.setYawControlMode(YawControlMode.ANGLE);//设置yaw控制为角度
            flightController.setVerticalControlMode(VerticalControlMode.VELOCITY);//设置垂直方向速度为速度
            flightController.setRollPitchCoordinateSystem(FlightCoordinateSystem.GROUND);//设置坐标系为大地坐标系
            long endTime = System.currentTimeMillis();
            if (null == sendVirtualStickDataTimer) {
                sendVirtualStickDataTask = new SendVirtualStickDataTask();
                sendVirtualStickDataTimer = new Timer();
                sendVirtualStickDataTimer.schedule(sendVirtualStickDataTask, 0, 50);
            }
        }
    }
//结束发送速度控制指令
    private void stop_auto_landing (){
        if(flightController != null){
            getAircraftInstance().getFlightController().setVirtualStickModeEnabled(false, new CommonCallbacks.CompletionCallback() {
                @Override
                public void onResult(DJIError djiError) {
                    if (djiError != null) {
                        Toast.makeText(MainActivity.this,"err->"+djiError.toString(),Toast.LENGTH_SHORT).show();
                    }
                }
            });
        }
        Toast.makeText(MainActivity.this,"复飞停止",Toast.LENGTH_SHORT).show();
//            虚拟摇杆停止
        if(sendVirtualStickDataTimer != null){
            sendVirtualStickDataTimer.cancel();
            sendVirtualStickDataTimer = null;
            sendVirtualStickDataTask = null;
        }
    }
```



