programming help needed

Our programmers are having trouble figuring out how to lock onto one light when two of them are on during autonomous! Wondering if any one could help us out, please post if you can!


I was a programmer last year, but this year I’m on electrical/leadership. So while I know in general terms what we’re talking about, I don’t have any specific experience this year with the camera. That being said, here’s my idea: would it be possible (if you find yourself between two lights) to pick one and turn yourself toward it until you can’t see the other one? If your camera is unhappy turning, then try turning the robot.

I’ll think about this more and try to come up with another answer if that doesn’t work for you.

Best wishes,
Paul Dennis

From what I know it only sees the center of (mass, light, whatever) right? Like it will end up somewhere between the two lights. I think someone told me that somewhere in the code, dont take me for certain I havent touched on this problem yet in our code, the camera is takeing the highest, lowest, furthest right, and furthest left points of light. It uses them to find the center. Well I think that perhaps if you wanted a robot to lock onto one specifically, left or right, top or bottom, you could use those points to get it at least closer to the target.

It wont be perfect, but if it works it will probably put the center target at the (right)(left)(top)(bottom) of the target, whatever one you chose. Best I can think of right now. Just look through the camera code to see if you cant find the part that picks out those points and decides on the center. It might take a bit of work, but its not impossible.

Basically, you want to look at the ratio of width (x2-x1) to height (y2-y1). This will tell you if there are two lights.

Something else you can look at as well is the number of pixels (the variable is called “pixels”)… and it’s ratio to the area width*height… unfortunately keep in mind that these are all unsigned chars, so it means that the limit is 255 for all values.

I’m pasting the EasyC example code segment about how the demo determined if it was one or two lights:

#define MIN_REGION          0
#define WIDEST_ONE_LIGHT    30
#define HALF_LIGHT_WIDTH    3


// get data from camera
CaptureTrackingData ( &centroid_x , &centroid_y , &upleft_x , &upleft_y , &lowright_x , &lowright_y , &region_size , &confidence , 0 , 0 ) ;
targets = 0;
if ( region_size > MIN_REGION  ) { // Check if we're locked
	icentroid_x = (int)centroid_x ; // move into integer variable
	int target_width = lowright_x - upleft_x ; // Horizontal extents of bounding box
	if ( target_width > WIDEST_ONE_LIGHT  ) { // looking at two lights?
		targets = 2;
		// pick the closer one of the two lights.
		if ( ( lowright_x - centroid_x) < (centroid_x - upleft_x) ) {
			// the centroid is nearer the right 
			target_x = lowright_x- HALF_LIGHT_WIDTH  ;
		} else {
			// the centroid is nearer the left
			target_x = upleft_x + HALF_LIGHT_WIDTH  ;
	} else { // the target is NOT wide, it's one light
		targets = 1;
		target_x = icentroid_x; // target that light

That code basically checked if the width was greater than a constant, and then decided it was two targets instead of one.

Now, I would suggest aiming for the opposite side of the median, which, when you are exactly at the middle, will be the same as the center coordinate:
(lowright_x + upleft_x - icentroid_x) – that is… the flip image of the centroid…
or in normal C, it would be (x2 + x1 - mx)