|
1 | 1 | Camera
|
2 | 2 | ======
|
3 | 3 |
|
4 |
| -The ``Camera`` class defines how images should be rendered from a camera in the world model. Note that the ``Camera`` class does not by itself add a camera to the MuJoCo model — the camera must have already existed and can be referenced by its name. The camera can be added in two ways: |
5 |
| - |
6 |
| -1. By adding a camera to the MuJoCo model file. Refer to the `section on camera <https://mujoco.readthedocs.io/en/stable/XMLreference.html#body-camera>`_ in the MuJoCo XML reference for more information. As an example, the following XML code adds a tracking camera to the MuJoCo model: |
7 |
| - |
8 |
| -.. code-block:: xml |
9 |
| -
|
10 |
| - <worldbody> |
11 |
| - <!-- ... other things ... --> |
12 |
| - <camera name="camera_top" class="nmf" mode="track" ipd="0.068" pos="0 0 8" euler="0 0 0"/> |
13 |
| - </worldbody> |
14 |
| -
|
15 |
| -2. By calling ``.worldbody.add()`` on the root element of the MuJoCo model programmatically in Python. Practically, this can be done by extending an existing FlyGym Arena class and adding the camera in the ``__init__`` method. For example, the following code adds a stationary bird's eye camera to the MuJoCo model: |
16 |
| - |
17 |
| -.. code-block:: python3 |
18 |
| -
|
19 |
| - from flygym.arena import BaseArena |
20 |
| -
|
21 |
| - class MyArena(BaseArena): |
22 |
| - def __init__(self): |
23 |
| - super().__init__() |
24 |
| - self.birdeye_cam = self.root_element.worldbody.add( |
25 |
| - "camera", |
26 |
| - name="birdseye_cam", |
27 |
| - mode="fixed", |
28 |
| - pos=(20, 0, 20), |
29 |
| - euler=(0, 0, 0), |
30 |
| - fovy=60, |
31 |
| - ) |
32 |
| - # ... other things ... |
33 |
| -
|
34 |
| -Once the camera is added to the MuJoCo model, it can be referenced by its name to initialize the ``Camera`` object with additional parameters assigned to it. These can include: rendering rate in frames-per-second (FPS), window size, play speed, etc. Furthermore, the ``Camera`` class has useful methods such as ``.save_video``, ``.reset``, etc. Logics such as rotating the camera in tilted terrain are also implemented in the ``Camera`` class. The ``.render`` method is the main point of entry for fetching images from the camera. |
35 |
| - |
36 |
| -The full API reference of the ``Camera`` class is as follows: |
37 |
| - |
38 |
| -.. autoclass:: flygym.camera.Camera |
| 4 | +The ``Camera`` class defines how images should be rendered from a camera in the world model. |
| 5 | +Cameras are added dynamically to the model by calling ``.body.add()`` on any body of the MuJoCo model programmatically in Python. In this way, the XML file does not need to contain all the preset cameras. |
| 6 | +When instantiating a ``Camera`` object, the user has to specify: |
| 7 | + - The attachment point: this can be a body or a site in the model. |
| 8 | + - The name of the camera. |
| 9 | + - The targeted fly names. Those flies will be the one(s) whose contact forces will be drawn. |
| 10 | +In order to simplify ``Camera`` instantiation, we provide a set of predefined camera parameters in config.yaml. Those parameters are used if the camera name matches the name of one of those cameras. |
| 11 | +In case the camera name does not match any of the predefined cameras, the user can specify the camera parameters manually. |
| 12 | + |
| 13 | +This new logic for cameras allows a more flexible definition of the cameras update rules. |
| 14 | +We propose three different camera update rules: |
| 15 | +- ``ZStabilizedCamera``: The camera z position is fixed at a given height above the floor. |
| 16 | +- ``YawOnlyCamera``: Only the yaw and position of the camera are updated. This smoothens camera movements during locomotion in tracked cameras. |
| 17 | +- ``GravityAlignedCamera``: This camera updates its orientation based on the changes in the gravity vector. This camera is useful for tracking the fly orientation in the world frame. |
| 18 | + |
| 19 | +The full API reference of the different type of camera classes is as follows: |
| 20 | + |
| 21 | +.. automodule:: flygym.camera |
39 | 22 | :members:
|
40 | 23 | :undoc-members:
|
41 | 24 | :show-inheritance:
|
0 commit comments