Camera Range Finding

Ok I am new to programming, but I am supposed to be figuring out how we can use the camera this year. Now it looks easy enough to make the robot get to the vision tetra, but obviously it needs to know when it gets there. My first thought was to use one of the light sensors from last year and turn up the sensitivity so they would see any reflected light from a tetra, but that seemed kind of iffy. Now I am thinking of using the tilt of the camera to compute the range of the target. My plan was to run a cable from the tilt servo port on the camera then split it and run one end to the servo, and another to the RC, then monitor the signal on this cable in order to tell where the servo was supposed to be, then when it gets to the proper angle it starts up the code that makes the robot pick up the tetra. But just now I was going over the code and I noticed this in user_routines_DDT.c:

/********************************************
** VISION VARIABLES **
*********************************************/
int pan_dir=0;
int state=0;
int latch=0;
int latch2=0;
extern unsigned int index_ptr;
extern unsigned int data_rdy;
extern cam_struct cam;

int color=0;
const int steering_comp = 30; //steering compenstation (0 to 127)
const int speed_setting = 150; //forward speed setting (127 to 254)
extern int pan_position,tilt_position,tracking;
unsigned int speed_control;

Notice that on the second to the last line it seems to be setting up a variable that monitors the tilt position. Can someone tell me whether my analysis is correct, and how I can access this for an if/then statement basically saying that if this value is above or below a certain number it needs to do something.

Yes. This is precisely why they have the camera on the TTL port: so you can have access to all of the data, including the servo positions.

Ok. Thanks. Do you know what format that number is in? Is it the pwm value being sent to the tilt servo? And regardless of its format could I do something like this:

if (tilt_position =< x)
{
CODE FOR PICKING UP THE TETRA
}

where x is the value which represents the camera angle at which I want it to start executing the pick up the tetra code?

cam.tilt_servo is the variable for your “tilt_position” and will return your tilt servo position as a value from 0 to 255.

FYI, camera_track_update in camera.c has a pretty good breakdown on what useful values you can read from the camera in tracking mode.


int camera_track_update(void)
{
  int i;

  if(wait_for_data()==0) return 0;
 
  if(cam_uart_buffer[0]=='T' && cam_index_ptr>=9)
    {
	  cam.x=cam_uart_buffer[1];
	  cam.y=cam_uart_buffer[2];
	  cam.x1=cam_uart_buffer[3];
	  cam.y1=cam_uart_buffer[4];
	  cam.x2=cam_uart_buffer[5];
	  cam.y2=cam_uart_buffer[6];
	  cam.size=cam_uart_buffer[7];
	  cam.conf=cam_uart_buffer[8];
	  if(cam_index_ptr>9)
		{
		  cam.pan_servo=cam_uart_buffer[9];
		  cam.tilt_servo=cam_uart_buffer[10];
		}
	  reset_rx_buffer();
	  return 1;
    }
  // Bad data in buffer
  reset_rx_buffer();
  return 0;
}

Good luck!

-SlimBoJones…

Where can we find the camera code, and is there a script we are supposed to use? We are new at programming and we have no idea how to program teh camera…

Thnx

Fred

At least as of yesterday the camera code is not officially available. I think. Basically for the first few days innovation first had the code on their website, then they took it away and made it say that they are still working on the code.

ok, thanks

Hey, russel, I think basically that you would use the readings from the servos to tirnagulate the distance. Basically, you know the height of the camera, and you know one of the angle, and so you can triangulate the second side using a sin function, not too hard to do… Thats why its nice havign the servo output readings… After looking I didn’t find anything like that currently in the code but it would not be hard to write a little alogrithm to do that…

Peace up.

As far as I know the camera code included in the IFI default code is the official version, but it may be updated into the season. The user interface for the computer is here but this page also contains a notice saying that new default code with the camera will be out shortly. They may have just forgotten to update this when they posted the camera default code, or there will be a revision soon.

well maybe for the target it will work, but for finding the tetra the issue is that of camera is most likely not going to have to tilt the camera once it finds the tetra to follow it. Weve tried to mess around with this, but have had no sucess