Go to Post Valentine's day, who has time for Valentine's day?????? I have code to write!! - paulcd2000 [more]
Home
Go Back   Chief Delphi > Technical > Programming > C/C++
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 03-03-2012, 17:46
woodk woodk is offline
Registered User
FRC #2809
 
Join Date: Jan 2009
Location: Kingston, Ontario, Canada
Posts: 31
woodk has a spectacular aura aboutwoodk has a spectacular aura aboutwoodk has a spectacular aura about
Camera code stops recieving images

Hi Everyone,

We are having an interesting problem with our camera code and we were wondering if anyone has seen anything like these.

We have an auto targeting routine that works great but we are only able to call it about 6 times andd then the camera stops returning images. We still get the live feed on the dashboard though. Afterwards we have to reboot to get the camera code to work again.

Any idea what might be wrong?

Does anyone do anything special in sequential camera calls?
Reply With Quote
  #2   Spotlight this post!  
Unread 04-03-2012, 02:14
mikets's Avatar
mikets mikets is offline
Software Engineer
FRC #0492 (Titan Robotics)
Team Role: Mentor
 
Join Date: Jan 2010
Rookie Year: 2008
Location: Bellevue, WA
Posts: 671
mikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of light
Re: Camera code stops recieving images

One possibility is the camera task died. You need to look at your net console to see if that's the case.
__________________
Reply With Quote
  #3   Spotlight this post!  
Unread 06-03-2012, 09:19
frdrake frdrake is offline
Registered User
FRC #0233
 
Join Date: Feb 2012
Location: Melbourne
Posts: 23
frdrake is on a distinguished road
Re: Camera code stops recieving images

Are you deleting the old images you are creating as part of your loop. I read somewhere that the old images will build up fast if you aren't removing them constantly.
Reply With Quote
  #4   Spotlight this post!  
Unread 06-03-2012, 18:05
Method's Avatar
Method Method is offline
Registered User
no team
 
Join Date: Jan 2012
Rookie Year: 2011
Location: Ca
Posts: 38
Method is an unknown quantity at this point
Re: Camera code stops recieving images

Im having the same problem right now. I have one version where it doesn't occur and a more recent one where it does. The changes should* all be okay though...
The newer version organizes particles. That is the only change. My image is deleted also.

As for the console, i have been using the ds lcd recently because after i connect target server when trying to open the console the target tools option is not available in the drop down menu.
Reply With Quote
  #5   Spotlight this post!  
Unread 06-03-2012, 19:38
Method's Avatar
Method Method is offline
Registered User
no team
 
Join Date: Jan 2012
Rookie Year: 2011
Location: Ca
Posts: 38
Method is an unknown quantity at this point
Re: Camera code stops recieving images

reports->at(highParticle).center_mass_y;

I think lines like this may be what is guilty... is there anything wrong with this?

reports is the vector particle analysis report and high particle is an integer

I commented all of these lines out (I used them to compare particles and create variables like highParticle or highParticleCenterX etc.)
Reply With Quote
  #6   Spotlight this post!  
Unread 06-03-2012, 19:59
mikets's Avatar
mikets mikets is offline
Software Engineer
FRC #0492 (Titan Robotics)
Team Role: Mentor
 
Join Date: Jan 2010
Rookie Year: 2008
Location: Bellevue, WA
Posts: 671
mikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of light
Re: Camera code stops recieving images

Quote:
Originally Posted by Method View Post
reports->at(highParticle).center_mass_y;

I think lines like this may be what is guilty... is there anything wrong with this?

reports is the vector particle analysis report and high particle is an integer

I commented all of these lines out (I used them to compare particles and create variables like highParticle or highParticleCenterX etc.)
There are many things that could go wrong with that statement. Are you sure reports is not a NULL pointer? Are you sure highParticle contains a valid index etc?
__________________
Reply With Quote
  #7   Spotlight this post!  
Unread 06-03-2012, 21:21
Method's Avatar
Method Method is offline
Registered User
no team
 
Join Date: Jan 2012
Rookie Year: 2011
Location: Ca
Posts: 38
Method is an unknown quantity at this point
Re: Camera code stops recieving images

Yes, i am sure(within reasonable doubt).

It works for a few iterations before failing.
I had the 2 other team programmers look to check that everything was alright when this issue started (after I added code using those lines).

