def initializeTello():
    myDrone = djitellopy.Tello()
    myDrone.connect()
    myDrone.for_back_velocity = 0
    myDrone.left_right_velocity = 0
    myDrone.up_down_velocity = 0
    myDrone.yaw_velocity = 0
    print(myDrone.get_battery())
    myDrone.streamoff()
    myDrone.streamon()
    return myDrone
Beispiel #2
0
        self.event = Event()
        self.thread = Thread(target=self._target)
        self.thread.start()
    def _target(self):
        while not self.event.wait(self._time):
            self.function(*self.args, **self.kwargs)
    @property
    def _time(self):
        return self.interval - ((time.time() - self.start) % self.interval)
    def stop(self):
        self.stopped = True
        self.event.set()
        self.thread.join()


me = tello.Tello()
me.connect()
w,h = 360, 240
thresh = 0.5# Threshold to detect object

classNames = []
classFile = 'coco.names'
with open(classFile, 'rt') as f:
    classNames = f.read().rstrip('\n').split('\n')

configPath = 'ssd_mobilenet_v3_large_coco_2020_01_14.pbtxt'
weightPath = 'frozen_inference_graph.pb'

net = cv2.dnn_DetectionModel(weightPath, configPath)
net.setInputSize(320, 320)
net.setInputScale(1.0/127.5)
Beispiel #3
0
        finally:
            # drone.quit()
            pass


if __name__ == '__main__':

    def handler(event, sender, data, **args):
        drone = sender
        if event is drone.EVENT_FLIGHT_DATA:
            print(data)

    face_cascad = cv2.CascadeClassifier(cv2.data.haarcascades +
                                        'haarcascade_frontalface_default.xml')
    eye_cascade = cv2.CascadeClassifier(cv2.data.haarcascades +
                                        'haarcascade_eye.xml')
    drone = djitellopy.Tello()
    time.sleep(2)
    drone.connect()
    time.sleep(2)

    threadl = []
    t1 = mythread1()
    t2 = mythread2()
    threadl.append(t1)
    threadl.append(t2)
    t1.start()
    time.sleep(2)
    t2.start()
    print('Ending now %s' % time.ctime())
Beispiel #4
0
    def __init__(self):

        # FlowDroNet Configuration
        self.pwcnet_ckpt_path = localpath + '/models/pwc-net/pwcnet.ckpt-11000'
        self.dronet_model_path = localpath + '/models/FlowDroNet/model_graph_final.pb'
        self.output_folder = '/recordings/test_0'
        self.logfile = "log.json"
        self.FPS = 10
        self.hud_scale = 1.5
        self.starting_speed = 100

        # Configuration of controllable parameters
        # initial values
        self.params = {
            'v_max': 50,
            'r_max': 100,
            'r_scale': 0,
            'prev_len': 3,
            'prev_coll': 0.6,
            'prev_steer': 0.3,
            'reverse_thresh': 0.6,
            'reverse_offset': 0.7,
        }
        # stepsize
        self.params_d = {
            'v_max': 5,
            'r_max': 5,
            'r_scale': 50,
            'prev_len': 1,
            'prev_coll': 0.1,
            'prev_steer': 0.1,
            'reverse_thresh': 0.1,
            'reverse_offset': 0.1,
        }
        # max (min is 0)
        self.params_m = {
            'v_max': 100,
            'r_max': 100,
            'r_scale': 1000,
            'prev_len': 10,
            'prev_coll': 1,
            'prev_steer': 1,
            'reverse_thresh': 1,
            'reverse_offset': 1,
        }

        # Logging
        self.log_info = {'cur_v': [], 'cur_s': [], 'prd_c': [], 'prd_s': []}

        # Init internal variables (do not change anything below here)
        self.for_back_velocity = 0  # Drone velocities between -100~100
        self.left_right_velocity = 0
        self.up_down_velocity = 0
        self.yaw_velocity = 0
        self.internalSpeed = 100
        self.send_rc_control = False
        self.v_old = [
            0,
        ]
        self.s_old = [
            0,
        ]
        self.was_dronet = True
        self.last_pred_col = 0
        self.last_pred_ang = 0
        self.last_time = time.time()
        self.is_armed = False
        self.battery_percentage = 0
        self.should_stop = False
        self.record_data = False
        self.show_raw_data = False
        self.frame = None
        self.current_parameter = 0
        self.param_keys = list(self.params.keys())
        self.log_count = 0

        # Configure the pwc-net model for inference, starting with the default options
        self.nn_opts = deepcopy(_DEFAULT_FLOWDRONET_OPTS)
        self.nn_opts['verbose'] = False
        self.nn_opts['batch_size'] = 1
        self.nn_opts['ckpt_path'] = self.pwcnet_ckpt_path
        self.nn_opts['dronet_mode'] = 'rgb'
        self.nn_opts['dronet_model_path'] = self.dronet_model_path
        self.target_size = (int(self.nn_opts['y_shape'][1]),
                            int(self.nn_opts['y_shape'][0]))

        # Create output folder if not exists
        if not os.path.exists(
                os.path.join(self.output_folder,
                             str(self.log_count).zfill(2))):
            os.makedirs(
                os.path.join(self.output_folder,
                             str(self.log_count).zfill(2)))

        # Init pygame with display
        pygame.init()
        pygame.display.init()
        pygame.display.set_caption("FlowDroNeTello")
        self.screen = pygame.display.set_mode([
            int(self.hud_scale * self.target_size[0]) + 44,
            int(self.hud_scale * self.target_size[1]) + 36
        ])

        # Show bootscreen
        loadimg = cv2.imread(localpath + "/../misc/images/startuplogo.png")
        loadimg = np.fliplr(loadimg)
        loadimg = np.rot90(loadimg)
        loadimg = pygame.surfarray.make_surface(loadimg)
        self.screen.fill([0, 0, 0])
        self.screen.blit(loadimg, (0, 0))
        pygame.display.update()
        pygame.time.set_timer(USEREVENT + 1, int(1. / self.FPS * 1000))

        # Instantiate the model in inference mode and display the model configuration
        self.nn = ModelFlowDroNet(mode='test', options=self.nn_opts)
        self.nn.print_config()

        # Init Tello object that interacts with the Tello drone
        self.tello = djitellopy.Tello()