Adding a camera - Environment.GetSensors() returns list with length 0

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Adding a camera - Environment.GetSensors() returns list with length 0

Aleksandar Atanasov
This post was updated on .
Hi!

  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 *
import numpy
import time
import cv2

env = Environment()
env.SetViewer('qtcoin')
env.Load('environment.kr210-2-cr.xml')
robot = env.GetRobots()[0]
manip = robot.SetActiveManipulator('DummyManipulator')
camera = env.GetSensor('cameraSensor')
with env:
with robot:
...
...

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[0] gives an error "list index out of range").

Can you please tell me what I'm doing wrong?

Greetings,
Aleksandar
Reply | Threaded
Open this post in threaded view
|

Re: Adding a camera - Environment.GetSensors() returns list with length 0

Aleksandar Atanasov
This post was updated on .
Problem solved. I misspelled the name (not the case in my post here though :D). Sorry for the fuss. :) It's working now and I get my camera (it also appears in my scene).

EDIT: Really strange. If I simply run my program, OpenRAVE throws an exception "SensorData failed". BUT if I run my code in Debug-mode step by step I get the data from the camera. O_O

Here is the code snippet where the magic happens:

...
cam = env.GetSensor('camera1')
cam.Configure(Sensor.ConfigureCommand.PowerOn)
camData = cam.GetSensorData()
cam.Configure(Sensor.ConfigureCommand.PowerOff)
...

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)?