Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
demo.py - first step towards integration (single threaded)
- Loading branch information
martind
committed
Mar 2, 2015
1 parent
416670d
commit abcff79
Showing
4 changed files
with
109 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#!/usr/bin/python | ||
""" | ||
ARDrone3 demo with autonomous navigation to two color Parrot Cap | ||
usage: | ||
./demo.py <task> [<metalog> [<F>]] | ||
""" | ||
import sys | ||
import cv2 | ||
|
||
from bebop import Bebop | ||
from video import VideoFrames | ||
from capdet import detectTwoColors, loadColors | ||
|
||
# this will be in new separate repository as common library fo robotika Python-powered robots | ||
from apyros.metalog import MetaLog, disableAsserts | ||
from apyros.manual import myKbhit, ManualControlException | ||
|
||
TMP_VIDEO_FILE = "video.bin" | ||
|
||
|
||
g_vf = None | ||
|
||
def videoCallback( data ): | ||
global g_vf | ||
g_vf.append( data ) | ||
frame = g_vf.getFrame() | ||
if frame: | ||
print "Video", len(frame) | ||
# workaround for a single frame | ||
f = open( TMP_VIDEO_FILE, "wb" ) | ||
f.write( frame ) | ||
f.close() | ||
cap = cv2.VideoCapture( TMP_VIDEO_FILE ) | ||
ret, img = cap.read() | ||
cap.release() | ||
if ret: | ||
img, detected = detectTwoColors( img, loadColors("cap-colors.txt") ) | ||
print "Detected", detected | ||
# cv2.imshow('image', img) | ||
# key = cv2.waitKey(10) | ||
|
||
|
||
|
||
def demo( drone ): | ||
print "Follow 2-color cap ..." | ||
global g_vf | ||
g_vf = VideoFrames( onlyIFrames=True, verbose=False ) | ||
drone.videoCbk = videoCallback | ||
drone.videoEnable() | ||
for i in xrange(100): | ||
print i, | ||
drone.update( cmd=None ) | ||
|
||
if __name__ == "__main__": | ||
if len(sys.argv) < 2: | ||
print __doc__ | ||
sys.exit(2) | ||
metalog=None | ||
if len(sys.argv) > 2: | ||
metalog = MetaLog( filename=sys.argv[2] ) | ||
if len(sys.argv) > 3 and sys.argv[3] == 'F': | ||
disableAsserts() | ||
|
||
drone = Bebop( metalog=metalog ) | ||
demo( drone ) | ||
print "Battery:", drone.battery | ||
|
||
# vim: expandtab sw=4 ts=4 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters