Example #1
0
    def __init__(self, parent):
        gui.MyFrame1.__init__(self, parent)
        self.statusBar.SetStatusWidths([100, -1])
        self.statusBar.SetStatusText('Not Connected')
        self.lc_commands.InsertColumn(0, 'command', width=300)
        self.bebop = Bebop()

        # load saved commands from file
        self._loadJsonFile()
Example #2
0
	def start(self):
		'''开始函数'''
		#初始化飞机对象
		self.bebop = Bebop()
		#连接飞机  
		print("connecting")
		self.success = self.bebop.connect(10)  #与飞机进行连接(最大尝试次数为10次)
		if self.success == True: 
			print("sleeping")  
			self.bebop.smart_sleep(5)
			self.bebop.ask_for_state_update()   #获取飞机的状态
			if self.indoorFlyFlag == True:
				self.setIndoorFly()
				print("set indoor fly sucess!!!")
			print("The aircraft was successfully initialized!")
			self.startSuccessFlag = True   #开始成功

		else:
			print("The connection failed. Please check again!")
			self.startSuccessFlag = False   #开始失败
		self.removeExitFile()
def main():
    bebop2 = Bebop()
    bebop1 = Bebop(drone_type="Bebop")
    mac = None  # ToDo
    mambo = Mambo(mac, use_wifi=True)
    #swing = Swing(mac)
    drone_list = [bebop2, bebop1, mambo]
    for drone in drone_list:
        print("Trying to connect to %s drone..." % 'TODO')
        success = drone.connect(
            10)  # attempts to connect to the drone, success is Boolean
        if success:
            print("Successfully Connected to drone!")
            print("Sleeping")
            drone.smart_sleep(3)
            print("Ready!")
            drone.ask_for_state_update()

            controller(drone)

    print("Could not connect to a drone.")
 def __init__(self, home):
     self.rango_largo = properties.RANGO_LARGO
     self.rango_ancho = properties.RANGO_ANCHO
     self.mapa_largo = properties.MAPA_LARGO / self.rango_largo
     self.mapa_ancho = properties.MAPA_ANCHO / self.rango_ancho
     self.search_map = [[0 for j in range(int(self.mapa_largo))]
                        for i in range(int(self.mapa_ancho))]
     self.home = home
     self.current_position = home
     self.battery_status = NORMAL
     self.mutex_search_map = threading.Lock()
     self.bebop = Bebop()
     self.initialize()
Example #5
0
def face_tracking(droneVision:DroneVisionGUI,bebop:Bebop):
    face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')

    cv2.namedWindow("face_tracking")

    frame = droneVision.get_latest_valid_picture()

    while cv2.getWindowProperty('face_tracking', 0) >= 0:
        frame = droneVision.get_latest_valid_picture()
        gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
        faces = face_cascade.detectMultiScale(gray, 1.3, 5)
        (x,y,w,h) = None, None, None, None
        if len(faces) > 0:
            (x,y,w,h) = faces[0]
            cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 255), 1)
            print("Face Size: "+ str(w*h))

        backup_threshold = 3600
        fwd_threshold = 2000

        if w is not None and w*h > backup_threshold:
            print("GOING BACK")
            bebop.fly_direct(roll=0,pitch=-20,yaw=0,vertical_movement=0,duration=0.1)
        elif w is not None and w*h < fwd_threshold:
            print("GOING FORWARD")
            bebop.fly_direct(roll=0, pitch=20, yaw=0, vertical_movement=0, duration=0.1)

        if x is not None and x+(w/2.0) > 650:
            print("GOING RIGHT")
            bebop.fly_direct(roll=0,pitch=0,yaw=70,vertical_movement=0,duration=0.1)
        elif x is not None and x+(w/2.0) < 200:
            print("GOING LEFT")
            bebop.fly_direct(roll=0, pitch=0, yaw=-70, vertical_movement=0, duration=0.1)

        cv2.imshow("face_tracking",frame)
        cv2.waitKey(10)

    bebop.safe_land(10)
    cv2.destroyAllWindows()
Example #6
0
 def __init__(self, home):
     self.rango_largo = properties.RANGO_LARGO
     self.rango_ancho = properties.RANGO_ANCHO
     self.mapa_largo = properties.MAPA_LARGO / self.rango_largo
     self.mapa_ancho = properties.MAPA_ANCHO / self.rango_ancho
     self.ip = None
     self.port = None
     self.search_map = [[0 for j in range(int(self.mapa_largo))]for i in range(int(self.mapa_ancho))]
     self.current_position = home
     self.current_rotation = math.pi / 2
     self.mutex_search_map = threading.Lock()
     self.poi_position = None
     self.home = home
     self.bebop = Bebop()
     self.init_time = None
     self.obstaculos = properties.OBSTACLES
     self.max_altitude = properties.MAX_ALTITUDE
     self.pathToFollow = None
     self.destinationZone = None
     self.countIter = 0
     self.logMapTimestamp = None
     self.logMap = None
Example #7
0
    def __init__(self):
        super().__init__()

        self.bebop = Bebop()

        print("connecting to bebop drone")
        self.connection.emit("progress")
        self.success = self.bebop.connect(5)
        if self.success:
            self.connection.emit("on")
            self.bebop.set_max_altitude(20)
            self.bebop.set_max_distance(20)
            self.bebop.set_max_rotation_speed(180)
            self.bebop.set_max_vertical_speed(2)
            self.bebop.enable_geofence(1)
            self.bebop.set_hull_protection(1)

            # todo: battery signal to emit (look in sensors)
            #TODO test this piece of code
            self.bebop.set_user_sensor_callback(print,
                                                self.bebop.sensors.battery)
        else:
            print("refresh....")
            self.connection.emit("off")
Example #8
0
    # done doing vision demo
    print("Ending the sleep and vision")
    mamboVision.close_video()

    mambo.smart_sleep(5)

    print("disconnecting")
    mambo.disconnect()


if __name__ == "__main__":
    # make my mambo object
    # remember to set True/False for the wifi depending on if you are using the wifi or the BLE to connect
    # the address can be empty if you are using wifi
    mambo = Bebop()
    print("trying to connect to mambo now")

    success = mambo.connect(num_retries=3)
    print("connected: %s" % success)

    if (success):
        # get the state information
        print("sleeping")
        mambo.smart_sleep(1)
        mambo.ask_for_state_update()
        mambo.smart_sleep(1)

        # setup the extra window to draw the markers in
        cv2.namedWindow("ExampleWindow")
        cv2.namedWindow("dst")
Example #9
0
class myoBebop(object):

	def __init__(self , indoorFly = True):
		'''类初始化函数'''
		self.bebop = None 
		self.indoorFlyFlag = indoorFly
		self.actionType = "rest"   #当前的动作类型
		self.startSuccessFlag = False #初始化是否成功标志位
		self.takeOfFlag = False		#是否起飞标志位
		self.landFlag = True	#是否降落标志位
		self.startFlag = False	#程序开始标志位
		self.executeCommondFlag = True		#命令执行成功标志位
		#动作映射字典
		self.actionMapDict = {	"front"	: 	"fist"  , 	"back" 	:	 "open_hand" , 
								"left"	: 	"one" , 	"right" : 	 "two" ,
								"up"	:	"good",		"down"	:	 "low" ,
								"rotateLeft" : "three" ,  "rotateRight" : "four" , 
								"takeOf": 	"ok"  , 	"land" 	: 	 "love"}
		self.tempCount = 0   #计数
		self.excuteFlag1 = True   #读取动作类别标志位
		self.excuteFlag2 = True	  #读取按键值的标志位
		self.flyType = 0  #飞机飞行类别(0:正常飞行 , 1:特技飞行)
		self.moveStepTime = 1  #飞行器水平运行步长时间
		self.rotateStepTime = 1 #飞行器旋转运行步长时间

	def start(self):
		'''开始函数'''
		#初始化飞机对象
		self.bebop = Bebop()
		#连接飞机  
		print("connecting")
		self.success = self.bebop.connect(10)  #与飞机进行连接(最大尝试次数为10次)
		if self.success == True: 
			print("sleeping")  
			self.bebop.smart_sleep(5)
			self.bebop.ask_for_state_update()   #获取飞机的状态
			if self.indoorFlyFlag == True:
				self.setIndoorFly()
				print("set indoor fly sucess!!!")
			print("The aircraft was successfully initialized!")
			self.startSuccessFlag = True   #开始成功

		else:
			print("The connection failed. Please check again!")
			self.startSuccessFlag = False   #开始失败
		self.removeExitFile()


	def bebopFly(self , actionType):
		'''根据动作类别进行相应的动作'''
		if actionType == self.actionMapDict["front"]:   #向前飞
			self.executeCommondFlag = False   
			
			print("flying state is %s" % self.bebop.sensors.flying_state)
			if self.flyType == 0:
				self.bebop.fly_direct(roll=0, pitch=50, yaw=0, vertical_movement=0, duration=self.moveStepTime)
				print("fly front")
			elif self.flyType == 1:
				self.success = self.bebop.flip(direction="front")
				print("flip front")
				print("mambo flip result %s" % self.success)
				self.bebop.smart_sleep(5)
			self.executeCommondFlag = True

		elif actionType == self.actionMapDict["back"]:   #向后飞
			self.executeCommondFlag = False
			
			print("flying state is %s" % self.bebop.sensors.flying_state)
			if self.flyType == 0:
				self.bebop.fly_direct(roll=0, pitch=-50, yaw=0, vertical_movement=0, duration=self.moveStepTime)
				print("fly back")
			elif self.flyType == 1:
				self.success = self.bebop.flip(direction="back")
				print("flip back")
				print("mambo flip result %s" % self.success)
				self.bebop.smart_sleep(5)
			self.executeCommondFlag = True

		elif actionType == self.actionMapDict["left"]:   #左飞
			self.executeCommondFlag = False
			
			print("flying state is %s" % self.bebop.sensors.flying_state)
			if self.flyType == 0:
				self.bebop.fly_direct(roll=50, pitch=0, yaw=0, vertical_movement=0, duration=self.moveStepTime)
				print("fly left")
			elif self.flyType == 1:
				self.success = self.bebop.flip(direction="left")
				print("flip left")
				print("mambo flip result %s" % self.success)
				self.bebop.smart_sleep(5)
			self.executeCommondFlag = True

		elif actionType == self.actionMapDict["right"]:   #右飞
			self.executeCommondFlag = False
			
			print("flying state is %s" % self.bebop.sensors.flying_state)
			if self.flyType == 0:
				self.bebop.fly_direct(roll=-50, pitch=0, yaw=0, vertical_movement=0, duration=self.moveStepTime)
				print("fly right")
			elif self.flyType == 1:
				self.success = self.bebop.flip(direction="right")
				print("flip right")
				print("mambo flip result %s" % self.success)
				self.bebop.smart_sleep(5)
			self.executeCommondFlag = True

		elif actionType == self.actionMapDict["up"]:   #上飞
			self.executeCommondFlag = False
			print("flying state is %s" % self.bebop.sensors.flying_state)
			if self.flyType == 0:
				self.bebop.fly_direct(roll = 0, pitch = 0, yaw = 0, vertical_movement=50, duration = self.moveStepTime)
				print("fly up")
			elif self.flyType == 1:
				pass
			self.executeCommondFlag = True

		elif actionType == self.actionMapDict["down"]:   #下飞
			self.executeCommondFlag = False
			print("flying state is %s" % self.bebop.sensors.flying_state)
			if self.flyType == 0:
				self.bebop.fly_direct(roll = 0, pitch = 0, yaw = 0, vertical_movement= - 50, duration = self.moveStepTime)
				print("fly down")
			elif self.flyType == 1:
				pass
			self.executeCommondFlag = True

		elif actionType == self.actionMapDict["rotateLeft"]:   #向左旋转
			self.executeCommondFlag = False
			print("flying state is %s" % self.bebop.sensors.flying_state)
			if self.flyType == 0:
				self.bebop.fly_direct(roll=0, pitch=0, yaw=50, vertical_movement=0, duration=self.moveStepTime)
				print("fly rotateLeft")
			elif self.flyType == 1:
				pass
			self.executeCommondFlag = True

		elif actionType == self.actionMapDict["rotateRight"]:   #向右旋转
			self.executeCommondFlag = False
			print("flying state is %s" % self.bebop.sensors.flying_state)
			if self.flyType == 0:
				self.bebop.fly_direct(roll=0, pitch=0, yaw = -50, vertical_movement=0, duration=self.moveStepTime)
				print("fly rotateRight")
			elif self.flyType == 1:
				pass
			self.executeCommondFlag = True

		elif actionType == self.actionMapDict["takeOf"]: #起飞
			self.startFlag = True
			if self.landFlag == True:
				self.landFlag = False
				self.executeCommondFlag = False
				print("take of ")
				self.bebop.safe_takeoff(10)
				self.bebop.smart_sleep(5)
				self.executeCommondFlag = True
				self.takeOfFlag = True

		elif actionType == self.actionMapDict["land"]: #降落
			if self.takeOfFlag == True:
				self.takeOfFlag = False
				self.executeCommondFlag = False
				print("land ")
				self.bebop.safe_land(10)
				self.bebop.smart_sleep(5)
				self.landFlag = True
				self.executeCommondFlag = True
	#myo失去连接后,飞机自动着落		
	def safeAction(self):
		if self.startFlag == True:
			if self.flyType == 0:
				if self.tempCount > 100:
					self.bebop.safe_land(10)
					self.bebop.smart_sleep(5)
					print("DONE - disconnecting")
					self.bebop.disconnect()
					self.mThread.forcedStopThread()
			elif self.flyType == 1:
				if self.tempCount > 300:
					self.bebop.safe_land(10)
					self.bebop.smart_sleep(5)
					print("DONE - disconnecting")
					self.bebop.disconnect()
					self.mThread.forcedStopThread()

	def setTheActionMain(self):
		'''设置动作类别线程函数'''
		if self.excuteFlag1 == True:
			self.excuteFlag1 = False
			os.system("python2 myoMain.py")
			time.sleep(0.01)

	def removeExitFile(self , fileName = "actionTempData.dat" ):
		'''删除已经存在的文件'''
		if os.path.exists(fileName) == True:
			os.remove(fileName)

	def setIndoorFly(self):
		'''设置室内飞行的参数'''
		self.bebop.set_max_tilt(5)
		self.bebop.set_max_vertical_speed(1)

	def getKeyValueMain(self):
		'''获取按键值的线程函数'''
		if self.excuteFlag2 == True:
			self.excuteFlag2 = False
			os.system("python2 quit.py" ) 
			time.sleep(0.01)
	#按键退出函数
	def quitMain(self):
		print("quit")
		self.bebop.safe_land(10)
		self.bebop.smart_sleep(5)
		self.bebop.disconnect()
		self.mThread.forcedStopThread()

	def getTheActionMain(self):
		'''得到动作类别线程函数'''
		global quitFlag
		while True:
			self.actionType = getTheCurrentAction()
			getTheKeyValue()
			if quitFlag == True:
				self.quitMain()
			else:
				if self.actionType == None:
					self.tempCount += 1
				else:
					self.tempCount = 0
				self.safeAction()
				if self.executeCommondFlag == True:
					self.bebopFly(self.actionType)
				time.sleep(0.01)

	def run(self):
		'''运行主程序'''
		try:
			self.mThread = myThread()
			self.mThread.addThread('setTheActionMain' , self.setTheActionMain , 0)
			self.mThread.addThread('getTheActionMain' , self.getTheActionMain , 0)
			self.mThread.addThread('getKeyValueMain' , self.getKeyValueMain , 0)
			self.mThread.runThread()
		except KeyboardInterrupt:
			print("DONE")
			self.bebop.disconnect()
			self.mThread.forcedStopThread()
Example #10
0
from pyparrot.Bebop import Bebop
from geographiclib.geodesic import Geodesic
import geopy.distance

bebop = Bebop()

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

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

bebop.ask_for_state_update()

bebop.set_max_altitude(5)
bebop.set_max_distance(10)
bebop.enable_geofence(1)

#print("HomeChanged_longitude: " + str(bebop.sensors.sensors_dict["HomeChanged_longitude"]))
#print("HomeChanged_latitude: " + str(bebop.sensors.sensors_dict["HomeChanged_latitude"]))
#print("HomeChanged_altitude: " + str(bebop.sensors.sensors_dict["HomeChanged_altitude"]) + "\n\n")

print("First State Update: ")

Drone_1a_Lat = bebop.sensors.sensors_dict["GpsLocationChanged_latitude"]
print("GpsLocationChanged_latitude:  " +
      str(bebop.sensors.sensors_dict["GpsLocationChanged_latitude"]))
Drone_1a_Lon = bebop.sensors.sensors_dict["GpsLocationChanged_longitude"]
print("GpsLocationChanged_longitude: " +
      str(bebop.sensors.sensors_dict["GpsLocationChanged_longitude"]))
Example #11
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 pyparrot.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)
        bebop.pan_tilt_camera_velocity(pan_velocity=0, tilt_velocity=-2, duration=4)

        # 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)
        bebopVision.open_video()

    else:
        print("Error connecting to bebop. Retry")
