Allowing bebop drone to do multiple commands


#1

Hi there
Am trying to write a function that takes multiple points of interests. Suppose that I have P1, P2 and P3. How to create a wait function for the drone to go from P1 to P2 and then to P3.

I’m using the below function to move the drone to a given position.

    public void goToPOI(double x,double y,double z){
        if ((mDeviceController != null) && (mState.equals(ARCONTROLLER_DEVICE_STATE_ENUM.ARCONTROLLER_DEVICE_STATE_RUNNING))) {
            mDeviceController.getFeatureARDrone3().sendPilotingMoveTo(x, y, z, ARCOMMANDS_ARDRONE3_PILOTING_MOVETO_ORIENTATION_MODE_TO_TARGET,1);
        } 

Also, i created a Listener to listen for onMove change update

void onMovedToChange(ARCOMMANDS_ARDRONE3_PILOTINGSTATE_MOVETOCHANGED_STATUS_ENUM movetochanged_status);



    private void notifyMoveToChange(ARCOMMANDS_ARDRONE3_PILOTINGSTATE_MOVETOCHANGED_STATUS_ENUM movetochanged_status) {
        List<Listener> listenersCpy = new ArrayList<>(mListeners);
        for (Listener listener : listenersCpy) {
            listener.onMovedToChange(movetochanged_status);
        }
    }

And i added the following to the onReceive

else if ((commandKey == ARCONTROLLER_DICTIONARY_KEY_ENUM.ARCONTROLLER_DICTIONARY_KEY_ARDRONE3_PILOTINGSTATE_MOVETOCHANGED) && (elementDictionary != null)){
                ARControllerArgumentDictionary<Object> args = elementDictionary.get(ARControllerDictionary.ARCONTROLLER_DICTIONARY_SINGLE_KEY);
                if (args != null) {
                    double latitude = (double)args.get(ARFeatureARDrone3.ARCONTROLLER_DICTIONARY_KEY_ARDRONE3_PILOTINGSTATE_MOVETOCHANGED_LATITUDE);
                    double longitude = (double)args.get(ARFeatureARDrone3.ARCONTROLLER_DICTIONARY_KEY_ARDRONE3_PILOTINGSTATE_MOVETOCHANGED_LONGITUDE);
                    double altitude = (double)args.get(ARFeatureARDrone3.ARCONTROLLER_DICTIONARY_KEY_ARDRONE3_PILOTINGSTATE_MOVETOCHANGED_ALTITUDE);
                    ARCOMMANDS_ARDRONE3_PILOTINGSTATE_MOVETOCHANGED_ORIENTATION_MODE_ENUM orientation_mode = ARCOMMANDS_ARDRONE3_PILOTINGSTATE_MOVETOCHANGED_ORIENTATION_MODE_ENUM.getFromValue((Integer)args.get(ARFeatureARDrone3.ARCONTROLLER_DICTIONARY_KEY_ARDRONE3_PILOTINGSTATE_MOVETOCHANGED_ORIENTATION_MODE));
                    float heading = (float)((Double)args.get(ARFeatureARDrone3.ARCONTROLLER_DICTIONARY_KEY_ARDRONE3_PILOTINGSTATE_MOVETOCHANGED_HEADING)).doubleValue();
                    final ARCOMMANDS_ARDRONE3_PILOTINGSTATE_MOVETOCHANGED_STATUS_ENUM status = ARCOMMANDS_ARDRONE3_PILOTINGSTATE_MOVETOCHANGED_STATUS_ENUM.getFromValue((Integer)args.get(ARFeatureARDrone3.ARCONTROLLER_DICTIONARY_KEY_ARDRONE3_PILOTINGSTATE_MOVETOCHANGED_STATUS));


                    mHandler.post(new Runnable() {
                        @Override
                        public void run() {
                            movetochanged_status_enum = status;
                            notifyMoveToChange(status);

                        }
                    });
                }

Is there a way to ask the system to do each mission in order.

Thank you in advance

Edit by @Djavan: added code blocks


#2

Hi.

The MoveTo API is a “one shot”. So you’ll have to wait for the first one to be finished in order to start a new one.
Here is what you can do:

public void onMovedToChange(ARCOMMANDS_ARDRONE3_PILOTINGSTATE_MOVETOCHANGED_STATUS_ENUM status) {
   if (status == STOPPED) {
        switch (moveToIdx) {
               case 1: 
                    goToPOI(x1, y1, z1);
                    moveToIdx++;
                    break;
              case 2:
                    goToPOI(x2, y2, z2);
                    moveToIdx++;
                    break;
              default:
                   break;
        }
   }
}

This code probably won’t compile, but you can get the idea :slight_smile: