Go to Post We should have a rule in CD, no sad booboo faces that make you want to cry... - JaneYoung [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
 
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 04-02-2005, 20:38
schenkin schenkin is offline
Registered User
#0486
 
Join Date: Jan 2005
Location: Strath Haven High School
Posts: 17
schenkin is on a distinguished road
Autonomous With Camera

So, weve gotten tracking working just like everyone else here. I am trying to figure out how to move what we have in the normal mode to autonomous. Below are things I have to consider:

1. Setting which color we should use for tracking
2. Which functions must be called on in order for tracking to work properly


Has anyone gotten this to work properly? It seems to me that If i copy all the stuff in Default_Routine() function to the Default_Routine_Fast() function it should work. This means the following code:

camera_find_color(color) // Tells is what color to start tracking

and


if (p1_sw_trig > 0 && tracking > 0) { //If vision active and tracking use camera data
p1_y = speed_control; //set forward speed
p1_x = pan_position; //set turning rate
p1_x = 255 - p1_x; //invert turn direction
// Steering Compensation
if (p1_x > 135 && p1_x < 225 && steering_comp > 0)
p1_x = p1_x + steering_comp;
if (p1_x < 120 && p1_x > steering_comp && steering_comp > 0)
p1_x = p1_x - steering_comp;
pwm11 = Limit_Mix(2000 + ramp_y() + ramp_x() - 127); //uses our ramp
pwm12 = Limit_Mix(2000 + ramp_y() - ramp_x() + 127); //uses our ramp


Had anyone done this? I just wanted to share my thoughts.


--Sam
--Team 486
--Positronic Panthers
--Gotrobot.org



EDIT:

I just had a thought. Since the code to pick your color isn't in the Default_Routine() function, it is always running, even when the robot is disabled. This means that another way you can work setting up the camera is by mimicking the button controls. For instance:

I don't think i'll do this for changing the colors (it'll start looking for each color in turn), but it might be useful for the other functions. An important thing to remember is that there is no need to change the output variable when you can change the input one!

Last edited by schenkin : 04-02-2005 at 20:47.
  #2   Spotlight this post!  
Unread 04-02-2005, 21:39
schenkin schenkin is offline
Registered User
#0486
 
Join Date: Jan 2005
Location: Strath Haven High School
Posts: 17
schenkin is on a distinguished road
Re: Autonomous With Camera

I just realized:

One of the variables used by the code I copied earlier is external. This is the pan_position variable. Can I just define it as external and have it find it? The problem is that I can't just copy the code that creates it because that code runs in the normal loop and I don't want to screw up the timing. Suggestions?
  #3   Spotlight this post!  
Unread 04-02-2005, 22:35
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

I would love it if someone would write a white paper on this. It might seem obvious to some people, but to me (and probably a lot of others who are learning programming as they go) it is horribly confusing.
I have some ideas on how to do this, but the problem is that this is not one of those things I can do one step at a time, rather I have to do it all in one big step, then when it doesnt work I will have to try to find where in the mass of code the problem lies.
  #4   Spotlight this post!  
Unread 05-02-2005, 09:33
magical hands magical hands is offline
Jigar Patel
AKA: Jigar Patel
FRC #2185 (Etobicoke CI)
Team Role: Mentor
 
Join Date: Dec 2003
Rookie Year: 2004
Location: TORONTO
Posts: 93
magical hands is on a distinguished road
Re: Autonomous With Camera

Quote:
Originally Posted by russell
I would love it if someone would write a white paper on this. It might seem obvious to some people, but to me (and probably a lot of others who are learning programming as they go) it is horribly confusing.
I have some ideas on how to do this, but the problem is that this is not one of those things I can do one step at a time, rather I have to do it all in one big step, then when it doesnt work I will have to try to find where in the mass of code the problem lies.
I think I will try this idea and maybe give you guys some feedback on wether it will work or not and if it does than i will post it in white paper so others can see. But only if i am Successful! If you guys already started on this project than let me know this is my e-mail jigarjuhi@yahoo.ca
  #5   Spotlight this post!  
Unread 05-02-2005, 13:57
schenkin schenkin is offline
Registered User
#0486
 
Join Date: Jan 2005
Location: Strath Haven High School
Posts: 17
schenkin is on a distinguished road
Re: Autonomous With Camera

Ok, I think what i'm going to do is just make the function within Default_Routine() a function outside of the loop and then call on it within it. Then I can run that code from user_routines_fast(). Color selection will be accomplished by mimicking joystick button presses.

Not the most elegant, but it might work.

--Sam
--
--Team 486: Positronic Panthers
  #6   Spotlight this post!  
Unread 05-02-2005, 16:33
doyler doyler is offline
Rookie / Programmer
#0900 (Infinity)
Team Role: Programmer
 
Join Date: Oct 2004
Rookie Year: 2005
Location: Durham
Posts: 87
doyler is an unknown quantity at this point
Re: Autonomous With Camera

Depending on your autonomous strategy is what color you want. Possibly green if you want the vision tetra?

Here is what we have for tracking green autonomously

Code:
char look_for_green=1;

...

  while (autonomous_mode)   /* DO NOT CHANGE! */
  {

	if(look_for_green)
	{
		camera_find_color(GREEN);  
		look_for_green=0;
	}
__________________
  #7   Spotlight this post!  
Unread 05-02-2005, 17:20
Kevin Watson's Avatar
Kevin Watson Kevin Watson is offline
La Caņada High School
FRC #2429
Team Role: Mentor
 
Join Date: Jan 2002
Rookie Year: 2001
Location: La Caņada, California
Posts: 1,335
Kevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond repute
Re: Autonomous With Camera

Quote:
Originally Posted by schenkin
I just realized:

One of the variables used by the code I copied earlier is external. This is the pan_position variable. Can I just define it as external and have it find it? The problem is that I can't just copy the code that creates it because that code runs in the normal loop and I don't want to screw up the timing. Suggestions?
I've taken a first cut at getting all of the little bits of camera code into one source file. If you'd like to check it out, here's a link:

http://kevin.org/frc/frc_camera.zip

-Kevin
__________________
Kevin Watson
Engineer at stealth-mode startup
http://kevin.org
  #8   Spotlight this post!  
Unread 07-02-2005, 14:49
schenkin schenkin is offline
Registered User
#0486
 
Join Date: Jan 2005
Location: Strath Haven High School
Posts: 17
schenkin is on a distinguished road
Re: Autonomous With Camera

Does just executing that camera track green color make the robot go towards green?
  #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.
  #10   Spotlight this post!  
Unread 08-02-2005, 00:07
Sachiel7's Avatar
Sachiel7 Sachiel7 is offline
<Yes I managed to flip it
AKA: Shayne Helms
FRC #1132 (RAPTAR Robotics)
 
Join Date: Sep 2002
Rookie Year: 2002
Location: Richmond, VA
Posts: 541
Sachiel7 is just really niceSachiel7 is just really niceSachiel7 is just really niceSachiel7 is just really niceSachiel7 is just really nice
Send a message via AIM to Sachiel7
Re: Autonomous With Camera

What exactly is the cam.size variable?
Is your code waiting for the screen to be full of the color you're tracking?
I think a little more info would help me out, but I would like to say thanks for all the info, I'm finally getting a tracking mode started for our bot! I'll post it once it's done...
__________________
-=Sachiel7=-

There's no such thing as being too simple!
Look for Team #1132, RAPTAR Robotics at the VCU Regional this year!
  #11   Spotlight this post!  
Unread 08-02-2005, 00:32
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

The cam.size variable is the number of pixels the camera is tracking. I actually borrowed that idea from the default code. Let me edit that post and add an explanation.
  #12   Spotlight this post!  
Unread 09-02-2005, 22:05
neilsonster's Avatar
neilsonster neilsonster is offline
Registered User
AKA: Andrew Neilson
FRC #0772 (Sabre Bytes)
Team Role: College Student
 
Join Date: Jan 2005
Rookie Year: 2005
Location: Waterloo, ON, Canada
Posts: 188
neilsonster is a name known to allneilsonster is a name known to allneilsonster is a name known to allneilsonster is a name known to allneilsonster is a name known to allneilsonster is a name known to all
Send a message via MSN to neilsonster
Re: Autonomous With Camera

Hi, I am having some trouble implementing the camera code into the autonomous as well... Should I be #include-ing anything other than user_camera.h? Also, with the camera hooked up correctly it doesn't seem to be accessing the #if _USE_CMU_CAMERA sections of code in user_routines_fast, should I even be using that? I just need it to recognize the camera in autonomous!!! AHhhh!!
  #13   Spotlight this post!  
Unread 11-02-2005, 07:55
schenkin schenkin is offline
Registered User
#0486
 
Join Date: Jan 2005
Location: Strath Haven High School
Posts: 17
schenkin is on a distinguished road
Re: Autonomous With Camera

I just don't think you should have to initialize the variables. These variables are global aren't they? The only code you should have to change is that within the Default_Routine() loop. Everything else is run even when in autonomous mode.
  #14   Spotlight this post!  
Unread 12-02-2005, 10:12
Joe_P.'s Avatar
Joe_P. Joe_P. is offline
Registered User
AKA: Joe Jervis
None #1167 (Knightmare)
Team Role: Alumni
 
Join Date: Jan 2005
Rookie Year: 2005
Location: Savannah, Ga
Posts: 146
Joe_P. will become famous soon enoughJoe_P. will become famous soon enough
Send a message via AIM to Joe_P. Send a message via MSN to Joe_P. Send a message via Yahoo to Joe_P.
Re: Autonomous With Camera

ok, i understand how this code looks for one color, but what if we wanted it to look for two colors, like when we shift sides of the field? i am hoping it is not that time consuming, but if it is, that is ok.
  #15   Spotlight this post!  
Unread 13-02-2005, 04:20
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

I assume you mean you want to be able to track red, or blue depending on which team you are on? Hmmm. Is there some way your program can know which team you are on? If not then use a switch you can set for which team you are on, then when you are running those functions at the beginning have it say camera_find_color(thecolor); and earlier in the program have an if/then to make it set thecolor equal to red or blue (there are some numbers that represent the different colors... I think 4 and 5 respectively, but you might want to check that) based on the position of your switch. It is again, crude but it works.
If I were you though I would not use that code I posted above for your final program, I really only meant it as a model of what you can do, you will probably want to elaborate on it.
Closed Thread


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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Scripting Setup and the Camera + Serial Port Drivers CJO Programming 22 11-01-2006 17:42
Unresponsive camera neilsonster Programming 9 17-02-2005 08:51
CMUCam2 Camera Code - Are important parts commented out? Mr. Lim Programming 4 14-01-2005 12:11
autonomous mode problem on field Chris_C Programming 17 26-03-2003 19:11


All times are GMT -5. The time now is 23:50.

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