Go to Post I'm basically only posting this so that future Shaker Robotics kids will see it and tell themselves "never again"... - Chris is me [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 26-01-2012, 22:53
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
Comprehensive help for camera code

for(UINT32 x = 0; x < particles->size(); x++)
{
ParticleAnalysisReport& par = (*particles)[x];
if(par.center_mass_x_normalized > 0)
{
//right
}
if(par.center_mass_x_normalized < 0)
{
//left
}
}


This is a part of an example of tracking code.
I do not understand the purpose of the for, or why (*particles)[x] isn't just (*particles)
Is particles->size(); returning the number of particles or something? If so, wouldn't the code make the robot cycle through aiming at the different targets?
Reply With Quote
  #2   Spotlight this post!  
Unread 27-01-2012, 08:33
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: Comprehensive help for camera code

It would indeed attempt to drive towards each particle in turn. I forget if I posted that particular code snippet, but what you'd probably want would be something like this, where you select a favourite particle. For example, here's code that selects the biggest particle:

Code:
ParticleAnalysisReport biggest = {0};
for(UINT32 x = 0; x < particles->size(); x++)
{
  ParticleAnalysisReport& par = (*particles)[x];
  if(par.particleArea > biggest.particleArea) // particleArea may not be the right member... I'm going from memory.
  {
    biggest = par;
  }
}
if(biggest .center_mass_x_normalized > 0)
{
//right 
}
if(biggest .center_mass_x_normalized < 0)
{
//left
}
Of course, you may not want to drive towards the biggest particle, but rather the most backboard-shaped particle...

For your syntax question:
particles is a pointer to a vector<ParticleAnalysisReport>. Therefore, to call member functions on it like size(), you need to use the arrow operator. To call the square-bracket operator, you need to indirect it using the * first to get yourself a non-pointer vector<ParticleAnalysisReport>.

particles->size() tells you how many particles there are in the list of particles.

Last edited by Bongle : 27-01-2012 at 08:36.
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