Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/camera tracking drone #239

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions examples/drone/interactive_drone.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,37 @@ def update_thrust(self):
return self.rpms


def update_camera(scene, drone):
"""Updates the camera position to follow the drone"""
if not scene.viewer:
return

drone_pos = drone.get_pos()

# Camera position relative to drone
offset_x = 0.0 # centered horizontally
offset_y = -4.0 # 4 units behind (in Y axis)
offset_z = 2.0 # 2 units above

camera_pos = (float(drone_pos[0] + offset_x), float(drone_pos[1] + offset_y), float(drone_pos[2] + offset_z))

# Update camera position and look target
scene.viewer.set_camera_pose(pos=camera_pos, lookat=tuple(float(x) for x in drone_pos))


def run_sim(scene, drone, controller):
while controller.running:
try:
# Update drone with current RPMs
rpms = controller.update_thrust()
drone.set_propellels_rpm(rpms)

# Update physics
scene.step()

# Update camera position to follow drone
update_camera(scene, drone)

time.sleep(1 / 60) # Limit simulation rate
except Exception as e:
print(f"Error in simulation loop: {e}")
Expand All @@ -116,9 +139,9 @@ def main():
# Initialize Genesis
gs.init(backend=gs.cpu)

# Create scene with enhanced camera view
# Create scene with initial camera view
viewer_options = gs.options.ViewerOptions(
camera_pos=(4.0, 0.0, 2.0),
camera_pos=(0.0, -4.0, 2.0), # Now behind the drone (negative Y)
camera_lookat=(0.0, 0.0, 0.5),
camera_fov=45,
max_FPS=60,
Expand Down