Final test version of play_animation.py

This commit is contained in:
Arthur
2019-02-26 21:01:24 +00:00
parent 7f7af0b2f7
commit 328350e2ab

View File

@@ -13,19 +13,19 @@ USE_LEDS = True
def takeoff(): #x, y, z
if USE_LEDS:
LedLib.wipe_to(0, 255, 0)
FlightLib.takeoff()
FlightLib.takeoff1()
def land():
if USE_LEDS:
LedLib.blink(0, 255, 0)
FlightLib.land()
FlightLib.land1()
if USE_LEDS:
LedLib.off()
def do_next_animation(current_frame):
FlightLib.navto(current_frame['x'], current_frame['y'], current_frame['z'], speed=current_frame['speed'])
def do_next_animation(current_frame, x0 = 0, y0 = 0):
FlightLib.navto(current_frame['x']+x0, current_frame['y']+y0, current_frame['z'], yaw = 1.57)
if USE_LEDS:
LedLib.fill(current_frame['green'], current_frame['red'], current_frame['blue'])
@@ -36,8 +36,7 @@ def read_animation_file(filepath=animation_file_path):
animation_file, delimiter=',', quotechar='|'
)
for row in csv_reader:
frame_number, x, y, z, yaw, red, green, blue = row
speed = FlightLib.get_distance()
frame_number, x, y, z, speed, red, green, blue = row
frames.append({
'number': int(frame_number),
'x': float(x),
@@ -57,15 +56,17 @@ def get_frames():
if __name__ == '__main__':
rospy.init_node('Animation_player', anonymous=True)
LedLib.init_led()
if USE_LEDS:
LedLib.init_led()
X0 = 0.5
Y0 = 1.0
read_animation_file()
rate = rospy.Rate(10)
#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(x=frames[0]['x'], y=frames[0]['y'], z=frames[0]['z'])
#for frame in frames:
# rate.sleep()
# do_next_animation(frame)
FlightLib.reach(x=frames[0]['x']+X0, y=frames[0]['y']+Y0, z=frames[0]['z'], yaw = 1.57)
for frame in frames:
rate.sleep()
do_next_animation(frame, x0 = X0, y0 = Y0)
land()