From f815b3bd96fe914e029e77ff5cacdee861a5a432 Mon Sep 17 00:00:00 2001 From: Francisco Rivas Date: Tue, 15 Feb 2022 16:18:13 +0100 Subject: [PATCH] Fixed tmp random initial index selection and non valid stat selection --- behavior_metrics/pilot.py | 5 ++++- behavior_metrics/utils/tmp_world_generator.py | 15 +++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/behavior_metrics/pilot.py b/behavior_metrics/pilot.py index 830aa518..41b1c554 100644 --- a/behavior_metrics/pilot.py +++ b/behavior_metrics/pilot.py @@ -215,7 +215,10 @@ def calculate_metrics(self, experiment_metrics): if hasattr(self.brains.active_brain, 'inference_times'): self.brains.active_brain.inference_times = self.brains.active_brain.inference_times[10:-10] mean_inference_time = sum(self.brains.active_brain.inference_times) / len(self.brains.active_brain.inference_times) - frame_rate = self.sensors.get_camera('camera_0').total_frames / experiment_metrics['experiment_total_simulated_time'] + try: + frame_rate = self.sensors.get_camera('camera_0').total_frames / experiment_metrics['experiment_total_simulated_time'] + except: + frame_rate = 0 gpu_inference = self.brains.active_brain.gpu_inference real_time_update_rate = self.real_time_update_rate first_image = self.brains.active_brain.first_image diff --git a/behavior_metrics/utils/tmp_world_generator.py b/behavior_metrics/utils/tmp_world_generator.py index 95b81450..26cf2d17 100644 --- a/behavior_metrics/utils/tmp_world_generator.py +++ b/behavior_metrics/utils/tmp_world_generator.py @@ -53,13 +53,20 @@ def tmp_world_generator(current_world, stats_perfect_lap, real_time_update_rate, root = tree.getroot() perfect_lap_checkpoints, circuit_diameter = metrics.read_perfect_lap_rosbag(stats_perfect_lap) - + check_point_offset = 5 if randomize: - random_index = random.randint(0, int(len(perfect_lap_checkpoints))) - random_point = perfect_lap_checkpoints[random_index] + random_index = random.randint(0, int(len(perfect_lap_checkpoints) - check_point_offset - 1)) + + try: + random_point = perfect_lap_checkpoints[random_index] + except Exception as exc: + random_index = 2 + random_point = perfect_lap_checkpoints[random_index] + + p1 = perfect_lap_checkpoints[random_index] - p2 = perfect_lap_checkpoints[random_index + 5] + p2 = perfect_lap_checkpoints[random_index + check_point_offset] delta_y = p2['pose.pose.position.y'] - p1['pose.pose.position.y'] delta_x = p2['pose.pose.position.x'] - p1['pose.pose.position.x'] result = math.atan2(delta_y, delta_x)