-
Notifications
You must be signed in to change notification settings - Fork 2
/
BasicMovements.py
64 lines (49 loc) · 1.99 KB
/
BasicMovements.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
from djitellopy import tello
import cv2
from time import sleep
# want to add delays for each command (line 2)
# Need to connect to Tello Drone, create tello object
ai = tello.Tello()
# this will create the tello object.
ai.connect()
# connecting to Tello Drone
# To make sure this code is running, I'll print out the battery percentage to see if the connection is stable
print(ai.get_battery())
# Needs to take off
ai.takeoff()
# Automating the drone to go forward at a velocity of 50
ai.send_rc_control(0, 50, 0, 0)
"""Send RC control via four channels. Command is sent every self.TIME_BTW_RC_CONTROL_COMMANDS seconds.
Arguments:
left_right_velocity: -100~100 (left/right)
forward_backward_velocity: -100~100 (forward/backward)
up_down_velocity: -100~100 (up/down)
yaw_velocity: -100~100 (yaw)
"""
sleep(2)
# delays per second, how long it stays in the air
ai.send_rc_control(0, 0, 0, 25)
sleep(2)
# Rotates right at 50
ai.send_rc_control(0, 75, 0, 0)
sleep(2)
# Goes forward at a velocity of 50 again
ai.send_rc_control(0, 0, 0, 0)
# Need this so the drone stops and then lands
ai.land()
# For Computer Vision
ai.streamon()
# Gives us all the frames that we need
while True:
image = ai.get_frame_read().frame
# This should give us each image one by one (individually)
# To resize image we can use the ML library openCV2 to do such
image = cv2.resize(image, (360, 240))
# Keeping the size of the frame small so the image loads faster
# image then updates into the resized because of CV2 library
cv2.imshow("Image", image)
# Creates a window to display image
cv2.waitKey(1)
"""Frames will shut down, before we can see it, so we need to give it a delay of some sort, 1 milisecond should
do the trick. There will be a delay in the frames,because of the transfer from drone to client side,
trying to keep up with the graphical computations."""