Example #13
0
class ARDrone(Drone):
    def __init__(self):
        super().__init__()

        self.bebop = Bebop()

        print("connecting to bebop drone")
        self.connection.emit("progress")
        self.success = self.bebop.connect(5)
        if self.success:
            self.connection.emit("on")
            self.bebop.set_max_altitude(20)
            self.bebop.set_max_distance(20)
            self.bebop.set_max_rotation_speed(180)
            self.bebop.set_max_vertical_speed(2)
            self.bebop.enable_geofence(1)
            self.bebop.set_hull_protection(1)

            # todo: battery signal to emit (look in sensors)
            #TODO test this piece of code
            self.bebop.set_user_sensor_callback(print,
                                                self.bebop.sensors.battery)
        else:
            print("refresh....")
            self.connection.emit("off")

    def take_off(self):
        self.bebop.safe_takeoff(5)

    def land(self):
        self.bebop.safe_land(5)

    def stop(self):
        self.bebop.disconnect()

    def fly_direct(self, roll, pitch, yaw, vertical_movement):
        my_roll = self.bebop._ensure_fly_command_in_range(roll)
        my_pitch = self.bebop_ensure_fly_command_in_range(pitch)
        my_yaw = self.bebop_ensure_fly_command_in_range(yaw)
        my_vertical = self.bebop_ensure_fly_command_in_range(vertical_movement)
        command_tuple = self.bebop.command_parser.get_command_tuple(
            "ardrone3", "Piloting", "PCMD")
        self.bebop.drone_connection.send_single_pcmd_command(
            command_tuple, my_roll, my_pitch, my_yaw, my_vertical)

    def process_motion(self, _up, _rotate, _front, _right):
        velocity_up = _up * self.max_vert_speed
        velocity_yaw = _rotate * self.max_rotation_speed
        velocity_pitch = _front * self.max_horiz_speed
        velocity_roll = _right * self.max_horiz_speed
        #print("PRE", velocity_roll, velocity_pitch, velocity_up, velocity_yaw)
        self.fly_direct(velocity_roll, velocity_pitch, velocity_yaw,
                        velocity_up)
Example #14
0
    with detection_graph.as_default():
        od_graph_def = tf.GraphDef()
        with tf.gfile.GFile(PATH_TO_CKPT, 'rb') as fid:
            serialized_graph = fid.read()
            od_graph_def.ParseFromString(serialized_graph)
            tf.import_graph_def(od_graph_def, name='')
    sess = tf.Session(graph=detection_graph)

# Loading label map
# Label maps map indices to category names, so that when our convolution network predicts `5`, we know that this corresponds to `airplane`.  Here we use internal utility functions, but anything that returns a dictionary mapping integers to appropriate string labels would be fine
    label_map = label_map_util.load_labelmap(PATH_TO_LABELS)
    categories = label_map_util.convert_label_map_to_categories(
        label_map, max_num_classes=NUM_CLASSES, use_display_name=True)
    category_index = label_map_util.create_category_index(categories)

    drone = Bebop()
    success = drone.connect(5)
    #drone.set_picture_format('jpeg')
    is_bebop = True

    if (success):
        # get the state information
        print("sleeping")
        drone.smart_sleep(1)
        drone.ask_for_state_update()
        drone.smart_sleep(1)
        status = input("Input 't' if you want to TAKE OFF or not : ")

        bebopVision = DroneVisionGUI(drone, is_bebop=True, buffer_size=200,user_code_to_run=tracking_target,
                                      user_args=(drone, status, q))
        Kim = Kim(bebopVision)
Example #15
0

from pyparrot.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)

bebop.smart_sleep(5)
bebop.safe_land(10)

print("DONE - disconnecting")
bebop.disconnect()
Example #16
0
import sys, termios, tty, os, time, argparse

