Add files via upload

This commit is contained in:
Alexandr
2018-11-25 14:15:46 +03:00
committed by GitHub
parent 90b6dd2f98
commit 715a719840

66
Drone/play_animation.py Normal file
View File

@@ -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)