From c6f800b4898bd87b303f24202794e626c172e034 Mon Sep 17 00:00:00 2001 From: Artem30801 Date: Sat, 8 Dec 2018 15:46:01 +0300 Subject: [PATCH] Syntax fixes --- Drone/Client.py | 17 +++++++++-------- Drone/play_animation.py | 30 ++++++++++++------------------ 2 files changed, 21 insertions(+), 26 deletions(-) diff --git a/Drone/Client.py b/Drone/Client.py index df7fcf9..c34e7d3 100755 --- a/Drone/Client.py +++ b/Drone/Client.py @@ -1,16 +1,18 @@ import socket import play_animation import time +import ntplib +from threading import Thread sock = socket.socket() -serv = '192.168.1.10' # Change to server ip +serv = '192.168.1.10' # Change to server ip port = 35001 sock.connect((serv, port)) -sock.send(bytes('left','utf-8')) +sock.send(bytes('left', 'utf-8')) command = '' + def receive(): global command - try: while True: data = str(sock.recv(1024)) @@ -48,6 +50,7 @@ def receive(): led.off() sock.close() + def time_synch(): c = ntplib.NTPClient() response = c.request('ntp1.stratum2.ru') @@ -57,13 +60,13 @@ def time_synch(): def pl_anim(): global command play_animation.read_animation_file() - dtime=time_synch() - time.time() + dtime = time_synch() - time.time() while True: if 'begin_anim' in command: t_st = int(command[command.index('('):]) - if t_st==dtime+time.time: + if t_st == dtime+time.time: break if 'synch' in command: dtime=time_synch() - time.time() @@ -76,9 +79,7 @@ def pl_anim(): play_animation.do_next_animation(frame) - - -if __name__==__main__: +if __name__ == "__main__": t_0 = Thread(target=receive) t_0.daemon = True t_0.start() diff --git a/Drone/play_animation.py b/Drone/play_animation.py index 83502df..cc4686e 100644 --- a/Drone/play_animation.py +++ b/Drone/play_animation.py @@ -3,21 +3,14 @@ import csv from FlightLib.FlightLib import FlightLib FlightLib.init('SingleCleverFlight') from FlightLib.FlightLib import LedLib -import ntplib - animation_file_path = 'drone.csv' frames = [] -''' -def time_synch(): - c = ntplib.NTPClient() - response = c.request('ntp1.stratum2.ru') - return response.tx_time-time.time() -''' + def takeoff(): - FlightLib.takeoff(1.75) LedLib.wipe_to(0, 255, 0) + FlightLib.takeoff(1.75) def land(): @@ -29,7 +22,7 @@ def land(): def do_next_animation(current_frame): FlightLib.navto( round(float(current_frame['x']), 4), round(float(current_frame['y']), 4), round(float(current_frame['z']), 4), - round(float(current_frame['yaw']), 4), speed=2 + round(float(current_frame['yaw']), 4), speed=round(float(current_frame['speed']), 4) ) LedLib.fill( int(current_frame['green']), int(current_frame['red']), int(current_frame['blue']) @@ -54,20 +47,21 @@ def read_animation_file(): 'blue': blue, 'yaw': yaw }) -def frame() + + +def frame(): global frames return frames -''' + + if __name__ == '__main__': read_animation_file() - #dtime=time_synch()-time.time() - #while True: - # if t_st==dtime+time.time: - # break + takeoff() + #FlightLib.reach() for frame in frames: - time.sleep(0.1)#cut for using ntp + time.sleep(0.1) do_next_animation(frame) land() - time.sleep(3)''' + time.sleep(3) \ No newline at end of file