Go to Post See, building a really great robot is just a pseudo challenge for the concept of the whole FIRST program. It is just a phony way to bring people together to reach one common goal. - sanddrag [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 20-01-2012, 20:53
Cody Trey's Avatar
Cody Trey Cody Trey is offline
Programing = hard + fun
FRC #2582 (Panther Bots)
Team Role: Programmer
 
Join Date: Jan 2011
Rookie Year: 2009
Location: US
Posts: 31
Cody Trey is an unknown quantity at this point
Send a message via Yahoo to Cody Trey
Post Particle Analysis Report Problems

I am trying to use camera tracking to track the reflective tape, but I am having problems with the frcParticleAnalysis function. I'm not sure how to use it. my code is:


#include "WPILib.h"

/**
* This is a demo program showing the use of the RobotBase class.
* The SimpleRobot class is the base of a robot application that will automatically call your
* Autonomous and OperatorControl methods at the right time as controlled by the switches on
* the driver station or the field controls.
*/
class RobotDemo : public SimpleRobot
{
RobotDrive myRobot; // robot drive system
Joystick stick; // only joystick
Jaguar jag1;
Jaguar jag2;
Solenoid Sol1 ;
Joystick stick2;
HSLImage image;
ParticleAnalysisReport par;
BinaryImage image2;



public:
RobotDemo(void):
myRobot(1, 3, 2, 10), // front left, rear left, front right, rear right
stick(1), //these must be initialized in the same order
jag1(7),
jag2(8),
Sol1(8),
stick2(2)


{
myRobot.SetExpiration(0.1);
}

/**
* Drive left & right motors for 2 seconds then stop
*/
void Autonomous(void)
{
myRobot.SetSafetyEnabled(false);
AxisCamera &camera = AxisCamera::GetInstance();
camera.WriteBrightness(0);
Wait(3.0);
myRobot.MecanumDrive_Cartesian(0.0, 0.0, 0.0, 0.0); // stop robot
while (!IsOperatorControl())
{
camera.GetImage();
frcParticleAnalysis(image2, 5, par); /*the error says "cannot convert 'BinaryImage' to 'Image*' for argument '1' to 'int frcParticleAnalysis (Image*, int, ParticleAnalysisReport*)'*/
}
}


/*
* Runs the motors with single stick holonomic steering.
* comment
*/
void OperatorControl(void)
{
while (IsOperatorControl())
{
myRobot.SetSafetyEnabled(true);
myRobot.MecanumDrive_Cartesian(stick.GetX(), stick.GetY(), stick.GetThrottle(), 0); // drive with arcade style (use right stick)
if(stick.GetTrigger())
jag2.SetSpeed(.8);
jag1.SetSpeed(.5);
Wait(.2);
Sol1.Set(true);
if(stick2.GetTrigger())
jag1.SetSpeed(.5);
else
Sol1.Set(false);
jag1.SetSpeed(0);
jag2.SetSpeed(0);
Wait(0.005); // wait for a motor update time
}
}


};

START_ROBOT_CLASS(RobotDemo);
__________________
Love, Peace, and Robot Grease
Reply With Quote
  #2   Spotlight this post!  
Unread 20-01-2012, 22:38
Bongle's Avatar
Bongle Bongle is offline
Registered User
FRC #2702 (REBotics)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2002
Location: Waterloo
Posts: 1,069
Bongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond repute
Send a message via MSN to Bongle
Re: Particle Analysis Report Problems

You declare your variable image2 as a BinaryImage*, which is why the compiler is having trouble. It sees parameter 1's type as "BinaryImage*", but it is looking for Image*. Also, you don't assign anything out of your call to camera.GetImage(). It should be something like image2 = camera.GetImage() [except that might not be the right type. Check out AxisCamera.h to find out what GetImage() returns].

I don't have the code in front of me, but it is likely that what you need to do is do something like this:

ColorImage colorImage;
camera.getImage(&colorImage);
frcParticleAnalysis(&colorImage, 5, par);


However, we had success last night doing something different. We did something very similar to this. It is unlikely the code below or above will compile, it's coming out of memory.
ColorImage img;
camera.getImage(&img);
BinaryImage* binImg = img.ThresholdRGB(192,256,192,156,192,256);
vector<ParticleAnalysisReport>* particles = binImg->GetOrderedReport(); // I don't remember this function's actual name
for(int x = 0;x < particles.size(); x++)
{
ParticleAnalysisReport& par = (*particles)[x];
// do something with par: look at par.center_mass_x, par.center_mass_y, etc.
}

Last edited by Bongle : 20-01-2012 at 22:52.
Reply With Quote
  #3   Spotlight this post!  
Unread 21-01-2012, 11:44
Cody Trey's Avatar
Cody Trey Cody Trey is offline
Programing = hard + fun
FRC #2582 (Panther Bots)
Team Role: Programmer
 
Join Date: Jan 2011
Rookie Year: 2009
Location: US
Posts: 31
Cody Trey is an unknown quantity at this point
Send a message via Yahoo to Cody Trey
Re: Particle Analysis Report Problems

Could you please post you actual code when you come in? It looks really good and I'd really like for my team to have camera tracking this year. Thanks so much!
__________________
Love, Peace, and Robot Grease
Reply With Quote
  #4   Spotlight this post!  
Unread 21-01-2012, 14:38
Cody Trey's Avatar
Cody Trey Cody Trey is offline
Programing = hard + fun
FRC #2582 (Panther Bots)
Team Role: Programmer
 
Join Date: Jan 2011
Rookie Year: 2009
Location: US
Posts: 31
Cody Trey is an unknown quantity at this point
Send a message via Yahoo to Cody Trey
Re: Particle Analysis Report Problems

this is my autonomous code as it stands now. can you guys help me figure out what to do/where to go from here.


void Autonomous(void)
{
myRobot.SetSafetyEnabled(false);
AxisCamera &camera = AxisCamera::GetInstance();
camera.WriteBrightness(0);
Wait(3.0);
myRobot.MecanumDrive_Cartesian(0.0, 0.0, 0.0, 0.0); // stop robot
while (!IsOperatorControl())
{
/** ColorImage &colorImagel;
camera.GetImage(&colorImage);
frcParticleAnalysis(&colorImage, 5, par); **/
HSLImage img;
camera.GetImage(&img);
BinaryImage* binImg = img.ThresholdRGB(192, 256, 192, 156, 192, 256);
vector<ParticleAnalysisReport>* par = binImg->GetOrderedParticleAnalysisReports(); //warning: unused variable 'par'
for(int x = 0; x < 5/**par.x**/; x++)
{
ParticleAnalysisReport& par = (*particles)[x]; //error: 'particles' undeclared (first use this function)
int x;
par.center_mass_x = x;

//do something with particles: par.center_mass_x & par.center_mass_y
}
}
}

thanks for the help
__________________
Love, Peace, and Robot Grease

Last edited by Cody Trey : 21-01-2012 at 14:39. Reason: for got to put a question...
Reply With Quote
  #5   Spotlight this post!  
Unread 21-01-2012, 15:35
Bongle's Avatar
Bongle Bongle is offline
Registered User
FRC #2702 (REBotics)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2002
Location: Waterloo
Posts: 1,069
Bongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond repute
Send a message via MSN to Bongle
Re: Particle Analysis Report Problems

Code:
void Autonomous(void)
	{
		myRobot.SetSafetyEnabled(false);
		AxisCamera &camera = AxisCamera::GetInstance();
		camera.WriteBrightness(0);
		Wait(3.0);
		myRobot.MecanumDrive_Cartesian(0.0, 0.0, 0.0, 0.0); 	// stop robot
		while (!IsOperatorControl())
		{
			ColorImage img;
			camera.GetImage(&img);
			BinaryImage* binImg = img.ThresholdRGB(192, 256, 192, 156, 192, 256);
			vector<ParticleAnalysisReport>* particles = binImg->GetOrderedParticleAnalysisReports();
			for(UINT32 x = 0; x < particles->size(); x++)
			{
				ParticleAnalysisReport& par = (*particles)[x]; 
				
				if(par.center_mass_x_normalized > 0) { /* turn right */ }
				else if(par.center_mass_x_normalized < 0) { /* turn left */ }
			}
		}
	}
This should get you started. The robot centering will be kinda jerky once you put the turning calls into myRobot, but should mostly work.

If you're focused JUST on autonomous however, don't forget the physical approach: put an aiming device on the robot, and have your drive team place and aim the robot using that. That removes the need to use the camera at all, mostly. You wouldn't get aiming in teleoperation mode, but if the goal is just autonomous, you can achieve it with just an on-robot aimer. It's actually what we did last year.

Last edited by Bongle : 21-01-2012 at 15:39.
Reply With Quote
  #6   Spotlight this post!  
Unread 21-01-2012, 16:26
Cody Trey's Avatar
Cody Trey Cody Trey is offline
Programing = hard + fun
FRC #2582 (Panther Bots)
Team Role: Programmer
 
Join Date: Jan 2011
Rookie Year: 2009
Location: US
Posts: 31
Cody Trey is an unknown quantity at this point
Send a message via Yahoo to Cody Trey
Re: Particle Analysis Report Problems

awesome, well I have one more error to fix then I can just wait until electrical and mechanical have there stuff finished...

BinaryImage* binImg = img.TresholdRGB(192, 256,156, 192, 256); //error: request for member 'ThresholdRGB' in 'image', which is of non-class type 'ColorImage*'

do I need to make img in to an RGB imag rather than just a Color Image?
__________________
Love, Peace, and Robot Grease
Reply With Quote
  #7   Spotlight this post!  
Unread 21-01-2012, 16:49
Bongle's Avatar
Bongle Bongle is offline
Registered User
FRC #2702 (REBotics)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2002
Location: Waterloo
Posts: 1,069
Bongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond repute
Send a message via MSN to Bongle
Re: Particle Analysis Report Problems

Quote:
Originally Posted by Cody Trey View Post
awesome, well I have one more error to fix then I can just wait until electrical and mechanical have there stuff finished...

BinaryImage* binImg = img.TresholdRGB(192, 256,156, 192, 256); //error: request for member 'ThresholdRGB' in 'image', which is of non-class type 'ColorImage*'

do I need to make img in to an RGB imag rather than just a Color Image?
You need to make it not a pointer.

The declaration for ColorImage should be:
ColorImage img;

From the compiler error, it sounds like you have
ColorImage* img;

That would be a pointer, which is why you can't do
img.ThresholdRGB(...)
Reply With Quote
  #8   Spotlight this post!  
Unread 21-01-2012, 16:59
Cody Trey's Avatar
Cody Trey Cody Trey is offline
Programing = hard + fun
FRC #2582 (Panther Bots)
Team Role: Programmer
 
Join Date: Jan 2011
Rookie Year: 2009
Location: US
Posts: 31
Cody Trey is an unknown quantity at this point
Send a message via Yahoo to Cody Trey
Re: Particle Analysis Report Problems

ok, when I do that i get

ColorImage img; //error: no matching function for call to 'ColorImgae::ColorImage()'
camera.GetImage(&img);

if you want I'll post the whole code as it stands now if you think it'll help
__________________
Love, Peace, and Robot Grease

Last edited by Cody Trey : 21-01-2012 at 17:01. Reason: forgot the '&'
Reply With Quote
  #9   Spotlight this post!  
Unread 21-01-2012, 17:12
Bongle's Avatar
Bongle Bongle is offline
Registered User
FRC #2702 (REBotics)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2002
Location: Waterloo
Posts: 1,069
Bongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond repute
Send a message via MSN to Bongle
Re: Particle Analysis Report Problems

Quote:
Originally Posted by Cody Trey View Post
ok, when I do that i get

ColorImage img; //error: no matching function for call to 'ColorImgae::ColorImage()'
camera.GetImage(&img);

if you want I'll post the whole code as it stands now if you think it'll help
Whoops, I forgot that ColorImage doesn't have a default constructor.

I believe it is:
ColorImage img(IMAQ_RGB_IMAGE);

You'll have to take a look at the constructor for ColorImage. Click on it, hit f3, and see what enumeration it requires. Hit f3 of the enumeration type, and it should take you to a list of options. You want the RGB one. Unfortunately, I'm once again at home, so I don't have our code in front of me.
Reply With Quote
  #10   Spotlight this post!  
Unread 21-01-2012, 17:26
Cody Trey's Avatar
Cody Trey Cody Trey is offline
Programing = hard + fun
FRC #2582 (Panther Bots)
Team Role: Programmer
 
Join Date: Jan 2011
Rookie Year: 2009
Location: US
Posts: 31
Cody Trey is an unknown quantity at this point
Send a message via Yahoo to Cody Trey
Re: Particle Analysis Report Problems

Quote:
Originally Posted by Bongle View Post
Whoops, I forgot that ColorImage doesn't have a default constructor.

I believe it is:
ColorImage img(IMAQ_RGB_IMAGE);

You'll have to take a look at the constructor for ColorImage. Click on it, hit f3, and see what enumeration it requires. Hit f3 of the enumeration type, and it should take you to a list of options. You want the RGB one. Unfortunately, I'm once again at home, so I don't have our code in front of me.
the constructor is IMAQ_IMAGE_RGB but it works now thanks!
__________________
Love, Peace, and Robot Grease
Reply With Quote
  #11   Spotlight this post!  
Unread 21-01-2012, 18:03
Bongle's Avatar
Bongle Bongle is offline
Registered User
FRC #2702 (REBotics)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2002
Location: Waterloo
Posts: 1,069
Bongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond repute
Send a message via MSN to Bongle
Re: Particle Analysis Report Problems

Quote:
Originally Posted by Cody Trey View Post
the constructor is IMAQ_IMAGE_RGB but it works now thanks!
As I'm always saying to our students - code compiling doesn't mean the code works :-)
Reply With Quote
  #12   Spotlight this post!  
