예제 #1
0
def test_Example():
    with pytest.raises(NotImplementedError):
        _ = Bond.function_classes()

    ret = Example.function_classes()

    assert isinstance(ret, set)

    b = Bebop()

    with pytest.raises(KeyError):
        assert b.opcode['pic_all_as_pat'].ret_type == Block.type_pattern

    for abs_class in ret:
        b.use(abs_class)

    assert b.opcode['pic_all_as_pat'].ret_type == Block.type_pattern
    assert len(b.opcode['2pat_merge_as_pic'].arg_types) == 2
    assert b.opcode['pat_flip_up_down'].ret_type == Block.type_pattern
    assert len(b.opcode['tests_verify_answer'].arg_types) == 1

    ret = Example.from_kind()

    assert ret == Question

    ret = Example.to_kind()

    assert ret == Answer
예제 #2
0
	def __init__(self, abstract_relation):
		Bebop.__init__(self)

		self.from_kind = abstract_relation.from_kind()
		self.to_kind   = abstract_relation.to_kind()

		self.rex_tuple	 = re.compile('^\\(.+\\)$')
		self.rex_picture = re.compile('^\\[\\[.+\\]\\]$')
		self.rex_vector	 = re.compile('^\\[[^\\[]+\\]$')

		for abs_class in abstract_relation.function_classes():
			self.use(abs_class)
예제 #3
0
def test_Bebop():
    b = Bebop()

    assert isinstance(b, Bebop)
    assert Bebop.__base__ == object

    with pytest.raises(KeyError):
        b.use(Bebop)

    b = Bebop()

    code = Code((b.opcode['swap_top2'], ))
    core = Core(code, stack=[Block.new_integer(19), Block.new_integer(21)])

    assert core.all_right
    assert core.stack[-1].data == 21

    ret, = core

    assert core.all_right
    assert core.stack[-1].data == 19

    assert isinstance(ret, Block)
    assert ret.type == Block.type_integer
    assert ret.data == 19

    core = Core(code)

    ret, = core

    assert core.all_right is False
    assert core.error_msg == 'swap_top2() with less than two'

    assert isinstance(ret, Block)
    assert ret.type == Block.type_error
    assert ret.data == 'swap_top2() with less than two'

    code = Code((b.opcode['get_answer'], ))
    core = Core(code)

    core.register['answer'] = Block.new_integer(37)

    ret, = core

    assert core.all_right
    assert core.stack[-1].data == 37

    assert isinstance(ret, Block)
    assert ret.type == Block.type_integer
    assert ret.data == 37
예제 #4
0
                        default=5, help='Size of the queue.')
    args = parser.parse_args()

    logger = multiprocessing.log_to_stderr()
    logger.setLevel(multiprocessing.SUBDEBUG)

    input_q = Queue(maxsize=args.queue_size)
    output_q = Queue(maxsize=args.queue_size)
    pool = Pool(args.num_workers, worker, (input_q, output_q))
    #
    # video_capture = WebcamVideoStream(src=args.video_source,
    #                                   width=args.width,
    #                                   height=args.height).start()
    # fps = FPS().start()

    isAlive = False
    bebop = Bebop()
    success = bebop.connect(5)
    print("Drone Initialized " + str(success))
    if success:
        bebopVision = DroneVisionGUI(bebop, is_bebop=True)
    else:
        print("Error: Bebop not found")
    # fps.stop()
    # print('[INFO] elapsed time (total): {:.2f}'.format(fps.elapsed()))
    # print('[INFO] approx. FPS: {:.2f}'.format(fps.fps()))

    pool.terminate()
    video_capture.stop()
    cv2.destroyAllWindows()
예제 #5
0
        bebop.smart_sleep(5)

        # land
        bebop.safe_land(5)

        print("Finishing demo and stopping vision")
        bebopVision.close_video()

    # disconnect nicely so we don't need a reboot
    print("disconnecting")
    bebop.disconnect()


if __name__ == "__main__":
    # make my bebop object
    bebop = Bebop()

    # connect to the bebop
    success = bebop.connect(5)

    if (success):
        # start up the video
        bebopVision = DroneVisionGUI(
            bebop,
            is_bebop=True,
            user_code_to_run=demo_user_code_after_vision_opened,
            user_args=(bebop, ))

        userVision = UserVision(bebopVision)
        bebopVision.set_user_callback_function(userVision.save_pictures,
                                               user_callback_args=None)
예제 #6
0
"""
Demo the Bebop indoors (takes off, turns about 90 degrees, lands)
Note, the bebop will hurt your furniture if it hits it.  Be sure you are doing this in an open area
and are prepared to catch!
"""

from Bebop import Bebop

bebop = Bebop()

print("connecting")
success = bebop.connect(10)
print(success)

if (success):
    print("turning on the video")
    bebop.start_video_stream()

    print("sleeping")
    bebop.smart_sleep(2)

    bebop.ask_for_state_update()

    #bebop.safe_takeoff(10)

    print("Flying direct: yaw SLOWLY for indoors")
    #bebop.fly_direct(roll=0, pitch=0, yaw=40, vertical_movement=0, duration=1)

    bebop.smart_sleep(5)
    #bebop.safe_land(10)
예제 #7
0
                          fill=(255, 255, 255, 255))

            # Remove the drawing library from memory as per the Pillow docs
            del draw

            # Display the resulting image
            # pil_image.show()

            # You can also save a copy of the new image to disk if you want by uncommenting this line
            pil_image.save(
                "C:/Users/nickm/Desktop/image_{0:0=3d}.png".format(i))


# -------
# make my bebop object
bebop = Bebop()
bebop.set_video_stream_mode('high_reliability')
# safely initialize control var
bebop.ready = True
# connect to the bebop
success = bebop.connect(5)

if success:
    # start up the video
    bebopVision = DroneVision(bebop, is_bebop=True)
    userVision = UserVision(bebopVision)
    bebopVision.set_user_callback_function(userVision.face_detect,
                                           user_callback_args=None)
    success = bebopVision.open_video()

    try:
예제 #8
0
"""
Flies the bebop in a fairly wide arc.  You want to be sure you have room for this. (it is commented
out but even what is here is still going to require a large space)
"""
from Bebop import Bebop

bebop = Bebop()

print("connecting")
success = bebop.connect(10)
print(success)

print("sleeping")
bebop.smart_sleep(5)
bebop.ask_for_state_update()
bebop.start_video_stream()
bebop.set_video_stream_mode('low_latency')
bebop.set_video_stream_resolutions('rec1080_stream480')
bebop.set_vide_stream_framerate('30_FPS')

bebop.smart_sleep(120)
bebop.stop_video_stream()
print("DONE - disconnecting")
bebop.disconnect()
예제 #9
0
from Bebop import Bebop

bebop = Bebop()

print("connecting")
success = bebop.connect(10)
print(success)

print("sleeping")
bebop.smart_sleep(5)

bebop.ask_for_state_update()

bebop.safe_takeoff(10)

print("flip left")
print("flying state is %s" % bebop.sensors.flying_state)
success = bebop.flip(direction="left")
print("mambo flip result %s" % success)
bebop.smart_sleep(5)

print("flip right")
print("flying state is %s" % bebop.sensors.flying_state)
success = bebop.flip(direction="right")
print("mambo flip result %s" % success)
bebop.smart_sleep(5)

