|
| 1 | +import mujoco |
| 2 | +import pytest |
| 3 | +from conftest import skip_if_headless |
| 4 | + |
| 5 | +from crazyflow import Sim |
| 6 | + |
| 7 | + |
| 8 | +@pytest.mark.unit |
| 9 | +@pytest.mark.parametrize("cam_name", ["fpv_cam:0", "track_cam:0", "fpv_cam:1", "track_cam:1"]) |
| 10 | +@pytest.mark.render |
| 11 | +@skip_if_headless |
| 12 | +def test_render_camera_selection_from_name(cam_name: str): |
| 13 | + sim = Sim(drone_model="cf21B_500", n_drones=2) |
| 14 | + cam_id = mujoco.mj_name2id(sim.mj_model, mujoco.mjtObj.mjOBJ_CAMERA, cam_name) |
| 15 | + sim.render(mode="human", camera=cam_name) |
| 16 | + viewer_cam = sim.viewer.viewer.cam |
| 17 | + assert viewer_cam.type == mujoco.mjtCamera.mjCAMERA_FIXED, "Camera type was not set to FIXED" |
| 18 | + assert viewer_cam.fixedcamid == cam_id, f"Expected cam ID {cam_id}, got {viewer_cam.fixedcamid}" |
| 19 | + sim.close() |
| 20 | + |
| 21 | + |
| 22 | +@pytest.mark.unit |
| 23 | +@pytest.mark.parametrize("cam_id", [0, 1, 2, 3]) |
| 24 | +@pytest.mark.render |
| 25 | +@skip_if_headless |
| 26 | +def test_render_camera_selection_from_id(cam_id: int): |
| 27 | + sim = Sim(drone_model="cf21B_500", n_drones=2) |
| 28 | + sim.render(mode="human", camera=cam_id) |
| 29 | + viewer_cam = sim.viewer.viewer.cam |
| 30 | + assert viewer_cam.type == mujoco.mjtCamera.mjCAMERA_FIXED, "Camera type was not set to FIXED" |
| 31 | + assert viewer_cam.fixedcamid == cam_id, f"Expected cam ID {cam_id}, got {viewer_cam.fixedcamid}" |
| 32 | + sim.close() |
| 33 | + |
| 34 | + |
| 35 | +@pytest.mark.unit |
| 36 | +@pytest.mark.render |
| 37 | +@skip_if_headless |
| 38 | +def test_render_free_camera(): |
| 39 | + sim = Sim(drone_model="cf21B_500", n_drones=2) |
| 40 | + sim.render(mode="human") |
| 41 | + viewer_cam = sim.viewer.viewer.cam |
| 42 | + assert viewer_cam.type == mujoco.mjtCamera.mjCAMERA_FREE, "Camera type was not set to FREE" |
| 43 | + sim.close() |
0 commit comments