Added check for animation file exceptions. Closes #19

This commit is contained in:
artem30801@gmail.com
2019-03-29 17:50:56 +03:00
parent 1f2c9386f9
commit a57a70a38e
3 changed files with 33 additions and 22 deletions

View File

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

View File

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

View File

@@ -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__':