IsaacLab icon indicating copy to clipboard operation
IsaacLab copied to clipboard

[Question] AttributeError: 'Camera' object has no attribute '_timestamp'

Open iamzweiaa opened this issue 1 month ago • 1 comments

Question

I'd like to try to add a scene camera in a direct RL env that i will play to see the trainning result. but it came to the error:AttributeError: 'Camera' object has no attribute '_timestamp' Here is my code ''' @configclass class DroneSceneEnvCfg(QuadcopterEnvCfg):

terrain = TerrainImporterCfg(
    prim_path="/World/stonebridge",
    terrain_type="usd",
    usd_path="source/isaaclab_assets/data/props/bridge/stonebridge_d.usd",
    collision_group=-1,
    physics_material=sim_utils.RigidBodyMaterialCfg(
        friction_combine_mode="multiply",
        restitution_combine_mode="multiply",
        static_friction=1.0,
        dynamic_friction=1.0,
        restitution=0.0,
    ),
    debug_vis=False,
)
#robot: ArticulationCfg = CRAZYFLIE_CFG.replace(prim_path="{ENV_REGEX_NS}/Robot")

camera_external: CameraCfg = CameraCfg(
    prim_path="/World/SceneCamera",         
    update_period=0.05,                     
    width=640,
    height=480,
    data_types=["rgb"],
    spawn=sim_utils.PinholeCameraCfg(
        focal_length=24.0,
        focus_distance=5.0,
        horizontal_aperture=20.955,
        clipping_range=(0.1, 1000.0),
    ),
    offset=CameraCfg.OffsetCfg(
        pos=(5.0, 5.0, 3.0),               
        rot=(0.707, 0.0, -0.707, 0.0),     
        convention="ros",
    ),
)

-----------------------------

-----------------------------

def main():

print(f"loading trained policy from {args_cli.checkpoint}...")
# load the trained jit policy
policy_path = os.path.abspath(args_cli.checkpoint)
file_content = omni.client.read_file(policy_path)[2]
file = io.BytesIO(memoryview(file_content).tobytes())
policy = torch.jit.load(file, map_location=args_cli.device)


# setup environment
env_cfg = DroneSceneEnvCfg()
env_cfg.sim.device = args_cli.device
env_cfg.scene.num_envs = args_cli.num_envs
env=QuadcopterEnv(env_cfg)
obs, _ = env.reset()
sim_dt = env.sim.get_physics_dt()

sim_utils.spawn_ground_plane(
    prim_path="/World/GroundPlane",
    cfg=sim_utils.GroundPlaneCfg(),
)
external_camera = Camera(env_cfg.camera_external)


# env_cfg.sim.set_camera_view([5, 5, 5], [0.0, 0.0, 0.0])

output_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), "output", "camera1")
os.makedirs(output_dir, exist_ok=True)
count = 0
# create simulation context
print("Creating simulation context...")
with torch.inference_mode():
    while simulation_app.is_running():
        action = policy(obs["policy"])
        obs, _, _, _, _ = env.step(action)
        external_camera.update(dt=env.sim.get_physics_dt())


        if args_cli.save_camera:
            rgb_frame_drone = external_camera.data.output["rgb"][0].cpu().numpy()
            drone_camera_info = external_camera.data.info[0]

            rep_output_drone = {"annotators": {}}
            rep_output_drone["annotators"]["rgb"] = {
                "render_product": {"data": rgb_frame_drone, **(drone_camera_info or {})}
            }
            rep_output_drone["trigger_outputs"] = {"on_time": count}
            dronewriter= rep.BasicWriter(output_dir=os.path.join(output_dir, "drone"), frame_padding=0)
            dronewriter.write(rep_output_drone)
        
        count += 1

if name == "main":

main()
simulation_app.close()

''' is there anything wrong? why i can't add a camera here?

iamzweiaa avatar Nov 05 '25 10:11 iamzweiaa

Hi, Can you share the full logs? Do you still get the error if you don't run with save_camera? Probably your writer is expecting the _timestamp attribute from Camera but it doesn't have it. As I don't know how to repro with your shared code, this is just my suspects.

PeterL-NV avatar Nov 06 '25 22:11 PeterL-NV

Hi, Can you share the full logs? Do you still get the error if you don't run with save_camera? Probably your writer is expecting the _timestamp attribute from Camera but it doesn't have it. As I don't know how to repro with your shared code, this is just my suspects.

Hi Peter thank you for the reply! your suspect is right! I didn't use the camera cfg correctly camera=env.scene.sensors["camera"] ---this is the right way

iamzweiaa avatar Nov 20 '25 10:11 iamzweiaa