parent
195e7a0782
commit
bb70deacf8
@ -1,28 +1,35 @@ |
||||
from TelloModule import TelloModule |
||||
import time |
||||
import matplotlib.pyplot as plt |
||||
import matplotlib.animation as animation |
||||
|
||||
|
||||
mod = TelloModule() |
||||
fig = plt.figure() |
||||
plt.ion() |
||||
|
||||
x = 100 |
||||
y = 150 |
||||
line1 = plt.plot([x, 0],[0, y], c = 'b') |
||||
line2 = plt.plot([-x, 0],[0, y], c = 'b') |
||||
line3 = plt.plot([-x, 0],[0, -y], c = 'b') |
||||
line4 = plt.plot([x, 0],[0, -y], c = 'b') |
||||
line5 = plt.plot([-x/3, x/3], [y-y/3, y-y/3], c = 'b') |
||||
|
||||
mod.module_init() |
||||
|
||||
point = [None, None, None, None] |
||||
while 1: |
||||
if (point[0] != None): |
||||
for p in point: |
||||
p.remove() |
||||
point[0] = plt.scatter(0, mod.get_forward_dist(), c = 'r') |
||||
point[1] = plt.scatter(mod.get_right_dist(), 0, c = 'r') |
||||
point[2] = plt.scatter(-mod.get_left_dist(), 0, c = 'r') |
||||
point[3] = plt.scatter(0, -mod.get_back_dist(), c = 'r') |
||||
|
||||
plt.pause(0.1) |
||||
|
||||
print ("\n -------- Test blocking mode --------- \n") |
||||
for i in range(10): |
||||
line = mod.get_block_dist() |
||||
print ("Test " + str(i) + |
||||
" count = " + str(line[0]) + |
||||
" forward = " + str(line[1]) + |
||||
" right = " + str(line[2]) + |
||||
" back = " + str(line[3]) + |
||||
" left = " + str(line[4]) + |
||||
" light = " + str(line[5])) |
||||
print ("\n ------ Test NON Blocking mode ------- \n") |
||||
mod.module_init('distance') |
||||
for i in range(10): |
||||
print ("Test " + str(i) + |
||||
" count = " + str(mod.get_count()) + |
||||
" forward = " + str(mod.get_forward_dist()) + |
||||
" right = " + str(mod.get_right_dist()) + |
||||
" back = " + str(mod.get_back_dist()) + |
||||
" left = " + str(mod.get_left_dist()) + |
||||
" light = " + str(mod.get_light())) |
||||
time.sleep(0.5) |
||||
plt.ioff() |
||||
plt.show() |
||||
mod.module_deinit() |
||||
print ("\n ------------ Finish Test ------------ \n") |
@ -0,0 +1,19 @@ |
||||
from easytello import tello |
||||
from TelloModule import TelloModule |
||||
|
||||
drone = tello.Tello() |
||||
mod = TelloModule() |
||||
|
||||
def main(): |
||||
drone.takeoff() |
||||
while 1: |
||||
line = mod.get_block_dist() |
||||
if int(line[1]) > 400: |
||||
drone.forward(20) |
||||
if int(line[1]) < 300: |
||||
drone.back(20) |
||||
|
||||
try: |
||||
main() |
||||
except KeyboardInterrupt: |
||||
drone.land() |
Loading…
Reference in new issue