How do I use the onCommandReceive method for flightplan?


#1

Hi guys. I am a beginner developer of the drone flight planning project.

Based on the code referenced in the forum, I managed to transfer malink files to bebop 2 using FTP!

I also confirmed that the mavlink file was successfully transferred to the flighltplan directory of the bebop 2.

By the way, I ran the startmavlink method, but nothing happened.

My guess is that in the parrot developer’s document, onCommandRecived method returns the status of bebop2.

I know that I have to check the following conditions to run the flighltplan. e.g) GPS, xyz calibration.

But I don’t know how to handle the state values in that method.

Here are the screenshots and the code.

I need your help to solve this problem.

[images]

//Android Studio Log

//Drone’s Directory

[codes]

//DroneController

public void transmitMavlinkFile(final Context ctx, @NonNull ARDiscoveryDeviceService deviceService, final String filename) {
    try {
        ARDISCOVERY_PRODUCT_ENUM product = ARDiscoveryService.getProductFromProductID(deviceService.getProductID());
        String address = ((ARDiscoveryDeviceNetService)(deviceService.getDevice())).getIp();
        ARFeatureCommon featureCommon = mDeviceController.getFeatureCommon();

        dataTransferManager = new ARDataTransferManager();
        uploader = dataTransferManager.getARDataTransferUploader();
        uploadManager = new ARUtilsManager();

        if (product == ARDISCOVERY_PRODUCT_ENUM.ARDISCOVERY_PRODUCT_SKYCONTROLLER_2) {
            uploadManager.initWifiFtp(UsbAccessoryMux.get(ctx).getMux().newMuxRef(), address, 61, "", "");
        } else {
            uploadManager.initWifiFtp(address, 61, "", "");
        }
        final UploadListener listener = new UploadListener(featureCommon);
        uploader.createUploader(uploadManager, "flightPlan.mavlink", filename, listener, null, listener, null, ARDATATRANSFER_UPLOADER_RESUME_ENUM.ARDATATRANSFER_UPLOADER_RESUME_FALSE);

        uploadHandlerThread = new HandlerThread("mavlink_uploader");
        uploadHandlerThread.start();

        uploadRunnable = uploader.getUploaderRunnable();
        uploadHandler = new Handler(uploadHandlerThread.getLooper());

        uploadHandler.post(uploadRunnable);
        Log.i(TAG, "transmit is success");

    } catch (Exception e) {
        Log.e(TAG, "transmitMavlinkFile exception: " + e.getMessage(), e);
    }
}

 private class UploadListener implements ARDataTransferUploaderProgressListener, ARDataTransferUploaderCompletionListener {

    private final ARFeatureCommon featureCommon;

    private UploadListener(final ARFeatureCommon featureCommon) {
        this.featureCommon = featureCommon;
    }

    @Override
    public void didUploadComplete(Object arg, final ARDATATRANSFER_ERROR_ENUM error) {
        //if (ARPro3Application.DEBUG) Log.d(TAG, "mavlink didUploadComplete status=" + error.name());

        final Object lock = new Object();

        synchronized (lock) {
            new Thread() {
                @Override
                public void run() {
                    synchronized (lock) {
                        uploader.cancelThread();
                        uploader.dispose();
                        uploader = null;

                        uploadManager.closeWifiFtp();
                        uploadManager.dispose();
                        uploadManager = null;

                        dataTransferManager.dispose();
                        dataTransferManager = null;

                        uploadHandlerThread.quit();
                        uploadHandlerThread = null;

                        //if (ARPro3Application.DEBUG) Log.d(TAG, "released uploader resources");

                        if (featureCommon != null && error == ARDATATRANSFER_ERROR_ENUM.ARDATATRANSFER_OK) {
                           // if (ARPro3Application.DEBUG) Log.d(TAG, "sendMavlinkStart");
                            featureCommon.sendMavlinkStart("flightPlan.mavlink", ARCOMMANDS_COMMON_MAVLINK_START_TYPE_ENUM.ARCOMMANDS_COMMON_MAVLINK_START_TYPE_FLIGHTPLAN);
                            Log.i(TAG,"SendMavlink is Success");
                        }
                    }
                }
            }.start();
        }
    }

    @Override
    public void didUploadProgress(Object arg, float percent) {
        /*
        if (ARPro3Application.DEBUG)
            Log.d(TAG, "mavlink file upload progress=" + percent);
            */
    }
}

//Here's MapsActivity

private void initIHM() {
    mTakeoffLandButton = (ImageButton) findViewById(R.id.btn_takeoff_land);
    //mVideoView = (BebopVideoView) findViewById(R.id.videoView);
    mBatteryIndicator = (ImageView) findViewById(R.id.battery_indicator);
    mBatteryBar = (ProgressBar) findViewById(R.id.batteryLevel);

 
    mTakeoffLandButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            LatLng latLng = mylatLng;
            String fileName;
            switch (mBebopDrone.getAutoFlyingState()) {
                case ARCOMMANDS_COMMON_MAVLINKSTATE_MAVLINKFILEPLAYINGSTATECHANGED_STATE_LOADED:
                    Log.i(TAG, "loaded state");
                    break;
                case ARCOMMANDS_COMMON_MAVLINKSTATE_MAVLINKFILEPLAYINGSTATECHANGED_STATE_PLAYING:
                    Log.i(TAG, "playing state");
                    break;
                case ARCOMMANDS_COMMON_MAVLINKSTATE_MAVLINKFILEPLAYINGSTATECHANGED_STATE_PAUSED:
                    Log.i(TAG, "paused state");
                    break;
                case ARCOMMANDS_COMMON_MAVLINKSTATE_MAVLINKFILEPLAYINGSTATECHANGED_STATE_STOPPED:
                    //mBebopDrone.setOutdoorMode();
                    //mBebopDrone.setCalibreation();
                    latLng = new LatLng(mylatitude,mylongitude);
                    fileName = mBebopDrone.generateMavlink(latLng,1.5f,1.5f);
                    //fileName = mBebopDrone.generateMavlinkFile(latLng, 1.5f, 1.5f);
                    mBebopDrone.transmitMavlinkFile(MapsActivity.this, service, fileName);
                    Log.i(TAG, "playing");
                    break;
                default:
                    Log.i(TAG, "default");
                    break;
            }
            /*
            switch (mBebopDrone.getFlyingState()) {
                    //mDrone.takeOff();
                    //.startMavlink(mylatLng,altitude,yaw);
                    break;
                // Atterir directement après le décollage ?
                case ARCOMMANDS_ARDRONE3_PILOTINGSTATE_FLYINGSTATECHANGED_STATE_TAKINGOFF:
                case ARCOMMANDS_ARDRONE3_PILOTINGSTATE_FLYINGSTATECHANGED_STATE_FLYING:
                case ARCOMMANDS_ARDRONE3_PILOTINGSTATE_FLYINGSTATECHANGED_STATE_HOVERING:
                    mBebopDrone.land();
                    break;
            }*/
        }
    });
    // Atterrissage d'urgence
    findViewById(R.id.btn_emergency).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            mBebopDrone.emergency();
        }
    });
}

#2

Hi,

You can check if FlightPlan is available with this event.

Then you can check all the “components” needed to start a FlightPlan. All of them which have a state equal to 0 are not ok and have to be fixed.