Why it returns -1 when I tried to create_camera_sensor?

I use self.gtm.create_camera_sensor(env_handle, self.cam_props) to create a camera sensor but it returns -1, so I can’t set the camera pos and get the image. I have checked the env_handle and it’s normal. I am wondering what could be the potential reason because it seems I just add the sensor as the example shows…

When I try to attact camera to body, it shows could not find camera with handle -1 in environment 0

Here is my code

local_offset = gymapi.Vec3(0.0, 0.0, 0.05)
cam_pitch = np.random.uniform(25, 35)
local_rotation = gymapi.Quat.from_axis_angle(gymapi.Vec3(0, 1, 0), np.deg2rad(cam_pitch))
camera_base_handle = self.gym.find_actor_rigid_body_handle(env_handle, robot_handle, “base”)
cam_handle = self.gym.create_camera_sensor(env_handle, self.cam_props)
self.camera_handles.append(cam_handle)
self.gym.attach_camera_to_body(
cam_handle, env_handle, camera_base_handle, gymapi.Transform(local_offset, local_rotation),
gymapi.FOLLOW_TRANSFORM
)

Hi @zdxiaohuihui

Make sure that the graphics_device is correctly configured (and it has a value different that -1) in gym.create_sim(compute_device, graphics_device, physics_engine, sim_params)

1 Like

Ah that works. I set the graphics_device to be -1 when training because it’s headless. Thank you so much!
But I want to use the camera data during training while not rendering the environment as it will make the training quite slow. Would this be possible?

Glad to hear it’s working…

As for the configuration, it is possible to configure the cameras (by setting the graphics_device) without creating/enabling the viewer.

For a reference, you can check the isaacgymenvs/tasks/base/vec_task.py file…
Particularly…

  • The configuration of the graphics_device
  • The creation of the viewer
  • And, the rendering

As you can identify, the graphics_device is set to -1 only if you don’t want to use camera sensors and want to run in headless mode… While the viewer is only created and used if the headless flag is set to False

So I can train without viewer by setting graphics_device_id not to be -1 while run in headless mode, but anyway I need to render if I want to use camera sensors. I see. Thank you so much for your kind reply!