mirror of
https://github.com/CopterExpress/clever-show.git
synced 2026-05-29 16:29:34 +00:00
Added check for animation file exceptions. Closes #19
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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__':
|
||||
|
||||
Reference in New Issue
Block a user