from pyparrot.Bebop import Bebop

parser = argparse.ArgumentParser(description='Set parameters for Parrot Bebop2')
parser.add_argument('-v', type = int, default = 20, help ='variable for roll, pitch, yaw')
parser.add_argument('-d', type = int, default = 2, help ='duration for each key press')

args = parser.parse_args()
percentage = args.v
duration_s = args.d

bebop = Bebop(drone_type="Bebop2")

print("Connecting Bebop2 with percentage: {}, duration: {}".format(percentage, duration_s))
success = bebop.connect(10)
print(success)
print(bebop.sensors.battery)

def getch():
    fd = sys.stdin.fileno()
    old_settings = termios.tcgetattr(fd)
    try:
        tty.setraw(sys.stdin.fileno())
        ch = sys.stdin.read(1)

    finally:
        termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
    return ch

if (success):
Example #17
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!

Author: Amy McGovern
"""

from pyparrot.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)
Example #18
0
"""
Demo the Bebop indoors (sets small speeds and then flies just a small amount)
Note, the bebop will hurt your furniture if it hits it.  Even though this is a very small
amount of flying, be sure you are doing this in an open area and are prepared to catch!

Author: Amy McGovern
"""

from pyparrot.Bebop import Bebop

bebop = Bebop(drone_type="Bebop2")

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)

    # set safe indoor parameters
    bebop.set_max_tilt(5)
    bebop.set_max_vertical_speed(1)
Example #19
0
        result = tfnet.return_predict(rescaled)
        print(result)

        # Sunflower detected:
        if (len(result) > 0):
            print("Found Sunflower")
            bebop.safe_land(10)
            bebopVision.close_video()
            found = True


###------------------###
#Start main:

# 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!")
Example #20
0
    def save_pictures(self, args):
        img = self.vision.get_latest_valid_picture()
        if img is not None:
            filename = "test_image_%06d.png" % self.index
            self.index += 1


try:
    # for Python2
    from Tkinter import *  ## notice capitalized T in Tkinter
except ImportError:
    # for Python3
    from tkinter import *  ## notice lowercase 't' in tkinter here

fields = 'Roll', 'Pitch', 'Yaw', 'Duration'
bebop = Bebop(drone_type='Bebop2')
print("Setting up a connection...")
success = bebop.connect(10)
if (success):
    print("Connection set:", success)
    # Turns on the camera (WIP)
    #bebopVision = DroneVision(bebop, is_bebop = True)
    #userVision = UserVision(bebopVision)
    #bebopVision.set_user_callback_function(userVision.save_pictures, user_callback_args = None)
    #print("Turning on the video...")
    #bebop.start_video_stream()
    #suc = bebopVision.open_video()
    #if suc:
    #    color_print("Vision successfully started", "SUCCESS")
    #else:
    #    color_print("Vision cannot start, try again", "ERROR")
Example #21
0
"""
Demos the tricks on the bebop. Make sure you have enough room to perform them!

Author: Amy McGovern
"""

from pyparrot.Bebop import Bebop

bebop = Bebop()

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

print("sleeping")
bebop.smart_sleep(1)
#
#bebop.ask_for_state_update()
#
#bebop.set_max_altitude(5)
#bebop.set_max_distance(10)
#bebop.enable_geofence(1)
#
#
#bebop.safe_takeoff(10)

#bebop.smart_sleep(1)
bebop.safe_land(10)

print("DONE - disconnecting")
bebop.disconnect()
Example #22
0
"""
Demo the Bebop indoors (sets small speeds and then flies just a small amount)
Note, the bebop will hurt your furniture if it hits it.  Even though this is a very small
amount of flying, be sure you are doing this in an open area and are prepared to catch!