The CPU usage in the DS climbs when it starts using the camera and plateaus for a while while it works before stopping.

I could post before and after code if it would help. (this is reasonably short because it's simplified and camera-specific)

I delete everything I use in any loops which I make it in.
Reply With Quote
  #8   Spotlight this post!  
Unread 06-03-2012, 21:30
mikets's Avatar
mikets mikets is offline
Software Engineer
FRC #0492 (Titan Robotics)
Team Role: Mentor
 
Join Date: Jan 2010
Rookie Year: 2008
Location: Bellevue, WA
Posts: 671
mikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of light
Re: Camera code stops recieving images

Yeah, it would help to diagnose the issue with the surrounding code.
__________________
Reply With Quote
  #9   Spotlight this post!  
Unread 06-03-2012, 23:07
Method's Avatar
Method Method is offline
Registered User
no team
 
Join Date: Jan 2012
Rookie Year: 2011
Location: Ca
Posts: 38
Method is an unknown quantity at this point
Re: Camera code stops recieving images

Okay and thankyou!
Attached Files
File Type: zip Code.zip (2.5 KB, 20 views)
Reply With Quote
  #10   Spotlight this post!  
Unread 06-03-2012, 23:42
mikets's Avatar
mikets mikets is offline
Software Engineer
FRC #0492 (Titan Robotics)
Team Role: Mentor
 
Join Date: Jan 2010
Rookie Year: 2008
Location: Bellevue, WA
Posts: 671
mikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of light
Re: Camera code stops recieving images

Wait, which line is the culprit now? There is no line "reports->at(highParticle).center_mass_y;" in your alteredCode.cpp. I assume the workingCode.cpp is the working one and alteredCode.cpp is the one with problems, although I see more bugs in workingCode than alteredCode.
__________________

Last edited by mikets : 06-03-2012 at 23:54.
Reply With Quote
  #11   Spotlight this post!  
Unread 07-03-2012, 01:29
Method's Avatar
Method Method is offline
Registered User
no team
 
Join Date: Jan 2012
Rookie Year: 2011
Location: Ca
Posts: 38
Method is an unknown quantity at this point
Re: Camera code stops recieving images

The primary differences between the two files are

Code:
				centerX = reports->at(highParticle).center_mass_x_normalized;
and

Code:
				for (unsigned int i = 0; i < reports->size(); i++)
				{
					if(reports->at(i).center_mass_y > reports->at(highParticle).center_mass_y)
					{
						highParticle = i;
					}
				}
				for (unsigned int i = 0; i < reports->size(); i++)
				{
					if(reports->at(i).center_mass_y < reports->at(lowParticle).center_mass_y)
					{
						lowParticle = i;
					}
				}
Also, your assumption is correct. The working one does not stop while the other, (with the above changes), does after working briefly.

I commented out these lines and the code began to work again.
I also tried to make particle analysis report pointers like in the other file to compare results but that works in a similar fashion with the exception that when the code stops working instead of the CPU usage flat-lining it spikes and does not come down and the code stops as with the other way.

I apologize for any distracting extraneous code or any bugs in the 'working' version. It is a save from when I got the camera to work as I intended (my lesson learned- this being the second time)

Once again, thankyou.
Reply With Quote
  #12   Spotlight this post!  
Unread 07-03-2012, 01:43
mikets's Avatar
mikets mikets is offline
Software Engineer
FRC #0492 (Titan Robotics)
Team Role: Mentor
 
Join Date: Jan 2010
Rookie Year: 2008
Location: Bellevue, WA
Posts: 671
mikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of light
Re: Camera code stops recieving images

Okay, then the most logical explanation is that your reports->size() sometimes gives you zero, meaning that it can't find any target. In that case, your reference to particle 0 "reports->at(highParticle).center_mass_x_normalized;" will fault. To prove this, add something like this to your code. By switching this code, you will print out size() before you execute that centerX line that will fault. I'd bet, size() is zero.
Code:
numTargets = reports->size();
dsLCD->Clear();
dsLCD->Printf(DriverStationLCD::kUser_Line1, 1, "report width %d", convexHullImage->GetWidth());
 
//fix so is based on score
dsLCD->Printf(DriverStationLCD::kUser_Line2, 1, "size %d", reports->size());
dsLCD->UpdateLCD();
centerX = reports->at(highParticle).center_mass_x_normalized;
dsLCD->Printf(DriverStationLCD::kUser_Line3, 1, "center x %f", centerX);
dsLCD->UpdateLCD();
__________________
Reply With Quote
  #13   Spotlight this post!  
Unread 07-03-2012, 01:58
Method's Avatar
Method Method is offline
Registered User
no team
 
Join Date: Jan 2012
Rookie Year: 2011
Location: Ca
Posts: 38
Method is an unknown quantity at this point
Re: Camera code stops recieving images

thankyou; i will try that as soon as possible.
I will check in the for loops also (which do something similar)

Last edited by Method : 07-03-2012 at 02:05.
Reply With Quote
  #14   Spotlight this post!  
Unread 07-03-2012, 23:37
Method's Avatar
Method Method is offline
Registered User
no team
 
Join Date: Jan 2012
Rookie Year: 2011
Location: Ca
Posts: 38
Method is an unknown quantity at this point
Re: Camera code stops recieving images

That fixed it; thankyou very much
Reply With Quote
  #15   Spotlight this post!  
Unread 07-03-2012, 23:42
mikets's Avatar
mikets mikets is offline
Software Engineer
FRC #0492 (Titan Robotics)
Team Role: Mentor
 
Join Date: Jan 2010
Rookie Year: 2008
Location: Bellevue, WA
Posts: 671
mikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of light
Re: Camera code stops recieving images

I am glad that's fixed. In general, you need to add more "error checking" code and always assume the WPI library calls could fail. For example, all the calls that generate images such as ThresholdRGB, FilterImages etc could fail and return NULL pointers. If you don't check and use them, you will fault. It may be unlikely but it could happen under unusual circumstances. For example, here is an excerpt of our vision processing code. Note that it checked for errors after each WPI library call and at the end when deleting the objects, we called SAFE_DELETE which is a macro that basically check for NULL pointer before it deleted the object.
Code:
int err = ERR_SUCCESS;
BinaryImage *image = NULL;
BinaryImage *thresholdImage = NULL;
BinaryImage *bigObjImage = NULL;
BinaryImage *convexHullImage = NULL;
BinaryImage *filteredImage = NULL;
m_camera->GetImage(&m_cameraImage);
//
// Filter the image by color.
//
thresholdImage = m_cameraImage.ThresholdRGB(*m_colorThresholds);
image = thresholdImage;
if (thresholdImage == NULL)
{
    err = imaqGetLastError();
    TErr(("Failed to filter image with thresholds (err=%d).", err));
}
else if (m_sizeThreshold > 0)
{
    //
    // Remove small objects
    //
    bigObjImage = image->RemoveSmallObjects(false, m_sizeThreshold);
    image = bigObjImage;
    if (bigObjImage == NULL)
    {
        err = imaqGetLastError();
        TErr(("Failed to filter image with size (err=%d).", err));
    }
}
if (err == ERR_SUCCESS)
{
    convexHullImage = image->ConvexHull(false);
    image = convexHullImage;
    if (convexHullImage == NULL)
    {
        err = imaqGetLastError();
        TErr(("Failed to generate Convex Hull image (err=%d).", err));
    }
}
if ((err == ERR_SUCCESS) && (m_filterCriteria != NULL))
{
    filteredImage = image->ParticleFilter(m_filterCriteria, m_numCriteria);
    image = filteredImage;
    if (filteredImage == NULL)
    {
       err = imaqGetLastError();
       TErr(("Failed to filter image based on criteria (err=%d).", err));
    }
}
if (err == ERR_SUCCESS)
{
    vector<ParticleAnalysisReport> *reports =
        image->GetOrderedParticleAnalysisReports();
    if (reports == NULL)
    {
        err = imaqGetLastError();
        TErr(("Failed to get particle analysis reports (err=%d).", err));
    }
    else
    {
        CRITICAL_REGION(m_semaphore)
        {
            SAFE_DELETE(m_targets);
            m_targets = reports;
            reports = NULL;
        }
        END_REGION;
    }
}
SAFE_DELETE(filteredImage);
SAFE_DELETE(convexHullImage);
SAFE_DELETE(bigObjImage);
SAFE_DELETE(thresholdImage);
__________________

Last edited by mikets : 08-03-2012 at 00:00.
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 03:01.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi