Go to Post FIRST encourages us to innovate and try new things, lets do the same for them. - Katie_UPS [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 19-03-2012, 18:18
thecakeisalie's Avatar
thecakeisalie thecakeisalie is offline
Registered User
FRC #0293
 
Join Date: Mar 2012
Location: Pennington
Posts: 37
thecakeisalie is an unknown quantity at this point
Vision Code question.

Having finished writing the vision code, I tested our vision code. The only problem is that it did not seem to work.
if you can pinpoint our problem, it would be very helpful. This is my first year coding camera code in c++, so... i expect many things to go wrong

the vision.h:
Code:
#ifndef VISION_H
#define VISION_H
#include "WPILib.h"

class Vision {
private:
	AxisCamera * camera;

public:
	Vision();
	int Height();
	int Center_Mass();
	double GetDistance(int h);
};

#endif
the vision.cpp:
Code:
#include "../Robotmap.h"
#include "Vision.h"
#include <math.h>
#define PI 3.14159265


Vision::Vision() {
camera ->GetInstance("10.02.93.15");
}
int Vision::Center_Mass()
{
	ParticleFilterCriteria2 criteria[] = {
						{IMAQ_MT_BOUNDING_RECT_WIDTH, 30, 400, false, false},
						{IMAQ_MT_BOUNDING_RECT_HEIGHT, 40, 400, false, false}
				};
			ColorImage *image = camera->GetImage();
			Threshold threshold(10, 255, 200, 255, 150, 255);
			BinaryImage *thresholdImage = image->ThresholdRGB(threshold);
			BinaryImage *bigObjectsImage = thresholdImage->RemoveSmallObjects(false, 2);  // remove small objects (noise)
			BinaryImage *convexHullImage = bigObjectsImage->ConvexHull(false);  // fill in partial and full rectangles
			BinaryImage *filteredImage = convexHullImage->ParticleFilter(criteria, 2);  // find the rectangles
			vector<ParticleAnalysisReport> *reports = filteredImage->GetOrderedParticleAnalysisReports();  // get the results				

			ParticleAnalysisReport *r = &(reports->at(1));
			int center_mass_x =  r->center_mass_x; // int, in pixels

			
			delete reports;
			delete filteredImage;
			delete convexHullImage;
			delete bigObjectsImage;
			delete thresholdImage;
			delete image;
			
			return center_mass_x;
}
and the aiming part:
Code:
	while (vision->Center_Mass() <159 || vision->Center_Mass() > 161){
		while (vision->Center_Mass() < 159){
			turret->DriveMotor(0.1);
			if (vision->Center_Mass() > 159) break;
		}
		while (vision->Center_Mass() > 161){
			turret->DriveMotor(-0.1);
			if (vision->Center_Mass() < 161) break;
		}
	}

Last edited by thecakeisalie : 19-03-2012 at 18:53.
Reply With Quote
  #2   Spotlight this post!  
Unread 20-03-2012, 14:43
frdrake frdrake is offline
Registered User
FRC #0233
 
Join Date: Feb 2012
Location: Melbourne
Posts: 23
frdrake is on a distinguished road
Re: Vision Code question.

There's obviously some parts missing (declarations for your targeting code like vision and center mass, so this is assuming those are right). Have you verified yet that the center of mass X you're finding in the image processing is the same as the value being passed into your targeting code?
Reply With Quote
  #3   Spotlight this post!  
Unread 20-03-2012, 15:37
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: 667
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: Vision Code question.

Also note that the first particle in the list is particle 0 not particle 1. Unless you have a reason to skip particle 0, that could be one of the bugs. In addition, you should not blindly access the particle array within checking the particles->size(). It is possible that the vision code found no target. In that case, your code will fault.
__________________
Reply With Quote
  #4   Spotlight this post!  
Unread 24-03-2012, 21:50
thecakeisalie's Avatar
thecakeisalie thecakeisalie is offline
Registered User
FRC #0293
 
Join Date: Mar 2012
Location: Pennington
Posts: 37
thecakeisalie is an unknown quantity at this point
Re: Vision Code question.

Thanks for the suggestions. I have heavily modified our vision code so that it should work now. Unfortunately, due to the lack of time plus the fact that it seems that we are capable of aiming the camera quite well with just the stream on the driverstation, we may not need to use the targeting code at all this year. However, it was great practice for next year
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 02:34.

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