From 715a719840c588b838ce949e7eea4a966f0f3db3 Mon Sep 17 00:00:00 2001 From: Alexandr <37707797+Neptune-1@users.noreply.github.com> Date: Sun, 25 Nov 2018 14:15:46 +0300 Subject: [PATCH] Add files via upload --- Drone/play_animation.py | 66 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 Drone/play_animation.py diff --git a/Drone/play_animation.py b/Drone/play_animation.py new file mode 100644 index 0000000..2f56337 --- /dev/null +++ b/Drone/play_animation.py @@ -0,0 +1,66 @@ +import time +import csv +import ntplib +from FlightLib import FlightLib +FlightLib.init('SingleCleverFlight') +from FlightLib import LedLib + +animation_file_path = 'animation.csv' +frames = [] +def time_synch() + c = ntplib.NTPClient() + response = c.request('ntp1.stratum2.ru') + return response.tx_time + +time0=time_synch() + + +def takeoff(): + FlightLib.takeoff() + LedLib.wipe_to(0, 255, 0) + + +def land(): + LedLib.rainbow() + FlightLib.land() + LedLib.off() + + +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 + ) + LedLib.fill( + int(current_frame['green']), int(current_frame['red']), int(current_frame['blue']) + ) + + +def read_animation_file(): + with open(animation_file_path) as animation_file: + csv_reader = csv.reader( + animation_file, delimiter=',', quotechar='|' + ) + for row in csv_reader: + frame_number, x, y, z, speed, red, green, blue, yaw = row + frames.append({ + 'number': frame_number, + 'x': x, + 'y': y, + 'z': z, + 'speed': speed, + 'red': red, + 'green': green, + 'blue': blue, + 'yaw': yaw + }) + + +if __name__ == '__main__': + read_animation_file() + takeoff() + for frame in frames: + do_next_animation(frame) + time.sleep(0.1) + land() + time.sleep(3)