Skip to content

Commit

Permalink
Renamed done to terminated and added methods to set the truncated flag
Browse files Browse the repository at this point in the history
  • Loading branch information
JacopoPan committed Apr 28, 2023
1 parent cb995f1 commit bf3096f
Show file tree
Hide file tree
Showing 9 changed files with 135 additions and 17 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ python3 pid.py

## TODO

- [ ] Add `yaml` configuration files
- [ ] Add `stable-baselines3` 2.0 support/examples
- [ ] Add `pytest`s/GitHub Actions
- [ ] Add `pytest`s/GitHub Action for learning examples
- [ ] Add `yaml` configuration files

## Citation

Expand Down
23 changes: 18 additions & 5 deletions gym_pybullet_drones/envs/BaseAviary.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,10 @@ def step(self,
The step's reward value(s), check the specific implementation of `_computeReward()`
in each subclass for its format.
bool | dict[..]
Whether the current episode is over, check the specific implementation of `_computeDone()`
Whether the current episode is over, check the specific implementation of `_computeTerminated()`
in each subclass for its format.
bool | dict[..]
Whether the current episode is truncated, check the specific implementation of `_computeTruncated()`
in each subclass for its format.
bool | dict[..]
Whether the current episode is trunacted, always false.
Expand Down Expand Up @@ -343,8 +346,8 @@ def step(self,
#### Prepare the return values #############################
obs = self._computeObs()
reward = self._computeReward()
terminated = self._computeDone()
truncated = False # TODO: add support for truncated episodes
terminated = self._computeTerminated()
truncated = self._computeTruncated()
info = self._computeInfo()
#### Advance the step counter ##############################
self.step_counter = self.step_counter + (1 * self.AGGR_PHY_STEPS)
Expand Down Expand Up @@ -1048,8 +1051,18 @@ def _computeReward(self):

################################################################################

def _computeDone(self):
"""Computes the current done value(s).
def _computeTerminated(self):
"""Computes the current terminated value(s).
Must be implemented in a subclass.
"""
raise NotImplementedError

################################################################################

def _computeTruncated(self):
"""Computes the current truncated value(s).
Must be implemented in a subclass.
Expand Down
19 changes: 17 additions & 2 deletions gym_pybullet_drones/envs/CtrlAviary.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,23 @@ def _computeReward(self):

################################################################################

def _computeDone(self):
"""Computes the current done value(s).
def _computeTerminated(self):
"""Computes the current terminated value(s).
Unused as this subclass is not meant for reinforcement learning.
Returns
-------
bool
Dummy value.
"""
return False

################################################################################

def _computeTruncated(self):
"""Computes the current truncated value(s).
Unused as this subclass is not meant for reinforcement learning.
Expand Down
19 changes: 17 additions & 2 deletions gym_pybullet_drones/envs/VelocityAviary.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,23 @@ def _computeReward(self):

################################################################################

def _computeDone(self):
"""Computes the current done value(s).
def _computeTerminated(self):
"""Computes the current terminated value(s).
Unused as this subclass is not meant for reinforcement learning.
Returns
-------
bool
Dummy value.
"""
return False

################################################################################

def _computeTruncated(self):
"""Computes the current truncated value(s).
Unused as this subclass is not meant for reinforcement learning.
Expand Down
19 changes: 17 additions & 2 deletions gym_pybullet_drones/envs/VisionAviary.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,23 @@ def _computeReward(self):

################################################################################

def _computeDone(self):
"""Computes the current done value(s).
def _computeTerminated(self):
"""Computes the current terminated value(s).
Unused as this subclass is not meant for reinforcement learning.
Returns
-------
bool
Dummy value.
"""
return False

################################################################################

def _computeTruncated(self):
"""Computes the current truncated value(s).
Unused as this subclass is not meant for reinforcement learning.
Expand Down
17 changes: 16 additions & 1 deletion gym_pybullet_drones/envs/multi_agent_rl/FlockAviary.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def _computeReward(self):

################################################################################

def _computeDone(self):
def _computeTerminated(self):
"""Computes the current done value(s).
Returns
Expand All @@ -145,6 +145,21 @@ def _computeDone(self):
done = {i: bool_val for i in range(self.NUM_DRONES)}
done["__all__"] = True if True in done.values() else False
return done

################################################################################

def _computeTruncated(self):
"""Computes the current truncated value(s).
Unused in this implementation.
Returns
-------
bool
Always false.
"""
return False

################################################################################

Expand Down
17 changes: 16 additions & 1 deletion gym_pybullet_drones/envs/multi_agent_rl/LeaderFollowerAviary.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def _computeReward(self):

################################################################################

def _computeDone(self):
def _computeTerminated(self):
"""Computes the current done value(s).
Returns
Expand All @@ -106,6 +106,21 @@ def _computeDone(self):

################################################################################

def _computeTruncated(self):
"""Computes the current truncated value(s).
Unused in this implementation.
Returns
-------
bool
Always false.
"""
return False

################################################################################

def _computeInfo(self):
"""Computes the current info dict(s).
Expand Down
17 changes: 16 additions & 1 deletion gym_pybullet_drones/envs/single_agent_rl/FlyThruGateAviary.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def _computeReward(self):

################################################################################

def _computeDone(self):
def _computeTerminated(self):
"""Computes the current done value.
Returns
Expand All @@ -120,6 +120,21 @@ def _computeDone(self):
return True
else:
return False

################################################################################

def _computeTruncated(self):
"""Computes the current truncated value(s).
Unused in this implementation.
Returns
-------
bool
Always false.
"""
return False

################################################################################

Expand Down
17 changes: 16 additions & 1 deletion gym_pybullet_drones/envs/single_agent_rl/HoverAviary.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def _computeReward(self):

################################################################################

def _computeDone(self):
def _computeTerminated(self):
"""Computes the current done value.
Returns
Expand All @@ -89,6 +89,21 @@ def _computeDone(self):
return True
else:
return False

################################################################################

def _computeTruncated(self):
"""Computes the current truncated value(s).
Unused in this implementation.
Returns
-------
bool
Always false.
"""
return False

################################################################################

Expand Down

0 comments on commit bf3096f

Please sign in to comment.