print("flip front")
print("flying state is %s" % bebop.sensors.flying_state)
success = bebop.flip(direction="front")
print("mambo flip result %s" % success)
예제 #10
0
class uavBebop:
    """A simple example class"""
    with_drone = False
    bebop = Bebop()
    timeout = 5
    speed_factor = 1
    print_trace = True

    def connect(self):
        if self.with_drone:
            return self.bebop.connect(10)
        else:
            print(
                "No connection because you are in 'no drone' mode. Call allow_flight()"
            )

    def disconnect(self):
        if self.with_drone:
            return self.bebop.disconnect()

    def arm(self):
        print("TODO : arming")

    def disarm(self):
        print("TODO : disarming")

    def takeoff(self):
        self.debug("Going to takeoff")
        if self.with_drone: self.bebop.safe_takeoff(self.timeout)

    def land(self):
        self.debug("Going to land")
        if self.with_drone: self.bebop.safe_land(self.timeout)

    def roll(self, speed, distance):
        self.debug("Going to roll {} for {}".format(speed, distance))
        if self.with_drone:
            self.bebop.fly_direct(roll=speed * self.speed_factor,
                                  pitch=0,
                                  yaw=0,
                                  vertical_movement=0,
                                  duration=distance)

    def pitch(self, speed, distance):
        if self.with_drone:
            self.bebop.fly_direct(roll=0,
                                  pitch=speed * self.speed_factor,
                                  yaw=0,
                                  vertical_movement=0,
                                  duration=distance)

    def yaw(self, speed, distance):
        if self.with_drone:
            self.bebop.fly_direct(roll=0,
                                  pitch=0,
                                  yaw=speed * self.speed_factor,
                                  vertical_movement=0,
                                  duration=distance)

    def throttle(self, speed, distance):
        if self.with_drone:
            self.bebop.fly_direct(roll=0,
                                  pitch=0,
                                  yaw=0,
                                  vertical_movement=speed * self.speed_factor,
                                  duration=distance)

    def stop(self):
        if self.with_drone:
            self.bebop.fly_direct(roll=0,
                                  pitch=0,
                                  yaw=0,
                                  vertical_movement=0,
                                  duration=distance)

    def return_to_launch(self):
        print("ERROR : RTL Not implemented.")

    def test_move(self):
        if self.with_drone:
            distance = 1
            self.roll(-10, distance)
            self.throttle(10, distance)
            self.pitch(10, distance)
            self.roll(10, distance)
            self.throttle(-10, distance)
            self.pitch(-10, distance)

    def allow_flight(self):
        self.with_drone = True

    def set_speed_factor(self, speed_factor):
        self.speed_factor = speed_factor

    def debug(self, msg):
        if self.print_trace:
            print(msg)
