Skip to content

Commit

Permalink
restore go2 example
Browse files Browse the repository at this point in the history
  • Loading branch information
YilingQiao committed Feb 2, 2025
1 parent 8d59063 commit f7f2f38
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 23 deletions.
1 change: 0 additions & 1 deletion examples/drone/interactive_drone.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ def update_thrust(self):
return self.rpms



def run_sim(scene, drone, controller):
while controller.running:
try:
Expand Down
13 changes: 0 additions & 13 deletions examples/locomotion/go2_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,6 @@ def __init__(self, num_envs, env_cfg, obs_cfg, reward_cfg, command_cfg, show_vie
),
)

# add follower camera
if show_viewer:
self.follower_camera = self.scene.add_camera(res=(640,480),
pos=(0.0, 2.0, 0.5),
lookat=(0.0, 0.0, 0.5),
fov=40,
GUI=True)
# follow the robot at a fixed height and orientation
self.follower_camera.follow_entity(self.robot, fixed_axis=(None, None, 0.5), smoothing=0.5, fix_orientation=True)

# build
self.scene.build(n_envs=num_envs)

Expand Down Expand Up @@ -134,9 +124,6 @@ def step(self, actions):
self.robot.control_dofs_position(target_dof_pos, self.motor_dofs)
self.scene.step()

if hasattr(self, "follower_camera"):
self.follower_camera.render()

# update buffers
self.episode_length_buf += 1
self.base_pos[:] = self.robot.get_pos()
Expand Down
3 changes: 1 addition & 2 deletions examples/locomotion/go2_train.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ def get_cfgs():

def main():
parser = argparse.ArgumentParser()
parser.add_argument("-v", "--vis", action="store_true", default=False, help="Enable visualization (default: False)")
parser.add_argument("-e", "--exp_name", type=str, default="go2-walking")
parser.add_argument("-B", "--num_envs", type=int, default=4096)
parser.add_argument("--max_iterations", type=int, default=100)
Expand All @@ -154,7 +153,7 @@ def main():
os.makedirs(log_dir, exist_ok=True)

env = Go2Env(
num_envs=args.num_envs, env_cfg=env_cfg, obs_cfg=obs_cfg, reward_cfg=reward_cfg, command_cfg=command_cfg, show_viewer=args.vis
num_envs=args.num_envs, env_cfg=env_cfg, obs_cfg=obs_cfg, reward_cfg=reward_cfg, command_cfg=command_cfg
)

runner = OnPolicyRunner(env, train_cfg, log_dir, device="cuda:0")
Expand Down
8 changes: 5 additions & 3 deletions genesis/vis/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ def follow_entity(self, entity, fixed_axis=(None, None, None), smoothing=None, f
The entity to follow.
fixed_axis : (float, float, float), optional
The fixed axis for the camera's movement. For each axis, if None, the camera will move freely. If a float, the viewer will be fixed on at that value.
For example, [None, None, None] will allow the camera to move freely while following, [None, None, 0.5] will fix the viewer's z-axis at 0.5.
For example, [None, None, None] will allow the camera to move freely while following, [None, None, 0.5] will fix the viewer's z-axis at 0.5.
smoothing : float, optional
The smoothing factor for the camera's movement. If None, no smoothing will be applied.
fix_orientation : bool, optional
Expand All @@ -306,15 +306,17 @@ def update_following(self):
"""

entity_pos = self._followed_entity.get_pos()[0].cpu().numpy()
if entity_pos.ndim > 1: #check for multiple envs
if entity_pos.ndim > 1: # check for multiple envs
entity_pos = entity_pos[0]
camera_pos = np.array(self._pos)
camera_pose = np.array(self._transform)
lookat_pos = np.array(self._lookat)

if self._follow_smoothing is not None:
# Smooth camera movement with a low-pass filter
camera_pos = self._follow_smoothing * camera_pos + (1 - self._follow_smoothing) * (entity_pos + self._init_pos)
camera_pos = self._follow_smoothing * camera_pos + (1 - self._follow_smoothing) * (
entity_pos + self._init_pos
)
lookat_pos = self._follow_smoothing * lookat_pos + (1 - self._follow_smoothing) * entity_pos
else:
camera_pos = entity_pos + self._init_pos
Expand Down
12 changes: 8 additions & 4 deletions genesis/vis/viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def follow_entity(self, entity, fixed_axis=(None, None, None), smoothing=None, f
The entity to follow.
fixed_axis : (float, float, float), optional
The fixed axis for the viewer's movement. For each axis, if None, the viewer will move freely. If a float, the viewer will be fixed on at that value.
For example, [None, None, None] will allow the viewer to move freely while following, [None, None, 0.5] will fix the viewer's z-axis at 0.5.
For example, [None, None, None] will allow the viewer to move freely while following, [None, None, 0.5] will fix the viewer's z-axis at 0.5.
smoothing : float, optional
The smoothing factor in ]0,1[ for the viewer's movement. If None, no smoothing will be applied.
fix_orientation : bool, optional
Expand All @@ -188,15 +188,19 @@ def update_following(self):
Update the viewer position to follow the specified entity.
"""
entity_pos = self._followed_entity.get_pos().cpu().numpy()
if entity_pos.ndim > 1: #check for multiple envs
if entity_pos.ndim > 1: # check for multiple envs
entity_pos = entity_pos[0]
camera_pose = np.array(self._pyrender_viewer._trackball.pose)
camera_pos = np.array(self._pyrender_viewer._trackball.pose[:3, 3])

if self._follow_smoothing is not None:
# Smooth viewer movement with a low-pass filter
camera_pos = self._follow_smoothing * camera_pos + (1 - self._follow_smoothing) * (entity_pos + np.array(self._camera_init_pos))
self._follow_lookat = self._follow_smoothing * self._follow_lookat + (1 - self._follow_smoothing) * entity_pos
camera_pos = self._follow_smoothing * camera_pos + (1 - self._follow_smoothing) * (
entity_pos + np.array(self._camera_init_pos)
)
self._follow_lookat = (
self._follow_smoothing * self._follow_lookat + (1 - self._follow_smoothing) * entity_pos
)
else:
camera_pos = entity_pos + np.array(self._camera_init_pos)
self._follow_lookat = entity_pos
Expand Down

0 comments on commit f7f2f38

Please sign in to comment.