Author: Amy McGovern
"""

from pyparrot.Bebop import Bebop

bebop = Bebop(drone_type="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)

    # set safe indoor parameters
    bebop.set_max_tilt(5)
    bebop.set_max_vertical_speed(1)
Example #23
0
"""
Make a small square. Purpose is to teach myself to program the drone.
"""

# boilerplate to connect and takeoff
from pyparrot.Bebop import Bebop
import math

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)

# do it using move_relative()
# fly forward
bebop.move_relative(1, 0, 0, 0)

bebop.smart_sleep(2)

# fly right
bebop.move_relative(0, 1, 0, 0)

bebop.smart_sleep(2)
    port = 5555

    print("Server:  " + host + ":" + str(port))

    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

    try:
        s.bind((host, port))
    except socket.error as e:
        print(str(e))

    s.listen(5)
    print("Waiting for a connection")

    # make my bebop object
    bebop = Bebop()

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

    if (success):
        bebop.smart_sleep(3)
        bebop.ask_for_state_update()

        flightProc = mp.Process(target=flight_plan, args=(keepGoing, ))
        flightProc.start()

        collisionProc = mp.Process(target=collision_avoidance,
                                   args=(keepGoing, ))
        collisionProc.start()
Example #25
0
import socket
from pyparrot.Bebop import Bebop

s = socket.socket()

port = 8080
s.bind(('', port))  # socketに名前をつける

print("listening")
s.listen(5)  # 接続待ち
c, addr = s.accept()  # 接続要求の取り出し
c.settimeout(10)

bebop = Bebop(drone_type="Bebop2")

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

try:
    if (success):
        print("sleeping")
        bebop.smart_sleep(2)

    bebop.ask_for_state_update()

    # set safe indoor parameters
    bebop.set_max_tilt(5)
    bebop.set_max_vertical_speed(1)

    # trying out the new hull protector parameters - set to 1 for a hull protection and 0 without protection
Example #26
0
    def Canny(pic):
        edges = cv2.Canny(pic, 50, 200, True)
        return(edges)

    def save_pictures(self, args):
        #print("saving picture")
        img = self.vision.get_latest_valid_picture()
        if (img is not None):
            img = Canny(img)
            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
    bebop.set_video_framerate("24_FPS")
    bebop.set_video_resolutions("rec720_stream720")
    bebopVision = DroneVision(bebop, is_bebop=True)
    bebopVision.cleanup_old_images = True
    userVision = UserVision(bebopVision)
    bebopVision.set_user_callback_function(userVision.save_pictures, user_callback_args=None)
    success = bebopVision.open_video()

    # if (success):
# import drone
from pyparrot.Bebop import Bebop


# function to uncover payload
def strip_packet(m):
    ba = bitstring.BitArray(bytes=m)  # encode string and turn to bit array
    pt = ba[9:16]  # type of packet contents
    # cc = ba[4:8]  # number of extra header fields
    print(pt.uint)  # for testing purposes
    # return ba[(12 + cc) * 8:]  # bit contents


# create drone and start video
drone = Bebop()
drone.connect(10)
drone.set_video_resolutions("rec1080_stream480")
drone.set_video_framerate("24_FPS")
drone.start_video_stream()

# create socket of required type, and bind to port
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)  # opens with ipv4 address and reads UDP packet
sock.bind(('192.168.42.63', 55004))  # binds machine to port

# receive packet and get payload
for _ in range(10):
    msg = sock.recv(4096)
    strip_packet(msg)
    # payload = stripPacket(msg)
Example #28
0
from pyparrot.Bebop import Bebop
import math

# you will need to change this to the address of YOUR mambo
bebop = Bebop()

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

# make my mambo object
# remember to set True/False for the wifi depending on if you are using the wifi or the BLE to connect

if (success):
    # get the state information
    print("sleeping")
    bebop.smart_sleep(2)
    bebop.ask_for_state_update()
    bebop.smart_sleep(5)

    print("taking off!")
    bebop.safe_takeoff(5)
    bebop.fly_direct(roll=0, pitch=0, yaw=0, vertical_movement=-20, duration=1)

    bebop.smart_sleep(3)

    print("Flying direct: going forward (positive pitch)")
    bebop.fly_direct(roll=0,
                     pitch=50,
                     yaw=0,
                     vertical_movement=0,
Example #29
0
from pyparrot.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)
Example #30
0
# Author - Samuel Ambler

# Fail command for bebop
from pyparrot.Bebop import Bebop

bebop = Bebop(drone_type="Bebop2")

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

if(success):
	bebop.safe_land(10)
	print("DONE - disconnecting")
	bebop.smart_sleep(5)
	print(bebop.sensors.battery)
	print("\033[1;37;41m BEBOP DOWN \033[1;37;40m");
	bebop.disconnect()