diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..7973e81 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..fdd8fdf --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/pythonProject1.iml b/.idea/pythonProject1.iml new file mode 100644 index 0000000..d89595a --- /dev/null +++ b/.idea/pythonProject1.iml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/Keypressmodule.py b/Keypressmodule.py new file mode 100644 index 0000000..7b89a97 --- /dev/null +++ b/Keypressmodule.py @@ -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() diff --git a/imagecpature.py b/imagecpature.py new file mode 100644 index 0000000..25c907b --- /dev/null +++ b/imagecpature.py @@ -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) \ No newline at end of file diff --git a/keyboardcontrol.py b/keyboardcontrol.py new file mode 100644 index 0000000..ccd0019 --- /dev/null +++ b/keyboardcontrol.py @@ -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]) + diff --git a/main.py b/main.py new file mode 100644 index 0000000..c28018d --- /dev/null +++ b/main.py @@ -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() \ No newline at end of file diff --git a/mapping.py b/mapping.py new file mode 100644 index 0000000..f47a5a3 --- /dev/null +++ b/mapping.py @@ -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) +