예제 #11
0
def test_instance_everything():
	a = Answer([[1, 0], [0, 1]])
	assert isinstance(a, Answer)
	assert Answer.__base__ == Block
	with pytest.raises(AttributeError):
		_ = a.__base__

	a = Bebop()
	assert isinstance(a, Bebop)
	assert Bebop.__base__ == object
	with pytest.raises(AttributeError):
		_ = a.__base__

	a = Block('hello', Block.type_error)
	assert isinstance(a, Block)
	assert Block.__base__ == object
	with pytest.raises(AttributeError):
		_ = a.__base__

	a = Bond(None, None)
	assert isinstance(a, Bond)
	assert Bond.__base__ == Block
	with pytest.raises(AttributeError):
		_ = a.__base__

	a = BopBack()
	assert isinstance(a, BopBack)
	assert BopBack.__base__ == object
	with pytest.raises(AttributeError):
		_ = a.__base__

	a = BopForward()
	assert isinstance(a, BopForward)
	assert BopForward.__base__ == object
	with pytest.raises(AttributeError):
		_ = a.__base__

	a = Code((Function(len, [Block.type_picture], Block.type_picture), Function(len, [Block.type_picture], Block.type_picture)))
	assert isinstance(a, Code)
	assert Code.__base__ == Block
	with pytest.raises(AttributeError):
		_ = a.__base__

	code = a

	a = CodeBase()
	assert isinstance(a, CodeBase)
	assert CodeBase.__base__ == Container
	with pytest.raises(AttributeError):
		_ = a.__base__

	a = CodeEval(Example)
	assert isinstance(a, CodeEval)
	assert CodeEval.__base__ == Field
	with pytest.raises(AttributeError):
		_ = a.__base__

	a = CodeGen(None, None, Example)
	assert isinstance(a, CodeGen)
	assert CodeGen.__base__ == CodeTree
	with pytest.raises(AttributeError):
		_ = a.__base__

	a = CodeTree(None, Example)
	assert isinstance(a, CodeTree)
	assert CodeTree.__base__ == CodeEval
	with pytest.raises(AttributeError):
		_ = a.__base__

	a = Core(code, [Block.new_picture(list_of_list=[[3, 2], [2, 3]])])
	assert isinstance(a, Core)
	assert Core.__base__ == Block
	with pytest.raises(AttributeError):
		_ = a.__base__

	a = Container()
	assert isinstance(a, Container)
	assert Container.__base__ == object
	with pytest.raises(AttributeError):
		_ = a.__base__

	a = Context()
	assert isinstance(a, Context)
	assert Context.__base__ == Container
	with pytest.raises(AttributeError):
		_ = a.__base__

	a = Example([[3, 2], [2, 3]], [[1, 0], [0, 1]], False)
	assert isinstance(a, Example)
	assert Example.__base__ == Bond
	with pytest.raises(AttributeError):
		_ = a.__base__

	a = Field(Example)
	assert isinstance(a, Field)
	assert Field.__base__ == Bebop
	with pytest.raises(AttributeError):
		_ = a.__base__

	a = Function(len, Block.type_nothing, Block.type_nothing)
	assert isinstance(a, Function)
	assert Function.__base__ == Block
	with pytest.raises(AttributeError):
		_ = a.__base__

	a = MCTS(None, None, Example)
	assert isinstance(a, MCTS)
	assert MCTS.__base__ == CodeGen
	with pytest.raises(AttributeError):
		_ = a.__base__

	a = MctsNode()
	assert isinstance(a, MctsNode)
	assert MctsNode.__base__ == object
	with pytest.raises(AttributeError):
		_ = a.__base__

	a = Problem()
	assert isinstance(a, Problem)
	assert Problem.__base__ == Container
	with pytest.raises(AttributeError):
		_ = a.__base__

	a = Question([[3, 2], [2, 3]])
	assert isinstance(a, Question)
	assert Question.__base__ == Block
	with pytest.raises(AttributeError):
		_ = a.__base__

	a = Search()
	assert isinstance(a, Search)
	assert Search.__base__ == object
	with pytest.raises(AttributeError):
		_ = a.__base__

	a = Source(('nop'))
	assert isinstance(a, Source)
	assert Source.__base__ == Block
	with pytest.raises(AttributeError):
		_ = a.__base__
예제 #12
0
import sys
import os.path
from controlGUI import *
from PyQt5.QtCore import QObject, pyqtSlot, QUrl
import sys
import os.path
from PyQt5.QtWidgets import QMainWindow, QWidget, QFrame, QSlider, QHBoxLayout, QPushButton, \
    QVBoxLayout, QAction, QFileDialog, QApplication
import vlc
from controlGUI import DroneGUI
from Bebop import Bebop

if __name__ == "__main__":
    bebop = Bebop()
    app = QApplication(sys.argv)
    vision = DroneGUI()
    vision.setDrone(bebop)
    bebop.setVision(vision)
    vision.show()
    vision.resize(995, 720)
    sys.exit(app.exec_())
예제 #13
0
"""
Flies the bebop in a fairly wide arc.  You want to be sure you have room for this. (it is commented
out but even what is here is still going to require a large space)
"""
from Bebop import Bebop

bebop = Bebop()

print("connecting")
success = bebop.connect(10)
print(success)

print("sleeping")
bebop.smart_sleep(5)
bebop.ask_for_state_update()

bebop.safe_takeoff(10)

print("Flying direct: going forward (positive pitch)")
bebop.fly_direct(roll=0, pitch=50, yaw=0, vertical_movement=0, duration=1)

print("Flying direct: yaw")
bebop.fly_direct(roll=0, pitch=0, yaw=50, vertical_movement=0, duration=1)

print("Flying direct: going backwards (negative pitch)")
bebop.fly_direct(roll=0, pitch=-50, yaw=0, vertical_movement=0, duration=0.5)

print("Flying direct: roll")
bebop.fly_direct(roll=50, pitch=0, yaw=0, vertical_movement=0, duration=1)

