loading
 
Roborealm loses the camera
Stephen Hewitson from United Kingdom  [6 posts]
3 years
Hi,

I am controlling RoboRealm using the COM_API. After successfully running through a barrage of tests and calling rr.close(), the next time I call rr.open() and rr.connect() I cannot seem to connect to the camera.

It comes up with an error saying "roborealm has detected the camera but could not connect to it"
No other applications are using the camera so my thoughts are that I am not releasing the camera properly inside roborealm - but I don't know what else to call other than rr.close().

Does anyone have any ideas?

Thanks,
Stephen
Steven Gentner from United States  [1405 posts] 3 years
Stephen,

Can you check that RR is actually gone from the task manager once you call close? Sometimes its possible that a timeout has not happened yet and one of the modules is holding it open.

Also, is there really a need to close and reopen the application? Can you just use rr.disconnect and then rr.connect which will close the connection but keep RR active. That will be a lot more efficient than restarting the app each time.

STeven.
Stephen Hewitson from United Kingdom  [6 posts] 3 years
STeven,

RR does go from task manager.

I close and reopen the application as I needed to reduce the current consumption and I didnt want the camera active all the time (which is what I saw when RR is running).

I go to a point (I think after I enabled verbose logging) where I am getting the following errors:
connectToCameraDirectX failed with code 183: Cannot create a file when that file already exists
connectToCameraDirectX2 failed with code 183: Cannot create a file when that file already exists
connectToCameraDirectX4 failed with code 183: Cannot create a file when that file already exists

Does that help at all?
Steven Gentner from United States  [1405 posts] 3 years
Stephen,

The error is saying that the camera is still active ... yes, it appears that things are not getting shut down correctly (DirectShow is a bit of a mess and some cameras don't quite respond in the same way).

What kind of camera are you using? We'll see if we can replicate the problem. If you can share your robofile by posting it here that would help.

Also, did you see the rr.SetCamera("off") and rr.SetCamera("on") which should also do what you need without restarting the connection. I'd still like to know what the camera is not being closed correctly but in the long run you will probably find that keeping RR active is easier.

STeven.
Stephen Hewitson from United Kingdom  [6 posts] 3 years
STeven,

I am using a Microsoft LifeCam Studio camera.
Just to confuse things, I've got the same camera on 2 PCs. They have different drivers for the camera (and only one of them doesn't work).

The camera is split into numerous parts:
Top level is a USB Composite Device. Inside this there is a Microsoft LifeCam Studio (with camera icon), Microsoft LifeCamStudio (with speaker icon), USB Input Device (which inside that has HID-Compliant Device).
I am guessing you are only interested in the camera iconed one...

So the one that appears to work with COM has the following driver info:
Date: 21/06/2006.
Version: 6.1.7601.18208
This driver was installed just by plugging the camera and letting Windows sort the rest.

The one that doesnt appear to work all that well with COM has the following:
Date: 02/12/2010
Version: 3.60.250.0
This driver was installed along with some software confusingly called LifeCam Studio.

I have got quite a bit of code using Sockets instead of COM, so I am going to convert my COM stuff back into Sockets for now.

