How to write a code in Android to send waypoints to my 3DRobotics drone?

612 Views Asked by At

Good afternoon.

At the moment I am trying to write the code in the "Main Activity" to send some waypoints to my IRIS drone but it is only working when the points are five. Could you check my code and give me suggestions about what is happening and how can I send more waypoints to my drone? I really appreciate your help because I am new developing in Android:

Code:

public void onBtnConnectTap3(View view) {

        if (this.drone.isConnected()) {
        this.drone.disconnect();
         } else {
        Spinner connectionSelector = (Spinner) findViewById(R.id.selectConnectionType);
        int selectedConnectionType = connectionSelector.getSelectedItemPosition();

        Bundle extraParams = new Bundle();
        if (selectedConnectionType == ConnectionType.TYPE_USB) {
            extraParams.putInt(ConnectionType.EXTRA_USB_BAUD_RATE, DEFAULT_USB_BAUD_RATE); // Set default baud rate to 57600
        } else {
            extraParams.putInt(ConnectionType.EXTRA_UDP_SERVER_PORT, DEFAULT_UDP_PORT); // Set default baud rate to 14550
        }
        ConnectionParameter connectionParams = new ConnectionParameter(selectedConnectionType, extraParams, null);
        this.drone.connect(connectionParams);
        }

        currentMission = new Mission();
        currentMission.clear();

        for (int i = 1; i < 20; i++) {

        waypoint2=new Waypoint();
        yaw=new YawCondition();
        waypoint2.setCoordinate(new LatLongAlt( i, i, i));
        yaw.setAngle(i);
        missionI3 = waypoint2;
        currentMission.addMissionItem(missionI3);
        missionI2=yaw;
        currentMission.addMissionItem(missionI2);
        }

         this.drone.generateDronie();
         this.drone.setMission(currentMission, true);
         this.drone.arm(true);

        }

Dependencies in Build.gradle:
dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.1.1'
    compile 'com.o3dr.android:dronekit-android:2.3.11'
    }

I would like to know if you also know where I can keep learning about how to develop apps in Android for 3DRobotics drones taking in consideration that my main sources are: http://android.dronekit.io/first_app.html and http://android.dronekit.io/javadoc/

Thanks in advance for your answer.

1

There are 1 best solutions below

0
On

I'm not completely sure what you are trying to accomplish, but I see some possible errors in your code.

  1. Use the latest of dronekit-android. The current version is 2.7.0. You can keep up to date on the versions here https://bintray.com/3drobotics/maven/dronekit-android/view

  2. You are generating a mission with 38 items (19 waypoints, and 19 yaws). You are doing a very unsafe thing by setting waypoint coordinates to 1,1,1 ... 19,19,19. You vehicle will fly somewhere I assume you didn't intend.

  3. I'm unsure why you have generateDronie(). As per the docs

    Generate action to create a dronie mission, and upload it to the connected drone.

A dronie is a specific type mission that will fly a selfie path.

  1. setMission() is correct. However, the last step in your code is to arm the vehicle. You will need to tell the drone to actually run the mission. You can do this with the startMission() method in the MissionApi class.

  2. Be careful setting and starting mission with the same user interaction. There is always the chance that setMission() will fail to upload to the vehicle. If this is the case, startMission() will run the last mission that was successfully uploaded to the vehicle.

    You can verify the upload succeeded by listening for the broadcast AttributeEvent.MISSION_SENT.

You can always contribute to the documentation by adding javadocs to APIs that you feel are missing or need clarification.