Skip to content

Commit

Permalink
precommit
Browse files Browse the repository at this point in the history
  • Loading branch information
jjshoots committed May 1, 2024
1 parent 9df80c7 commit 17ff4ec
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
4 changes: 3 additions & 1 deletion PyFlyt/gym_envs/fixedwing_envs/fixedwing_base_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,9 @@ def begin_reset(
drone_options = dict()

# camera handling
drone_options["use_camera"] = drone_options.get("use_camera", False) or bool(self.render_mode)
drone_options["use_camera"] = drone_options.get("use_camera", False) or bool(
self.render_mode
)

# init env
self.env = Aviary(
Expand Down
20 changes: 15 additions & 5 deletions PyFlyt/gym_envs/quadx_envs/quadx_base_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,16 @@ def begin_reset(
self.info["collision"] = False
self.info["env_complete"] = False

# need to handle Nones
if options is None:
options = dict()
if drone_options is None:
drone_options = dict()

# camera handling
drone_options["use_camera"] = drone_options.get("use_camera", False) or bool(self.render_mode)
drone_options["use_camera"] = drone_options.get("use_camera", False) or bool(
self.render_mode
)

# init env
self.env = Aviary(
Expand Down Expand Up @@ -288,23 +296,25 @@ def render(self) -> np.ndarray:
raise ValueError(
"Please set `render_mode='human'` or `render_mode='rgb_array'` in init to use this function."
)
if self.render_mode is "human":

if self.render_mode == "human":
_, _, rgbaImg, _, _ = self.env.getCameraImage(
width=self.render_resolution[1],
height=self.render_resolution[0],
viewMatrix=self.camera_parameters[2],
projectionMatrix=self.camera_parameters[3],
)
elif self.render_mode is "rgb_array":
elif self.render_mode == "rgb_array":
_, _, rgbaImg, _, _ = self.env.getCameraImage(
width=self.render_resolution[1],
height=self.render_resolution[0],
viewMatrix=self.env.drones[0].camera.view_mat,
projectionMatrix=self.env.drones[0].camera.proj_mat,
)
else:
raise ValueError(f"Unknown render mode {self.render_mode}, should not have ended up here")
raise ValueError(
f"Unknown render mode {self.render_mode}, should not have ended up here"
)

rgbaImg = np.asarray(rgbaImg).reshape(
self.render_resolution[0], self.render_resolution[1], -1
Expand Down
4 changes: 3 additions & 1 deletion PyFlyt/gym_envs/rocket_envs/rocket_base_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,9 @@ def begin_reset(
self.start_orn = rotation

# camera handling
drone_options["use_camera"] = drone_options.get("use_camera", False) or bool(self.render_mode)
drone_options["use_camera"] = drone_options.get("use_camera", False) or bool(
self.render_mode
)

# init env
self.env = Aviary(
Expand Down

0 comments on commit 17ff4ec

Please sign in to comment.