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:
(FRC_RobotTask): Uncaught C++ Exception (#1)!
It then says the memory addresses of the call stack.
Here’s my 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;
}