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 and viewer able to follow and entity #611

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jgleyze
Copy link

@jgleyze jgleyze commented Jan 19, 2025

Fixes #538 and #554

Hello !

I made changes to the camera and viewer class so that they can now follow an entity in various ways.

For both the viewer and any camera, once they are created, you can :

scene = gs.Scene(
            sim_options=gs.options.SimOptions(dt=0.02, substeps=2),
            viewer_options=gs.options.ViewerOptions(
                max_FPS=50,
                camera_pos=(2.0, 0.0, 2.5),
                camera_lookat=(0.0, 0.0, 0.5),
                camera_fov=40,
            ),
            show_viewer=True,
        )

entity = scene.add_entity() #load any enity

scene.viewer.follow_entity(entity)

follower_camera = scene.add_camera(res=(640,480),
                                        pos=(0.0, 2.0, 0.5),
                                        lookat=(0.0, 0.0, 0.5),
                                        fov=40,
                                        GUI=True)
 
follower_camera.follow_entity(entity, fixed_axis=(None, None, 0.5), smoothing=0.5, fix_orientation=True)

In this code both the viewer and follower_camera will follow the entity. The viewer will be rigidly linked to the entity, no smoothing (a bit nauseating if you do locomotion ahah!). The second one will have a smoothed motion on the xy plane and a fixed height of 0.5m.

fixed_axis is used to fix the camera movement on a chosen axis [x, y, z], if set to None the camera is able to move on this axis during the following. If set to a float the camera will stay fixed at this value on this axis. This does not fix its orientation. Hence won't change where the camera looks at, just its position the camera can still look up with a fixed z

fix_orientation is used alongside the fixed_axis because even though you fixed some axis the camera will rotate due to the call of lookat, this can lead to unwanted movement. For example, if fixed on the z height in a locomotion case the robot's gait might lead to some z movement and those would be repercuted on the camera orientation doing ups and downs.

Added code

  • camera.py

    • Added attributes relative to the following
    • Added function follow_entity to register the followed entity with some arguments related to the cameras' movement
    • Updated the render function to compute the camera's position with update_following
  • viewer.py

    • Basicaly the same, variation on the functions to call to set the camera's position
  • interactive_drone.py

    • Removed the update_camera function since it is now redundant, the viewer is directly set to follow the drone
  • go2_env.py

    • Added a follower camera on the side of the robot, the camera have fixed height and orientation
  • go2_train.py

    • Added -v / --vis to enable the gui for the viewer and follower camera

Examples

You can run

python examples/drone/interactive_drone.py
python examples/locomotion/go2_train.py -v

TODO

The camera only follow the first env due to camera.py

I don't really know how to get the id of each env here...

@jgleyze jgleyze changed the title [FEATURE] Camera and viwer able to follow and entity [FEATURE] Camera and viewer able to follow and entity Jan 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature request : Camera able to follow an entity
1 participant