I dont really use a robofile, I just load the stuff up as I go. I call the following (and sorry if this doesnt format it nicely...

if (RR_FALSE == rr.ShowWindow(false))
                    {
                        Debug_WriteLine("LEDS - RR - Can't hide window");
                    }

                    if (!rr.GetCurrentCamera().Contains("LifeCam"))
                    {
                        if (RR_FALSE == rr.SetCamera("LifeCam"))
                        {
                            Debug_WriteLine("LEDS - RR - Can't set camera");
                        }
                    }
                    if (RR_FALSE == rr.SetCameraFormat(800, 600, 30, "YUY2"))
                    {
                        Debug_WriteLine("LEDS - RR - Can't set camera format");
                    }

                    if (RR_FALSE == rr.SetCameraProperty("zoom", "60", false))
                    {
                        Debug_WriteLine("LEDS - RR - Can't set zoom");
                    }
                    if (RR_FALSE == rr.SetCameraProperty("focus", "14", false))
                    {
                        Debug_WriteLine("LEDS - RR - Can't set focus");
                    }
                    if (RR_FALSE == rr.SetCameraProperty("brightness", "130", false))
                    {
                        Debug_WriteLine("LEDS - RR - Can't set brightness");
                    }
                    if (RR_FALSE == rr.SetCameraProperty("saturation", "120", false))
                    {
                        Debug_WriteLine("LEDS - RR - Can't set saturation");
                    }
                    if (RR_FALSE == rr.SetCameraProperty("sharp", "50", false))
                    {
                        Debug_WriteLine("LEDS - RR - Can't set sharpness");
                    }

                    //Switch off auto-exposure and set value to -13
                    if (RR_FALSE == rr.SetCameraProperty("exposure", "-13", false))
                    {
                        Debug_WriteLine("LEDS - RR - Can't set exposure");
                    }

                    //Add the framework for the RGB filter and the blob filter
                    if (RR_FALSE == rr.Execute("<RGB_Filter>" +
                                            "<channel>3</channel>" +
                                            "<hue_value>64</hue_value>" +
                                            "<hysteresis>0</hysteresis>" +
                                            "<max_value>30</max_value>" +
                                            "<min_value>25</min_value>" +
                                            "<result_type>1</result_type>" +
                                        "</RGB_Filter>" +

                                        "<Flicker>" +
                                          "<num_frames>10</num_frames>" +
                                          "<threshold>8</threshold>" +
                                        "</Flicker>" +

                                        "<Blob_Filter>" +
                                            "<create_blob_array_variable>TRUE</create_blob_array_variable>" +
                                            "<filters>" +
                                                "<tab>" +
                                                    "<filter>" +
                                                        "<count_threshold>0</count_threshold>" +
                                                        "<create_array>0</create_array>" +
                                                        "<filter_id>8</filter_id>" +
                                                        "<invert_count>0</invert_count>" +
                                                        "<invert_threshold>0</invert_threshold>" +
                                                        "<minimum_size>30</minimum_size>" +
                                                        "<weight_threshold>0.98</weight_threshold>" +
                                                    "</filter>" +
                                                "</tab>" +
                                                "<tab:2/>" +
                                                "<tab:3/>" +
                                                "<tab:4/>" +
                                                "<tab:5/>" +
                                                "<tab:6/>" +
                                            "</filters>" +
                                            "<largest_is_background>FALSE</largest_is_background>" +
                                            "<show_weights>FALSE</show_weights>" +
                                            "<sort_array_on_x>TRUE</sort_array_on_x>" +
                                            "<sort_array_on_y>FALSE</sort_array_on_y>" +
                                        "</Blob_Filter>" +

                                        "<Rotate><custom_degree>0</custom_degree></Rotate>" +

                                        "<Shift><amount>0</amount><direction>1</direction></Shift>" +

                                        "<Shift><amount>0</amount><direction>2</direction></Shift>"))
                    {
                        Debug_WriteLine("LEDS - RR - Can't set pipeline");
                    }

Then all I do is set the filter by doing this...
rr.SetParameter("RGB_Filter", 1, "channel", "1");
                        String szFilterChannel = rr.GetParameter("RGB_Filter", 1, "channel");

                        if (szFilterChannel == "1")
                        {
                            bFilterSet = true;
                            Debug_WriteLine("LEDs - Red filter enabled");
                        }

and read the blob count using:
string szBlobCount = rr.GetVariable("BLOB_COUNT");

Thanks,
Stephen
Steven Gentner from United States  [1405 posts] 3 years
Stephen,

I have exactly that camera with the driver version that should NOT work ... but  alas it seems fine from the COM API.

Note, converting back to the sockets will not help as the COM object just translates the calls into socket calls for you ... so the interface is the same from the point of view of the RR app. I would not expect that to make any difference.

Instead, can you:

1. Run RR with the GUI and with an empty pipeline just click the Camera button on and off to see if you get the same issue? If not

2. Can you then simplify your COM calls to just open, and close the connection and run that a couple times to see if you get the error message? If not,

3. Add back in the camera settings but not the execute and set/get parameter and see what that does.

I'm trying to see if the issue has anything to do with RR or if it is truely a driver issue.

Note, I replicated all your statements above and ran the COM object 10x without any issue.

Thanks,
STeven.

Stephen Hewitson from United Kingdom  [6 posts] 3 years
STeven,

I've made a bit of progress over the weekend.
Now I start RR up which my application and keep it open all the time.

I see the issue now only if I close RR using my application.

if (!rr.IsConnected())
{
    rr.Connect("localhost", 6060);
}
rr.SetCamera("off");
rr.Close();

(I have tried with an without SetCamera("off") and it makes no difference)

My Close method just does the following:

if (!connected) return false;
if (send("<request><close/></request>"))
{
    String buffer;
    if ((buffer = readMessage()) != null)
    {
        return buffer.Equals("<response>ok</response>");
    }
}

Maybe I am closing it incorrectly(?) but my fix for now is that I never close RoboRealm.

Does that help at all?
Steven Gentner from United States  [1405 posts] 3 years
Stephen,

It does help a bit ... perhaps we have a timing issue here.

1. What is the state of the blue light of the camera after RR exits? Is it still on or off?

2. Can you test by adding a delay inbetween

rr.SetCamera("off");
Thread.Sleep(5000);
rr.Close();

and see if that does anything? I'm wondering if RR is closing too quickly and not allowing DirectX to cleanup correctly.

Unfortunately we're not seeing the error so its a bit tricky to fix.

STeven.

This forum thread has been closed due to inactivity (more than 4 months) or number of replies (more than 50 messages). Please start a New Post and enter a new forum thread with the appropriate title.

 New Post   Forum Index