Adding a camera - Environment.GetSensors() returns list with length 0
This post was updated on .
I have a bit of a problem here. I'm trying to add a camera sensor to my environment and after that work with the image data (OpenCV). I used the camera-example in the OpenRAVE wiki (a also tried using a separate file and create a reference to it in the sensor-tag but the result is the same):
<Environment> <robot name="kuka-KR210-2-CR" file="kr210-2-cr.dae"/> <sensor name="cameraSensor" type="BaseCamera"> <KK>640 640 320 340</KK> <width>640</width> <height>480</height> <framerate>5</framerate> <color>1 0 0</color> <translation>0 0 1.5</translation> <rotationaxis>1 0 0 90</rotationaxis> </sensor> </Environment>
The beginning of my code is where I'm loading my environment and calling the camera:
from openravepy import *
env = Environment()
robot = env.GetRobots()
manip = robot.SetActiveManipulator('DummyManipulator')
camera = env.GetSensor('cameraSensor')
I have tried with GetSensor(<nameOfSensor>) in which case I get a NoneType object and GetSensors(), which returns a list with 0 elements in it (so calling sensors gives an error "list index out of range").
It's just a fast power on, taking data and power off but it should work when not in Debug mode.
EDIT: Adding a timer resolves the issue. The problem probably lies in the setting responsible for the "speed" the camera shoots at. I think it's because of the time difference between the execution of the code and the shooting of the camera: I had set it to 5 FPS but if the code runs for like 1ms (and even less) the camera cannot get any data from the scene. This still does not answer the question - why does it work in debug mode (without a timer)?