diff --git a/Drone/FlightLib/FlightLib.py b/Drone/FlightLib/FlightLib.py index 74b4f98..e2960b5 100644 --- a/Drone/FlightLib/FlightLib.py +++ b/Drone/FlightLib/FlightLib.py @@ -11,7 +11,7 @@ from mavros_msgs.srv import SetMode from mavros_msgs.srv import CommandBool from std_srvs.srv import Trigger -module_logger = logging.getLogger("FlightLib.FlightLib") +module_logger = logging.getLogger("FlightLib") # create proxy service navigate = rospy.ServiceProxy('navigate', srv.Navigate) diff --git a/Drone/client.py b/Drone/client.py index f939ac5..02a6d18 100644 --- a/Drone/client.py +++ b/Drone/client.py @@ -26,7 +26,7 @@ logging.basicConfig( # TODO all prints as logs level=logging.INFO, format="%(asctime)s [%(name)-7.7s] [%(threadName)-12.12s] [%(levelname)-5.5s] %(message)s", handlers=[ - logging.FileHandler("client_logs"), + logging.FileHandler("client_logs.log"), logging.StreamHandler() ]) @@ -143,7 +143,10 @@ def recive_file(filename): def animation_player(running_event, stop_event): print("Animation thread activated") frames = play_animation.read_animation_file() - # rate = rospy.Rate(1000 / 125) + if not frames: + logging.error("Animation is empty, shutting down animation player") + return + delay_time = 0.125 print("Takeoff") diff --git a/Drone/play_animation.py b/Drone/play_animation.py index a024566..5bd9a2e 100644 --- a/Drone/play_animation.py +++ b/Drone/play_animation.py @@ -1,10 +1,13 @@ import time import csv import rospy +import logging from FlightLib import FlightLib -#FlightLib.init('SingleCleverFlight') from FlightLib import LedLib +module_logger = logging.getLogger("Animation player") + + animation_file_path = 'animation.csv' USE_LEDS = True @@ -39,24 +42,29 @@ def reach_frame(current_frame, x0=0.0, y0=0.0, timeout=5000): def read_animation_file(filepath=animation_file_path): - imporetd_frames = [] - with open(filepath) as animation_file: - csv_reader = csv.reader( - animation_file, delimiter=',', quotechar='|' - ) - for row in csv_reader: - frame_number, x, y, z, yaw, red, green, blue = row - imporetd_frames.append({ - 'number': int(frame_number), - 'x': float(x), - 'y': float(y), - 'z': float(z), - 'yaw': float(yaw), - 'red': int(red), - 'green': int(green), - 'blue': int(blue), - }) - return imporetd_frames + imported_frames = [] + try: + animation_file = open(filepath) + except IOError: + logging.error("File {} can't be opened".format(filepath)) + else: + with animation_file: + csv_reader = csv.reader( + animation_file, delimiter=',', quotechar='|' + ) + for row in csv_reader: + frame_number, x, y, z, yaw, red, green, blue = row + imported_frames.append({ + 'number': int(frame_number), + 'x': float(x), + 'y': float(y), + 'z': float(z), + 'yaw': float(yaw), + 'red': int(red), + 'green': int(green), + 'blue': int(blue), + }) + return imported_frames if __name__ == '__main__':