drone: Fix animation module

This commit is contained in:
Arthur Golubtsov
2020-06-18 16:29:45 +01:00
parent 6e47118dfb
commit dc38d55ddc

View File

@@ -445,11 +445,13 @@ class Animation(object):
self.mark_flight() self.mark_flight()
def get_start_frame(self, action): def get_start_frame(self, action):
if action == 'fly': try:
return self.output_frames[self.start_frame_index] if action == 'fly':
if action == 'takeoff': return self.output_frames[self.start_frame_index]
return self.output_frames_takeoff[self.start_frame_index] if action == 'takeoff':
return None return self.output_frames_takeoff[self.start_frame_index]
except IndexError:
return None
def get_output_frames(self, action): def get_output_frames(self, action):
if action == 'fly': if action == 'fly':
@@ -470,8 +472,9 @@ class Animation(object):
if not self.output_frames: if not self.output_frames:
return 'error: empty output frames' return 'error: empty output frames'
# Check current_height # Check current_height
if math.isnan(current_height): if self.config.animation_check_ground:
return 'error: bad copter height' if math.isnan(current_height):
return 'error: bad copter height'
# Select start action # Select start action
try: try:
start_action = self.config.animation_start_action start_action = self.config.animation_start_action
@@ -491,17 +494,18 @@ class Animation(object):
else: else:
return 'error in [ANIMATION] start_action parameter' return 'error in [ANIMATION] start_action parameter'
# Check that bottom point of animation is higher than ground level # Check that bottom point of animation is higher than ground level
try: if self.config.animation_check_ground:
ground_level = self.config.animation_ground_level try:
if ground_level == 'current': ground_level = self.config.animation_ground_level
ground_level = current_height if ground_level == 'current':
ground_level = float(ground_level) ground_level = current_height
except (ValueError, KeyError): ground_level = float(ground_level)
return 'error in [ANIMATION] ground_level parameter' except (ValueError, KeyError):
if state != "ACTIVE" and ground_level - tolerance > self.get_min_z(start_action): return 'error in [ANIMATION] ground_level parameter'
return 'error: animation is lower than ground level for {:.2f}m'.format( if state != "ACTIVE" and ground_level - tolerance > self.get_min_z(start_action):
ground_level - self.output_frames_min_z return 'error: animation is lower than ground level for {:.2f}m'.format(
) ground_level - self.output_frames_min_z
)
return start_action return start_action
try: try: