Converting EasyC Tracking Code into MpLAB

Now our team this year decided to keep programming in MpLAB since over the past years we have become a little more familiar with and is easier for us to use. The problem with this is that Intellitek released a 2 target following code for their EasyC, now we have a problem converting that code into MpLAB. This is the code that we have extracted from EasyC:

void SeekLight(void)
{
unsigned char centroid_x;
unsigned char centroid_y;
unsigned char lowright_x;
unsigned char lowright_y;
unsigned char upleft_x;
unsigned char upleft_y;
unsigned char region_size;
unsigned char confidence;
int elevation;
char done = 0;
int xerror = 0;
int icentroid_x;
int target_width;
unsigned long timer = 0;
int target_x;
int rotation;
int old_rotation;
unsigned char targets = 0;

  elevation = Start_Elevation_PWM;
  rotation = Center_Camera_PWM;
  ClearScreen();
  while (!done) // go until finished
  	{
  		PrintFrameToGD ( 1, 1, 10, 20, 0);
  		PrintTextToGD ( 2, 2, 0, "Targeting Camera

");
PrintTextToGD ( 4, 2, 0, "Targets Found: %d
", (int)targets);
PrintTextToGD ( 6, 4, 0, "Pan%3d
", (int)(rotation - 127);
PrintTextToGD ( 8, 4, 9, "Tilt%d
", (int)(elevation - 127);
// get data from camera

  CaptureTrackingData (&centroid_x, &centroid_y, &upleft_x, &upleft_y, &lowright_x, &lowright_y, &region_size, &confidence, 0, 0);
  target_width = lowright_x - upleft_x; // Horizontal extents of bounding box
  icentroid_x = (int)centroid_x; // Move into integer variable
  if (target_width > Widest_One_Light) // Looking at two targets?
  	{
  	targets = 2;
  	if ((lowright_x - centroid_x) < (centroid_x - upleft_x))
  		{
  			//centroid is near the left
  			target_x = lowright_x - HALF_LIGHT_WIDTH;
  		}
  	else
  		{
  			// the centroid is nearer the left
  			target_x = upleft_x +HALF_LIGHT_WIDTH;
  		}
  	}
  else if (region_size > MIN_REGION)
  	{
  		targets = 1;
  		target_x = icentroid_x;	//target that light
  	}
  else // The target is not wide, it's one light
  	{
  	// SetCurPos (4, 18);
  		PrintToScreen ("0);
  		targets = 0;
  	}
  // PrintToScreen ("TargetX = %d

“, (int)target_x)
if (region_size > MIN_REGION) // Check if we’re locked
{
timer = GetTimer (TIMER_NUM); // is it time to recenter the tilter
if (timer > TILT_SAMPLE_RATE ); //# of milliseconds between samples
{
elevation = DistanceToPeg (elevation, centroid_y); // Center tilt, get distance
rotation = RotateToPeg (rotation, target_x);
//SetCurPos (6, 11);
//PrintToScreen (”%d “, rotation - 127);
//SetCurPos (7, 11);
//PrintToScreem (”%d ", elevation - 127);
PresetTimer (TIMER_NUM, 0); // Reset The Timer
}
}
}
}

As far as I can see this code basically finds the target and checks to see whether that target it found is bigger than the normal sized light, if so it would recognize that there are 2 lights and find the better one. I would really appreciate it if someone can clarify this code or maybe even help us convert it into MpLAB for use. I understand that the fuction PrintTextToGD of course acts as a printf function, and RotateToPeg, and DistanceToPeg are your Tilt and Pan Values. As for all other functions I have no idea where to start making this work. ANY Help at all is greatly appreciated. Thank you very much!

You could use WPILib with MPLAB or just use easyC Pro. It has a syntax highlighting C editor so you can type code just like in MPLAB.

Instead of trying to convert this code from easyC to MPLab you should check out Kevin’s libraries posted on: http://www.kevin.org/frc/

It has solid code ready for use with MpLab.

Is Kevin’s code able to track 2 simultanious targets?

The CMU camera doesn’t track multiple targets. The code you mention just looks at the size of the blob and dertermines how many tagets its seeing.

Search the forum for team 250’s Multiple Object tracking code. I believe it is a sticky in the CMUcam subforum or the programming forum.

This code uses the camera’s VW (Virtual Window) command to disect image seen and parse the image to track multiple objects with distinct bounding boxes.