Menu

Drone not Responding to Video Changes

John Sno
2017-05-11
2017-06-29
  • John Sno

    John Sno - 2017-05-11

    Hi Phillip,

    For some reason, my drone does not seem to be responding to changes in video settings.

    For example, when I tell it to use the ground camera, it doesnt. Or, if I set fps to 2, it stays the same.

    Here is a snippet of my code:

    CDC = drone.ConfigDataCount
    drone.setConfigAllID()
    drone.videoFPS(2)
    drone.groundCam()
    while CDC == drone.ConfigDataCount: time.sleep(0.01)

    drone.startVideo()
    print "video"
    IMC = drone.VideoImageCount
    while drone.VideoImageCount == IMC: time.sleep(0.01)
    IMC = drone.VideoImageCount

    Hopefully the issue is with my code.

    You also mention in the Documentation that there is a bug where the drone doesnt respond. Could this be it?

    Thanks,
    JonSno

     
  • PS-Drone

    PS-Drone - 2017-05-14

    Hello John,

    I confess, I was not able to recreate your problem. So far your code looks fine, maybe it depends on a missing command at the previous part.

    Anyway, here is a code, which worked for me, I hope it will help you:

    import time, sys
    import ps_drone
    drone = ps_drone.Drone()
    drone.startup()
    drone.reset()
    while (drone.getBattery()[0] == -1): time.sleep(0.1)
    print "Battery: "+str(drone.getBattery()[0])+"% "+str(drone.getBattery()[1])
    drone.useDemoMode(True)
    drone.setConfigAllID()
    drone.sdVideo()
    drone.groundCam()
    drone.videoFPS(2)
    CDC = drone.ConfigDataCount
    while CDC == drone.ConfigDataCount: time.sleep(0.0001)
    drone.startVideo()
    drone.showVideo()
    IMC = drone.VideoImageCount
    stop = False
    while not stop:
    key = drone.getKey()
    if key and key != " ": stop = True

    The bug in the drones firmware (seen at version 2.2.8) I mentioned in the documentation “overhears” sometimes (around 1%-3%) a command to switch the cameras. Resend the command and it will work.

    Have a great day,
    Philipp

     
  • Tim Murphy

    Tim Murphy - 2017-06-29

    Hi Philipp (or John),
    I tried the code above and it seems to run ok - when I hit any key (other than space), it terminates as expected. However, I can see no video. This may be a stupid question - how should the video display? Should the call to drone.showVideo() launch a window that shows the video? If it should, it doesn't for me. Any help you can give me would be gratefully accepted.

    Regards,
    Tim

     
  • PS-Drone

    PS-Drone - 2017-06-30

    Hi Tim,

    seems something went wrong with your installation of OpenCV.
    You mentioned in an other thread, you are running Ubuntu 17.4, so I tested it with this OS, too.
    Just (re-)install the python-opencv-package by typing

    sudo apt-get install python-opencv

    and the video-function will work.
    I attached a screenshot, so you can see how firstVideo.py should look like ;-)

    Have a great day,
    Philipp

     

    Last edit: PS-Drone 2017-06-30
  • Tim Murphy

    Tim Murphy - 2017-07-04

    Thank you Phillip,
    I tried this but it made no difference.

    This Ubuntu 17.04 was a dual-boot O/S on my laptop (installed along with Windows 10). Apart from the problem outlined above, there is unreliable wifi on this Ubuntu 17.04 installation.
    Because of both of these problems, I decided to install ubuntu as a virtual installation on my Windows 10. I used Oracle VM VirtualBox and Ubuntu 16.04. After installation, the steps/commands I used are below. I would appreciate (when you have time) to look at what I did and see if you can find any errors/issues.

    *sudo add-apt-repository ppa:pinta-maintainers/pinta-stable
    sudo apt-get update

    sudo apt-get install build-essential
    wget http://ftp.gnu.org/gnu/bash/bash-4.4.tar.gz
    tar xf bash-4.4.tar.gz
    cd bash-4.4
    ./configure
    make
    sudo make install

    cd ..
    bash /home/tim/Downloads/Anaconda2-4.4.0-Linux-x8664.sh
    sudo apt install spyder
    export PATH=~/anaconda2/bin:$PATH
    conda updata conda
    conda update spyder
    conda create --name ann2 python=2
    source activate ann2

    conda install -c menpo opencv=2.4.11

    cd PSDrone/
    python useVideoDebug.py *

    I then tried to run my debug version of your useVideo.py script. The output is below:
    (ann2) server@tim-ubuntu:~/SimpleCV/PSDrone$ python useVideoDebug.py
    DEBUG: STARTING
    DEBUG: STARTUP DONE
    Battery: 85% OK
    DEBUG: CALLED ConfigDataCount - WAITING 'until it is done...'
    DEBUG: DONE - STARTING VIDEO
    DEBUG: VIDEO STARTED
    DEBUG: IN 'while not stop:', ABOUT TO ENTER 'while drone.VideoImageCount==IMC' LOOP - IMC=0

    My debug version of your script is given below:
    *##### Suggested clean drone startup sequence #####
    import time, sys
    import psdrone # Import PS-Drone-API
    import cv2 # Import OpenCV

    print "DEBUG: STARTING"
    drone = psdrone.Drone() # Start using drone
    drone.startup() # Connects to drone and starts subprocesses
    print "DEBUG: STARTUP DONE"

    drone.reset() # Sets drone's status to good (LEDs turn green when red)
    while (drone.getBattery()[0]==-1): time.sleep(0.1) # Waits until drone has done its reset
    print "Battery: "+str(drone.getBattery()[0])+"% "+str(drone.getBattery()[1]) # Gives battery-status
    drone.useDemoMode(True) # Just give me 15 basic dataset per second (is default anyway)

    Mainprogram begin

    drone.setConfigAllID() # Go to multiconfiguration-mode
    drone.sdVideo() # Choose lower resolution (hdVideo() for...well, guess it)
    drone.frontCam() # Choose front view
    CDC = drone.ConfigDataCount
    print "DEBUG: CALLED ConfigDataCount - WAITING 'until it is done...'"
    while CDC == drone.ConfigDataCount: time.sleep(0.0001) # Wait until done (after resync done)
    print "DEBUG: DONE - STARTING VIDEO"
    drone.startVideo() # Start video-function
    print "DEBUG: VIDEO STARTED"

    And action !

    IMC = drone.VideoImageCount # Number of encoded videoframes
    stop = False
    while not stop:
    print "IMC="+str(IMC)
    print "DEBUG: IN 'while not stop:', ABOUT TO ENTER 'while drone.VideoImageCount==IMC' LOOP"
    while drone.VideoImageCount==IMC: time.sleep(0.01) # Wait until the next video-frame
    IMC = drone.VideoImageCount
    print "DEBUG: IMC="+str(IMC)
    key = drone.getKey()
    if key: stop = True
    print "DEBUG: GETTING IMAGE"
    img = drone.VideoImage # Copy video-image
    print "DEBUG: GOT IMAGE - RESIZING"
    pImg = cv2.resize(img,(400,100)) # Process video-image
    print "DEBUG: IMAGE RESIZED - SHOWING"
    cv2.imshow('Drones video',pImg) # Show processed video-image
    print "DEBUG: YOU SHOULD SEE AN IMAGE NOW"
    cv2.waitKey(1) # OpenCV for Linux has a bug and needs this line*

     
  • PS-Drone

    PS-Drone - 2017-07-05

    Hi Tim,

    VirtualBox is great, I use it a lot, too.

    You should really give Mint a chance (I prefer MATE-edition). The look and feel is amazing; the standard-installation is also pretty good and everything works out of the box:
    https://www.linuxmint.com/download.php

    Anyway, as far as I can see, everything should be OK, but the python-openCV-interface is missing. Try: sudo apt-get install python-opencv
    It was also the only package I had to install while testing PS-Drone on Ubuntu 17.04.
    I also suggest to install synaptic (sudo apt-get install synaptic), it’s a useful packet-manager, but not included in Ubuntu.

    If firstVideo.py shows an image, everything works fine.

    Best wishes and have success,
    Philipp

     
  • Tim Murphy

    Tim Murphy - 2017-07-08

    Thanks Philipp,
    I left this issue to deal with other project work and returned to it yesterday. I went back to my Ubuntu installation and tried the code again and as if by magic it now worked. I didn't make any changes - It seems that a system reboot can work wonders sometimes. I now have video every time.

    Thanks for all your help and support. I will try LinuxMint too now that I have a virtualbox.

    Regards,
    Tim

     

Log in to post a comment.

MongoDB Logo MongoDB