Unread 21-01-2012, 22:03
Bryscus's Avatar
Bryscus Bryscus is offline
EE, CpE
AKA: Bryce B.
FRC #0180 (SPAM)
Team Role: Engineer
 
Join Date: Jan 2009
Rookie Year: 1999
Location: Jupiter, FL
Posts: 173
Bryscus has much to be proud ofBryscus has much to be proud ofBryscus has much to be proud ofBryscus has much to be proud ofBryscus has much to be proud ofBryscus has much to be proud ofBryscus has much to be proud ofBryscus has much to be proud ofBryscus has much to be proud of
Re: Particle Analysis Report Problems

If you run into issues tracking with an RGB image, try using HSL instead.

- Bryce
__________________
The opulence of the front office decor varies inversely with the fundamental solvency of the firm.
Reply With Quote
  #13   Spotlight this post!  
Unread 03-02-2012, 18:06
Cody Trey's Avatar
Cody Trey Cody Trey is offline
Programing = hard + fun
FRC #2582 (Panther Bots)
Team Role: Programmer
 
Join Date: Jan 2011
Rookie Year: 2009
Location: US
Posts: 31
Cody Trey is an unknown quantity at this point
Send a message via Yahoo to Cody Trey
Re: Particle Analysis Report Problems

Quote:
Originally Posted by Bongle View Post
As I'm always saying to our students - code compiling doesn't mean the code works :-)
I know... I meant built right...

Now that I've finially had a chance to test the code, I'm getting errors when we try to run it.

Quote:
<Code>-1074396120 ERROR: status = -1074396120 (0xBFF60428) Error counting particles: ...in GetNumberParticles() in C:/WindRiver/workspace/WPILib/Vision/BinaryImage.cpp at line 29


<Code>-1074396120 ERROR: status = -1074396120 (0xBFF60428) ImaqThreshold error: ...in ComputeThreshold() in C:/WindRiver/workspace/WPILib/Vision/ColorImage.cpp at line 37


<Code>-1074396120 ERROR: status = -1074396120 (0xBFF60428) Error counting particles: ...in GetNumberParticles() in C:/WindRiver/workspace/WPILib/Vision/BinaryImage.cpp at line 29
what do they mean? and...

do you think using a different image type would help?
__________________
Love, Peace, and Robot Grease
Reply With Quote
  #14   Spotlight this post!  
Unread 03-02-2012, 19:27
Bongle's Avatar
Bongle Bongle is offline
Registered User
FRC #2702 (REBotics)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2002
Location: Waterloo
Posts: 1,069
Bongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond repute
Send a message via MSN to Bongle
Re: Particle Analysis Report Problems

They're all probably related to the same error. You'd have to post the exact code you're using to call the ThresholdRGB function for me to have a clue.

Edit: the code I posted above that has the ThresholdRGB call has a problem. It should be
ThresholdRGB(192,256,192,256,192,256)

I put a 156 where 256 should have been.

Last edited by Bongle : 03-02-2012 at 19:30.
Reply With Quote
  #15   Spotlight this post!  
Unread 03-02-2012, 19:43
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: Particle Analysis Report Problems

I'm going to comment only on this single correction about the 156 versus 256...

Threshold takes 8-bit numbers for its thresholds. 256 is **NOT** an 8-bit number. 8-bit numbers range from (unsigned) 0-255 or (signed) -127 to 128. If you are passing 256 into this routine, you are likely passing a ZERO or an invalid number based upon the way Threshold processes it or passes it to the imaq functions.

255 is a MAX number ....

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 03:03.

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