print("Flying direct: going up")
예제 #14
0
class UserVision:
    def __init__(self, vision):
        self.index = 0
        self.vision = vision

    def save_pictures(self, args):
        #print("saving picture")
        img = self.vision.get_latest_valid_picture()

        filename = "test_image_%06d.png" % self.index
        #cv2.imwrite(filename, img)
        self.index += 1


# make my bebop object
bebop = Bebop()

# connect to the bebop
success = bebop.connect(5)

if (success):
    # start up the video
    bebopVision = DroneVision(bebop, is_bebop=True)

    userVision = UserVision(bebopVision)
    bebopVision.set_user_callback_function(userVision.save_pictures,
                                           user_callback_args=None)
    success = bebopVision.open_video()

    if (success):
        print("Vision successfully started!")
예제 #15
0
# from __future__ import print_function
# from dronekit import connect, VehicleMode, LocationGlobal, LocationGlobalRelative
# from pymavlink import mavutil # Needed for command message definitions
import time
import math
from Bebop import Bebop
# from pynput.keyboard import Controller
# # import time
#
bebop = Bebop()
def move(offset_x, offset_y, offset_z=0, time):
    # keyboard = Controller()
    # print(offset_x, offset_y)
    ''' text_file = open("buffer.txt", "w")

    target_y = 1
    target_x = 0
    if offset_y - target_y > 0:
        text_file.write("s")

    elif offset_y - target_y < 0:
        text_file.write("w")


    if offset_x - target_x > 0:
        text_file.write("a")
    elif offset_x - target_x < 0:
        text_file.write("d") '''
        bebop.fly_direct(roll=(100 * offset_y / abs(offset_y)), pitch=(100 * offset_x / abs(offset_x)), yaw=0, vertical_movement=(50 * offset_z/ abs(offset_z)), duration=time // 2)

def turn(direction, time):
예제 #16
0
    args = parser.parse_args()

    logger = multiprocessing.log_to_stderr()
    logger.setLevel(multiprocessing.SUBDEBUG)

    input_q = Queue(maxsize=args.queue_size)
    output_q = Queue(maxsize=args.queue_size)
    pool = Pool(args.num_workers, worker, (input_q, output_q))
    #
    # video_capture = WebcamVideoStream(src=args.video_source,
    #                                   width=args.width,
    #                                   height=args.height).start()
    # fps = FPS().start()

    isAlive = False
    bebop = Bebop()
    success = bebop.connect(5)
    count = 0
    print("Drone Initialized " + str(success))
    if success:
        bebopVision = DroneVision(bebop, is_bebop=True)

        userVision = UserVision(bebopVision)
        bebopVision.set_user_callback_function(userVision.save_pictures,
                                               user_callback_args=None)
        success = bebopVision.open_video()
        bebop.safe_takeoff(10)
        bebop.smart_sleep(30)
        ("Take off")
        while True and success and count < 30:  # fps._numFrames < 120
            frame = userVision.vision.get_latest_valid_picture()
예제 #17
0
    logger = multiprocessing.log_to_stderr()
    logger.setLevel(multiprocessing.SUBDEBUG)

    input_q = Queue(maxsize=args.queue_size)
    output_q = Queue(maxsize=args.queue_size)
    pool = Pool(args.num_workers, worker, (input_q, output_q))
    input_q.put(np.zeros((640,480,3)))
    #
    video_capture = WebcamVideoStream(src=args.video_source,
                                      width=args.width,
                                      height=args.height).start()
    print("CAM" + str(type(video_capture)))
    # fps = FPS().start()

    isAlive = False
    bebop = Bebop()
    success = bebop.connect(5)
    print("Drone Initialized " + str(success))
    if success:
        bebopVision = DroneVision(bebop, is_bebop=True)#, user_code_to_run=detection, user_args='')
        userVision = UserVision(bebopVision)
        bebopVision.set_user_callback_function(userVision.save_pictures, user_callback_args=None)
        success = bebopVision.open_video()
        # bebop.safe_takeoff(10)
        bebop.smart_sleep(10)
        ("Take off")
        count = 0

        while True and success and count < 50:  # fps._numFrames < 120
            frame = userVision.vision.get_latest_valid_picture()
            input_q.put(frame)