Go to Post Welcome to ChiefDelphi a month before Kick-Off. This is an annual traditional experience for quite a few regulars. - synth3tk [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 27-01-2012, 23:04
scottbot95 scottbot95 is offline
Registered User
FRC #1388 (Eagle Robotics)
Team Role: Programmer
 
Join Date: Jan 2010
Rookie Year: 2010
Location: Arroyo Grande, CA
Posts: 46
scottbot95 is an unknown quantity at this point
Uncaught C++ Exception

I have vision code that will detect the target and will spit the number of particles found to the console. But whenever it looses targets, it gives the following error:
Code:
(FRC_RobotTask): Uncaught C++ Exception (#1)!
It then says the memory addresses of the call stack.

Here's my code
Code:
#include "Vision.h"
#include "../Robotmap.h"

Vision::Vision() : Subsystem("Vision") {
	printDebug("Initializing Camera Settings.");
	
	// Get an instance of the camera
	AxisCamera &camera = AxisCamera::GetInstance(CAMERA_IP);
	
	// Write some configuration to the camera
	camera.WriteResolution(CAMERA_RESOLUTION);
	camera.WriteCompression(CAMERA_COMPRESSION);
	camera.WriteBrightness(CAMERA_BRIGHTNESS);
	camera.WriteMaxFPS(CAMERA_FPS);
	camera.WriteColorLevel(CAMERA_COLOR_LEVEL);
	
	
	printDebug("Done Configuring Camera.");
	
	lightRing = new Relay(DEFAULT_DIGITAL_MODULE, LIGHT_RING_PORT, Relay::kForwardOnly);
}
    
void Vision::InitDefaultCommand() {
	// Set the default command for a subsystem here.
	//SetDefaultCommand(new MySpecialCommand());
}

vector<ParticleAnalysisReport> Vision::particleAnalysis()
{
	// Get an instance of the Axis Camera
	AxisCamera &camera = AxisCamera::GetInstance(CAMERA_IP);
	
	// check if there is a new image
	if (camera.IsFreshImage())
	{
		// Get the Image
		ColorImage *colorImage = camera.GetImage();
		BinaryImage *binImage = colorImage->ThresholdRGB(0,175,175,255,0,175);
		
		printDebug("Getting Particle Analysis Report.");
		vector<ParticleAnalysisReport> *temp = binImage->GetOrderedParticleAnalysisReports();
		particles = *temp;
		delete temp;
		
		printDebug("Stepping through particle report to remove particles with area too small.");
		// Step through the particles and elimate any that are too small
		for (UINT8 i = 0; i<particles.size(); i++) {
			if(particles.at(i).particleArea<MIN_PARTICLE_AREA)
			{
				// Erase the current particle from view
				particles.erase(particles.begin()+i-1);
				
				// Because erasing an element actually adjusts all elements
				// after the current one, we need to bump <tt>i</tt> down one
				i--;
			}
		}
		
	}
	
	printDebug("Done processing image.");
	
	targetParticle = particles.at(0);
	
	return particles;
}

void Vision::setTargetParticle(int index)
{
	targetParticle = particles.at(index);
}

double Vision::getNormalizedPosition()
{
	return targetParticle.center_mass_x_normalized;
}
Reply With Quote
  #2   Spotlight this post!  
Unread 28-01-2012, 00:34
bob.wolff68's Avatar
bob.wolff68 bob.wolff68 is offline
Da' Mentor Man
FRC #1967
Team Role: Mentor
 
Join Date: Jan 2012
Rookie Year: 2007
Location: United States
Posts: 157
bob.wolff68 is just really nicebob.wolff68 is just really nicebob.wolff68 is just really nicebob.wolff68 is just really nicebob.wolff68 is just really nice
Re: Uncaught C++ Exception

Hi,
I have some concern about the idea of assigning 'particles = *temp' and deleting temp rather than simply USING temp-> in the routine and then deleting temp at the end, but that isn't looking like the culprit. I see
Code:
			targetParticle = particles.at(0);
as a big issue -- when there are no particles at all in the image, particles.size() or temp->size() if not deleted are zero. This means you CANNOT assign targetParticle = particles.at(0); as there is NO ZEROTH ELEMENT at that time. If you, instead, carefully deal with placing that part inside an
Code:
if (particles.size()) {
  targetParticle = particles.at(0);
  flagNoParticles = false;
}
else
  flagNoParticles = true;
then that part won't crash. HOWEVER, it seems that elsewhere in the code you are counting on targetParticle to be valid. You might have to be a little creative (using a flag or re-thinking your logic) in treating this special case such that where you are counting on targetParticle, you are checking to see if you are in the situation where there are none instead and just returning in those cases. It's a little hard to describe in words...if this isn't clear, maybe we could talk it out on the phone.

bob
__________________
~~~~~~~~~~~~~~~~~~~
Bob Wolff - Software from the old-school
Mentor / C / C++ guy
Team 1967 - The Janksters - San Jose, CA
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 14:17.

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