These are chat archives for dronekit/dronekit-android

18th
Jul 2016
buqing2009
@buqing2009
Jul 18 2016 01:16
This message was deleted
Hey guys, i'm confused that how can i read the image from camera by dronekit?
Fredia Huya-Kouadio
@ne0fhyk
Jul 18 2016 01:48
@buqing2009 can you give more context about what you're trying to accomplish
buqing2009
@buqing2009
Jul 18 2016 02:08
@ne0fhyk OK, now i have a NUC or TX1 running vision algorithm and control algorithm on the copter. And i need mobile device to control when the algorithm can be running , in the mean time, i need the image stream showing on the mobile device.
Fredia Huya-Kouadio
@ne0fhyk
Jul 18 2016 02:10
if you're using a diy copter, there's instructions on the tower wiki page to set up a video stream to Tower: https://github.com/DroidPlanner/Tower/wiki/Custom-video-stream
@buqing2009 if you're using a solo, the copter should stream automatically to the connected mobile device.
buqing2009
@buqing2009
Jul 18 2016 02:12
OK, i will try later, thank you!
pablomar13
@pablomar13
Jul 18 2016 16:17
@buqing2009 this is what I have for the solo camera... maybe it helps you.
private void startVideoStream(Surface videoSurface) {
        SoloCameraApi.getApi(drone).startVideoStream(videoSurface, "", true, new AbstractCommandListener() {
            @Override
            public void onSuccess() {
                showToast("Starting video stream.");
                String text = "Stop Stream";
                VideoStream.setText(text);
                Streaming = true;
            }
            @Override
            public void onError(int executionError) {
                showToast("Error while starting the video stream: " + executionError);
            }
            @Override
            public void onTimeout() {
                showToast("Timed out while attempting to start the video stream.");
            }
        });
    }

    private void stopVideoStream() {
        SoloCameraApi.getApi(drone).stopVideoStream(new SimpleCommandListener() {
            @Override
            public void onSuccess() {
                showToast("Stopping video stream.");
                String text = "Start Stream";
                VideoStream.setText(text);
                Streaming = false;
            }
        });
    }
VideoStream = (Button) findViewById(R.id.video_stream);
        VideoStream.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (!Streaming) {
                    if (cameraView!= null) {
                        startVideoStream(new Surface(cameraView.getSurfaceTexture()));
                    }
                } else {
                    if (cameraView != null) {
                        stopVideoStream();
                    }
                }
            }
        });
cameraView = (TextureView) findViewById(R.id.cameraView);
        if (cameraView != null) {
            cameraView.setSurfaceTextureListener(new TextureView.SurfaceTextureListener() {
                @Override
                public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
                    VideoStream.setEnabled(true);
                }
                @Override
                public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {
                }
                @Override
                public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
                    VideoStream.setEnabled(false);
                    return true;
                }
                @Override
                public void onSurfaceTextureUpdated(SurfaceTexture surface) {
                }
            });
        }
(I don't know why it doesn't put it all as code. Maybe someone can tell me please :) )
chaviw
@chaviw
Jul 18 2016 16:22
@pablomar13 Try putting it in all three single quotes on separate lines before and after
```
code
```
pablomar13
@pablomar13
Jul 18 2016 16:24
@chaviw yup. It works. Thanks
pablomar13
@pablomar13
Jul 18 2016 20:24
@ne0fhyk is there any knows issues with the Takeoff method??
public void takeoff() {
        final int altitude = 10; // in meters
        ControlApi.getApi(drone).takeoff(altitude, new AbstractCommandListener() {
            @Override
            public void onSuccess() {
                showToast(String.format(Locale.CANADA,"Taking off to %d meters...", altitude));
            }
            @Override
            public void onError(int executionError) {
                showToast("(!)Unable to take off.");
                SetupButton.setEnabled(true);
            }
            @Override
            public void onTimeout() {
                showToast("(!)Unable to take off.");
                SetupButton.setEnabled(true);
            }
        });
    }
Drone hovered at half meter instead of taking off to 10 meters. Do I have to keep check that it gets to 10 m before continuing my thread?
Fredia Huya-Kouadio
@ne0fhyk
Jul 18 2016 20:57
@pablomar13 yea, the onSuccess() callback only signals that the command is being executed by the drone.
@pablomar13 you have to monitor the drone altitude through the altitude telemetry events, and continue your logic when the drone altitude reaches 10m
pablomar13
@pablomar13
Jul 18 2016 21:02
@ne0fhyk ok thanks a lot!
pablomar13
@pablomar13
Jul 18 2016 22:14
@ne0fhyk Better to run them as a Runnable then?