Go to Post Stop being LAWYERS and start being ENGINEERS! - dlavery [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

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Spotlight this post!  
Unread 13-02-2012, 03:23
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
simple camera feed and LCD output

Hi!
I was just wanting to check that this is working correctly and make it available if so

I have a problem where enabling code would bring robot code and comms down till i reboot

I made this by cutting huge sections out of my code, simplifying them(I was separating R G and B then comparing particles[in separate files]), then putting them in the vision example


Code:
#include "WPILib.h"
#include "Vision/RGBImage.h"
#include "Vision/BinaryImage.h"

#define RL 200
#define RH 260
#define GL 140
#define GH 210
#define BL 90
#define BH 135

static AxisCamera &eyeOfSauron = AxisCamera::GetInstance("10.16.71.11");
DriverStationLCD* driverOut = DriverStationLCD::GetInstance();
//for smart dashboard

class VisionSample2012 : public SimpleRobot
{
DriverStationLCD* driverOut;
Joystick pilot;
public:
	VisionSample2012(void):
		pilot(1)
	{
		GetWatchdog().Kill();
		driverOut  = DriverStationLCD::GetInstance();

		//eyeOfSauron.WriteBrightness(30);
		//eyeOfSauron.WriteWhiteBalance(AxisCamera::kWhiteBalance_Hold);
		eyeOfSauron.WriteResolution(AxisCamera::kResolution_320x240);
		//eyeOfSauron.WriteColorLevel(100);
		//eyeOfSauron.WriteCompression(30);
		//lower easier on CRIO and harder on cam
		eyeOfSauron.WriteMaxFPS(5);
	}
	
	void Autonomous(void)
	{
		GetWatchdog().Kill();		
		while (IsAutonomous() && IsEnabled()) 
		{
			GetWatchdog().Kill();
			CamAnOut();
		}
	}
	void OperatorControl(void)
	{
		GetWatchdog().Kill();
		while (IsOperatorControl())
		{
			GetWatchdog().Kill();
			CamAnOut();
		}
	}
	void CamAnOut (void)
	{
		Threshold threshold(RH, RL, GH, GL, BH, BL);
		ParticleFilterCriteria2 criteria[] = {
											{IMAQ_MT_BOUNDING_RECT_WIDTH, 10, 200, false, false},
											{IMAQ_MT_BOUNDING_RECT_HEIGHT, 10, 200, false, false}};
//											false Set this element to TRUE to take calibrated measurements.
//											fales Set this element to TRUE to indicate that a match occurs when the measurement is outside the criteria range

//			ColorImage *image;
//			image = new RGBImage("/10ft2.jpg");		// get the sample image from the cRIO flash
				
		ColorImage image(IMAQ_IMAGE_RGB);
		//make image
		eyeOfSauron.GetImage(&image);
		//store camera feed to image
		BinaryImage *thresholdImage = image.ThresholdRGB(threshold);
		//pixel range
		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> *particles = filteredImage->GetOrderedParticleAnalysisReports();
		// get the results
		
		//LCD output
		if (IsAutonomous())
			driverOut->Printf(DriverStationLCD::kUser_Line1, 1, "Autonomous");
		else if (IsOperatorControl())
			driverOut->Printf(DriverStationLCD::kUser_Line1, 1, "Operat	or");

	//too many, or too few targets?  If not, how many?
		if (particles->size() == 0)
			driverOut->Printf(DriverStationLCD::kUser_Line2, 1, "loosen filter");
		else if (particles->size() > 4)
			driverOut->Printf(DriverStationLCD::kUser_Line2, 1, "tighten filter");
		else
		{								//TRY I
			driverOut->Printf(DriverStationLCD::kUser_Line2, 1, "Number of targets: %d", particles->size());
		}
		
		//update the LCD on the DS
		driverOut->UpdateLCD(			);
		
//delete reports;
		delete filteredImage;
		delete convexHullImage;
		delete bigObjectsImage;
		delete thresholdImage;
		delete &image;
	}
};

START_ROBOT_CLASS(VisionSample2012);
Reply With Quote
 


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 17: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