Skip to content

Commit

Permalink
Tested learn.py with obs spaces and act spaces except one d pid
Browse files Browse the repository at this point in the history
  • Loading branch information
JacopoPan committed Nov 20, 2023
1 parent 7221e95 commit ec44b64
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 40 deletions.
19 changes: 0 additions & 19 deletions gym_pybullet_drones/envs/BaseAviary.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,6 @@ def step(self,
) for i in range(self.NUM_DRONES)]
#### Save, preprocess, and clip the action to the max. RPM #
else:
self._saveLastAction(action)
clipped_action = np.reshape(self._preprocessAction(action), (self.NUM_DRONES, 4))
#### Repeat for as many as the aggregate physics steps #####
for _ in range(self.PYB_STEPS_PER_CTRL):
Expand Down Expand Up @@ -466,7 +465,6 @@ def _housekeeping(self):
self.GUI_INPUT_TEXT = -1*np.ones(self.NUM_DRONES)
self.USE_GUI_RPM=False
self.last_input_switch = 0
self.last_action = -1*np.ones((self.NUM_DRONES, 4))
self.last_clipped_action = np.zeros((self.NUM_DRONES, 4))
self.gui_input = np.zeros(4)
#### Initialize the drones kinemaatic information ##########
Expand Down Expand Up @@ -916,23 +914,6 @@ def _normalizedActionToRPM(self,

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

def _saveLastAction(self,
action
):
"""Stores the most recent action into attribute `self.last_action`.
The last action can be used to compute aerodynamic effects.
Parameters
----------
action : ndarray
Ndarray containing the current RPMs input for each drone.
"""
self.last_action = np.reshape(action, (self.NUM_DRONES, 4))

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

def _showDroneLocalAxes(self,
nth_drone
):
Expand Down
43 changes: 22 additions & 21 deletions gym_pybullet_drones/examples/learn.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@
DEFAULT_OUTPUT_FOLDER = 'results'
DEFAULT_COLAB = False

DEFAULT_OBS = ObservationType('kin')
DEFAULT_ACT = ActionType('rpm')
DEFAULT_AGENTS = 2
DEFAULT_MA = True
DEFAULT_OBS = ObservationType('kin') # 'kin' or 'rgb'
DEFAULT_ACT = ActionType('vel') # 'rpm' or 'pid' or 'vel' or 'one_d_rpm' / TO BE FIXED: 'one_d_pid'
DEFAULT_AGENTS = 3
DEFAULT_MA = False

def run(output_folder=DEFAULT_OUTPUT_FOLDER, gui=DEFAULT_GUI, plot=True, colab=DEFAULT_COLAB, record_video=DEFAULT_RECORD_VIDEO):

Expand Down Expand Up @@ -152,35 +152,36 @@ def run(output_folder=DEFAULT_OUTPUT_FOLDER, gui=DEFAULT_GUI, plot=True, colab=D
obs2 = obs.squeeze()
act2 = action.squeeze()
print("Obs:", obs, "\tAction", action, "\tReward:", reward, "\tTerminated:", terminated, "\tTruncated:", truncated)
if not DEFAULT_MA:
logger.log(drone=0,
timestamp=i/test_env.CTRL_FREQ,
state=np.hstack([obs2[0:3],
np.zeros(4),
obs2[3:15],
act2
]),
control=np.zeros(12)
)
else:
for d in range(DEFAULT_AGENTS):
logger.log(drone=d,
if DEFAULT_OBS == ObservationType.KIN:
if not DEFAULT_MA:
logger.log(drone=0,
timestamp=i/test_env.CTRL_FREQ,
state=np.hstack([obs2[d][0:3],
state=np.hstack([obs2[0:3],
np.zeros(4),
obs2[d][3:15],
act2[d]
obs2[3:15],
act2
]),
control=np.zeros(12)
)
else:
for d in range(DEFAULT_AGENTS):
logger.log(drone=d,
timestamp=i/test_env.CTRL_FREQ,
state=np.hstack([obs2[d][0:3],
np.zeros(4),
obs2[d][3:15],
act2[d]
]),
control=np.zeros(12)
)
test_env.render()
print(terminated)
sync(i, start, test_env.CTRL_TIMESTEP)
if terminated:
obs = test_env.reset(seed=42, options={})
test_env.close()

if plot:
if plot and DEFAULT_OBS == ObservationType.KIN:
logger.plot()

if __name__ == '__main__':
Expand Down

0 comments on commit ec44b64

Please sign in to comment.