View Single Post
  #9   Spotlight this post!  
Unread 07-02-2005, 22:59
russell's Avatar
russell russell is offline
Registered User
#1430 (WRONG)
Team Role: Electrical
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Anchorage AK
Posts: 402
russell is a name known to allrussell is a name known to allrussell is a name known to allrussell is a name known to allrussell is a name known to allrussell is a name known to all
Re: Autonomous With Camera

Quote:
Originally Posted by schenkin
Does just executing that camera track green color make the robot go towards green?
No it isnt quite that simple. Here is generall what I did (I am writing this from memory here so you will have to forgive possible problems in it):
in user_routines_fast.c
Code:
int counter=0; //define a counter in the beginning

then down in the autonomous part.....


if(counter==0)
  {
   camera_init(45,19,121);
   camera_auto_servo(1);
   camera_find_color(GREEN);
   }

if(camera_track_update()==1)
  {
   if (cam.size>0)
     {
      tracking=1;
      }
   else
      tracking=0;


if(tracking==1)
   {
    Ok now put some single joystick drive code here using the variable cam.pan_servo as the x axis of the joystick, and a constant value as the y axis
    }
else
  pwm11=pwm12=127;
Something like that. It is crude but it is working for me.

Basically what it does is when the program starts the first time it runs it initializes the camera (oh yeah you are gonna want to change those values in there to the ones you got from calibrating), then it sets it up to use auto servo then it tells it to track green. Then it checks to see if there is new data from the camera. If there is then it checks to see if it is tracking one or more pixels and if so it sets the variable "tracking" equal to one, and if it is not it sets it equal to 0. Then if tracking is equal to one it executes your drive code, and if not then it stops your motors. It is important to stop your motors so that when you loose sight of a target your robot doesnt go nuts.

If you have any questions please ask away, I am quite proud of this relatively simple code and I would love to answer any questions. Yeah, this is my first year programming....

Last edited by russell : 08-02-2005 at 00:38.