How to add mavlink items


#21

You get it from your connected DeviceController


#22

I have create this 2 files.

AutonomousBebopActivity.java

private void initIHM() {

    mTakeOffLand = (TextView)findViewById(R.id.tvTakeoffLand);
    mTakeOffLandBt = (Button) findViewById(R.id.takeOffOrLandBt);
    mTakeOffLandBt.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            LatLng latLng;
            String fileName;
            Log.i(TAG,String.format("flying state equal to = %d", mBebopDrone.getAutoFlyingState().getValue()));
        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:
                Log.i(TAG, "playing");
                latLng = new LatLng(droneLat,droneLng);
                fileName = mBebopDrone.generateMavlinkFile(latLng, 1.5f, 1.5f);
                mBebopDrone.transmitMavlinkFile(AutonomousBebopActivity.this, service, fileName);
                break;
            default:
                Log.i(TAG, "default");
                break;
        }
    }
}

AutonomousController.java

private ARDataTransferManager dataTransferManager;
private ARDataTransferUploader uploader;
private ARUtilsManager uploadManager;
private HandlerThread uploadHandlerThread;
private Runnable uploadRunnable;
private Handler uploadHandler;

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);

    } 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);
                        }
                    }
                }
            }.start();
        }
    }

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

Is it Correct?


#23

maybe?

Where is mBebopDrone created? I’m going to assume it is an instance of AutonomousController. How does mDeviceController get initialized (and connected to a drone) in AutonomousController?

Assuming all of that is working properly then sure, it’s correct. Your drone should takeoff, fly 0.00002000 degrees southeast facing 1.5 degrees (a smidge east of north) at 1.5 meters altitude. Hopefully you are flying over a very level surface or down a hill. 1.5 meters altitude doesn’t leave for much margin of error.

0.00002000 degrees appears to be about 8 feet. That may or may not be long enough for the run to be successful. It appears to be a good starting point if you are looking for a very crude way to calculate distance.

Shell


#24

Yes the mBebopDrone is a instance of AutonomousController and mDeviceController get initalized at the start of the activity by connecting to the drone by passing the service to AutonomousController.

The ARPro3Application is not available in any of the library.


#25

Now I know what is the ARPro3Application is about, it is the activity. But then the DEBUG will be a method to check the boolean value. Correct synman?


#26

ARPro3Application is the actual Android Application class for my application. please ignore (remove) it.


#27

Thank you synman.
It was really helpful.


#28

Hi guys,

What is the purpose of sendMavlinkPause() and sendMavlinkStop()?

Is it used when the drone starts hovering or it is to stop/pause the file being transmitted to the drone?


#29

Look at the documentation. :slight_smile:


#30

Hi guys,
After I takeoff, the drone does not fly to the location and return.
And the drone’s gps signal keeps on changing even before the takeoff.
Is it because of for calibration? If so how do I calibrate the gps.


#31

Hi guys,
Can someone help me out with my query?
Thanks


#32

There is no gps calibration.
Are you outside? Could you tell us more about your drone (type and firmware version).
Could you try to launch FreeFlight, go in the piloting HUD and see if the gps icon is changing on and on from green to orange? Also, in FreeFlight, if the magnetometer calibration is asked, please do it.


#33

Hi Djavan,
Sorry for the late response.

Drone: BebopDrone.
Hardware Version: HW_10
Software Version: 4.0.6

I was outside and they never ask the magnetometer calibration. But I did a manual calibration by going to the settings and calibrating.
I followed this tutorial to calibrate.

But i’m not sure is it correct or not?


#34

Hi guys,
Can anyone help me?


#35

Ok for the magnetometer calibration.


#39

Hi Djavan,
The attach link is the video that i took.
https://www.dropbox.com/s/s8j372uokt79xgr/2017_07_10_16_32_16[1].mp4?dl=0

It only show orange.

Is it possible that there might be an hardware failure?


#40

Hi, as I can see in your video, FreeFlight shows a green icon for the gps, so it should be good.
However, the other app shows a red icon, do you know why?


#41

Hi, the app is what i’m currently working on. It shows that the GPS is not stable. The value of the lat/lng keeps on changing before taking off.
However, why is the GPS Lat and Lng keeps on changing even when it is in a flat ground?


#42

It is totally normal that the gps position changes a bit. If you look on a map, the gps coordinates you got are really close.


#44

Hi, because when i fly the mavlink file the flight was not going correctly. It keeps flying some other direction and never land.