-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 266582d
Showing
10 changed files
with
243 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,24 @@ | ||
import pygame | ||
|
||
def init(): | ||
pygame.init() | ||
win = pygame.display.set_mode((400, 400)) | ||
|
||
def getKey(keyName): | ||
ans = False | ||
for eve in pygame.event.get():pass | ||
keyInput = pygame.key.get_pressed() | ||
myKey = getattr(pygame,'K_{}'.format(keyName)) | ||
if keyInput[myKey]: | ||
ans = True | ||
pygame.display.update() | ||
return ans | ||
def main(): | ||
if getKey("LEFT"): | ||
print("Left key Pressed") | ||
if getKey("RIGHT"): | ||
print("Right key Pressed") | ||
if __name__ == '__main__': | ||
init() | ||
while True: | ||
main() |
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,14 @@ | ||
from djitellopy import tello | ||
import cv2 | ||
|
||
us = tello.Tello() | ||
us.connect() | ||
print(us.get_battery()) | ||
|
||
us.streamon() | ||
|
||
while True: | ||
pic = us.get_frame_read().frame | ||
pic = cv2.resize(pic, (360, 240)) | ||
pic.imshow("image", pic) | ||
cv2.waitKey(2) |
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,51 @@ | ||
from djitellopy import tello | ||
import Keypressmodule as kp | ||
import time | ||
import cv2 | ||
|
||
kp.init() | ||
us = tello.Tello() | ||
us.connect() | ||
print(us.get_battery()) | ||
|
||
|
||
def getKeyIn(): | ||
lr, fb, up, yv = 0, 0, 0, 0 | ||
speed = 50 | ||
if kp.getKey("LEFT"): lr = speed | ||
elif kp.getKey("RIGHT"): lr = speed | ||
|
||
if kp.getKey("UP"): | ||
fb = speed | ||
elif kp.getKey("DOWN"): | ||
fb = -speed | ||
|
||
if kp.getKey("w"): | ||
up = speed | ||
elif kp.getKey("s"): | ||
up = -speed | ||
|
||
if kp.getKey("a"): | ||
yv = -speed | ||
elif kp.getKey("d"): | ||
yv = speed | ||
|
||
if kp.getKey("q"): | ||
us.land() | ||
if kp.getKey("e"): | ||
us.takeoff() | ||
|
||
if kp.getKey('z'): | ||
cv2.imwrite(f'Resources/Images/{time.time()}.jpg') | ||
##To aviod multiple unwanted shots | ||
time.sleep(0.3) | ||
|
||
return [lr, fb, up, yv ] | ||
|
||
##Reset drone if error is found | ||
us.takeoff() | ||
|
||
while True: | ||
vals = getKeyIn() | ||
us.send_rc_control(vals[0], vals[1], vals[2], vals[3]) | ||
|
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,18 @@ | ||
from djitellopy import tello | ||
from time import sleep | ||
|
||
us = tello.Tello() | ||
us.connect() | ||
print(us.get_battery()) | ||
us.takeoff() | ||
us.move_forward(15) | ||
sleep(2) | ||
##After sleep move | ||
us.send_rc_control(0, 50, 0, 0) | ||
##left, right, forward, backward and yaw(twist of drone) | ||
sleep(1) | ||
us.send_rc_control(10, 0, 0, 0) | ||
sleep(4) | ||
us.send_rc_control(0, 0, 0, 0) | ||
## so as to land like a helicopter | ||
us.land() |
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,105 @@ | ||
from djitellopy import tello | ||
import Keypressmodule as kp | ||
from time import sleep | ||
import numpy as np | ||
import cv2 | ||
import math | ||
##PARAMETERS | ||
|
||
forsp = 117/10 ##forward speed (cm)/s | ||
aspeed = 360/10 ##Angular speed in degrees/s | ||
val = 0.75 | ||
|
||
dval = forsp * aspeed | ||
aval = aspeed* val ## angular interval | ||
|
||
x, y = 500, 500 | ||
a = 0 | ||
yaw = 0 | ||
kp.init() | ||
us = tello.Tello() | ||
us.connect() | ||
print(us.get_battery()) | ||
|
||
points = [] | ||
|
||
x, y = 500, 650 | ||
|
||
def getKeyIn(): | ||
lr, fb, up, yv = 0, 0, 0, 0 | ||
speed = 15 | ||
global yaw | ||
global x | ||
global y | ||
global a | ||
d = 0 | ||
|
||
if kp.getKey("LEFT"): | ||
lr = speed | ||
d = dval | ||
a = -100 | ||
elif kp.getKey("RIGHT"): | ||
lr = speed | ||
d = -dval | ||
a = -180 | ||
|
||
if kp.getKey("UP"): | ||
fb = speed | ||
d = dval | ||
a = 270 | ||
elif kp.getKey("DOWN"): | ||
fb = -speed | ||
d = -dval | ||
a = -19 | ||
|
||
if kp.getKey("w"): | ||
up = speed | ||
elif kp.getKey("s"): | ||
up = -speed | ||
|
||
if kp.getKey("a"): | ||
yv = -speed | ||
yaw -= aval | ||
elif kp.getKey("d"): | ||
yv = speed | ||
yaw += -aval | ||
|
||
if kp.getKey("q"): | ||
us.land() | ||
if kp.getKey("e"): | ||
us.takeoff() | ||
|
||
sleep(val) | ||
a += yaw | ||
x += int(d*math.cos(math.radians(a))) | ||
y += int(d*math.sin(math.radians(a))) | ||
|
||
if kp.getKey('z'): | ||
cv2.imwrite(f'Resources/Images/{time.time()}.jpg') | ||
##To aviod multiple unwanted shots | ||
time.sleep(0.3) | ||
|
||
|
||
|
||
return [lr, fb, up, yv, x, y] | ||
|
||
##Reset drone if error is found | ||
us.takeoff() | ||
## DRaw an image using the drone. | ||
def artPoints(img , points): | ||
for point in points: | ||
cv2.circle(img, point , 5, (0, 0, 255), cv2.FILLED) | ||
cv2.putText(img, f'({points[-1][0] - 500/100}, {points[-1][1] - 500/100})m'),\ | ||
(points[-1][0] + 10, points[-1][1] + 30 ) | ||
|
||
|
||
while True: | ||
vals = getKeyIn() | ||
us.send_rc_control(vals[0], vals[1], vals[2], vals[3]) | ||
|
||
img = np.zeros((1000, 1000, 3), np.uint8) | ||
points.append((vals[4], vals[5])) | ||
artPoints(img, points) | ||
cv2.imshow("Resource", img) | ||
cv2.waitkey(1) | ||
|