From 6fab97c648c56dbb25a196234e1cba3cff2507f0 Mon Sep 17 00:00:00 2001 From: Artem30801 Date: Tue, 26 Feb 2019 09:13:35 +0300 Subject: [PATCH] Fixed animation reading, improved standalone run procedure --- Drone/play_animation.py | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/Drone/play_animation.py b/Drone/play_animation.py index e23b693..f93135b 100644 --- a/Drone/play_animation.py +++ b/Drone/play_animation.py @@ -10,7 +10,7 @@ frames = [] USE_LEDS = True -def takeoff(): #x, y, z +def takeoff(): if USE_LEDS: LedLib.wipe_to(0, 255, 0) FlightLib.takeoff() @@ -26,12 +26,16 @@ 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=round(float(current_frame['speed']), 4) + round(float(current_frame['x']), 4), + round(float(current_frame['y']), 4), + round(float(current_frame['z']), 4), + round(float(current_frame['yaw']), 4), ) if USE_LEDS: LedLib.fill( - int(current_frame['green']), int(current_frame['red']), int(current_frame['blue']) + int(current_frame['green']), + int(current_frame['red']), + int(current_frame['blue']) ) @@ -41,17 +45,16 @@ def read_animation_file(filepath=animation_file_path): animation_file, delimiter=',', quotechar='|' ) for row in csv_reader: - frame_number, x, y, z, speed, red, green, blue, yaw = row + frame_number, x, y, z, yaw, red, green, blue, = row frames.append({ 'number': frame_number, 'x': x, 'y': y, 'z': z, - 'speed': speed, + 'yaw': yaw, 'red': red, 'green': green, 'blue': blue, - 'yaw': yaw }) @@ -62,17 +65,20 @@ def get_frames(): if __name__ == '__main__': rospy.init_node('Animation_player', anonymous=True) - LedLib.init_led() + if USE_LEDS: + LedLib.init_led() read_animation_file() - #first_frame = frames[0] - #takeoff(round(float(first_frame['x']), 4), round(float(first_frame['y']), 4), round(float(first_frame['z']), 4)) takeoff() - #FlightLib.reach() + first_frame = frames[0] + FlightLib.reach(round(float(first_frame['x']), 4), + round(float(first_frame['y']), 4), + round(float(first_frame['z']), 4)) + for frame in frames: time.sleep(0.1) do_next_animation(frame) land() - time.sleep(3) \ No newline at end of file + time.sleep(3)