From 1b14a1a993f315b57a6c90ef9e07c51acbd12a56 Mon Sep 17 00:00:00 2001 From: Jacopo Panerati Date: Sun, 19 Nov 2023 12:56:42 +0400 Subject: [PATCH] Revised reward, terminated, truncated in RL aviaries --- gym_pybullet_drones/envs/HoverAviary.py | 6 +++--- gym_pybullet_drones/envs/LeaderFollowerAviary.py | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/gym_pybullet_drones/envs/HoverAviary.py b/gym_pybullet_drones/envs/HoverAviary.py index 76f8267cc..c66388570 100644 --- a/gym_pybullet_drones/envs/HoverAviary.py +++ b/gym_pybullet_drones/envs/HoverAviary.py @@ -48,7 +48,7 @@ def __init__(self, The type of action space (1 or 3D; RPMS, thurst and torques, or waypoint with PID control) """ - self.target_pos = np.array([0,0,1]) + self.TARGET_POS = np.array([0,0,1]) super().__init__(drone_model=drone_model, num_drones=1, initial_xyzs=initial_xyzs, @@ -74,7 +74,7 @@ def _computeReward(self): """ state = self._getDroneStateVector(0) - ret = max(0, 500 - np.linalg.norm(self.target_pos-state[0:3])**2) + ret = max(0, 500 - np.linalg.norm(self.TARGET_POS-state[0:3])**2) return ret ################################################################################ @@ -89,7 +89,7 @@ def _computeTerminated(self): """ state = self._getDroneStateVector(0) - if np.linalg.norm(self.target_pos-state[0:3]) < .001: + if np.linalg.norm(self.TARGET_POS-state[0:3]) < .001: return True else: return False diff --git a/gym_pybullet_drones/envs/LeaderFollowerAviary.py b/gym_pybullet_drones/envs/LeaderFollowerAviary.py index fcaa73f55..27865b024 100644 --- a/gym_pybullet_drones/envs/LeaderFollowerAviary.py +++ b/gym_pybullet_drones/envs/LeaderFollowerAviary.py @@ -54,7 +54,7 @@ def __init__(self, The type of action space (1 or 3D; RPMS, thurst and torques, or waypoint with PID control) """ - self.target_pos = np.array([0,0,1]) + self.TARGET_POS = np.array([0,0,1]) super().__init__(drone_model=drone_model, num_drones=num_drones, neighbourhood_radius=neighbourhood_radius, @@ -82,7 +82,7 @@ def _computeReward(self): """ rewards = np.zeros(self.NUM_DRONES) states = np.array([self._getDroneStateVector(i) for i in range(self.NUM_DRONES)]) - ret = max(0, 500 - np.linalg.norm(self.target_pos-states[0, 0:3])**2) + ret = max(0, 500 - np.linalg.norm(self.TARGET_POS-states[0, 0:3])**2) for i in range(1, self.NUM_DRONES): ret += max(0, 100 - np.linalg.norm(states[i-1, 3]-states[i, 3])**2) return ret @@ -99,7 +99,7 @@ def _computeTerminated(self): """ state = self._getDroneStateVector(0) - if np.linalg.norm(self.target_pos-state[0:3]) < .001: + if np.linalg.norm(self.TARGET_POS-state[0:3]) < .001: return True else: return False