Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   Autonomous With Camera (http://www.chiefdelphi.com/forums/showthread.php?t=33989)

schenkin 04-02-2005 20:38

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!

schenkin 04-02-2005 21:39

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?

russell 04-02-2005 22:35

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.

magical hands 05-02-2005 09:33

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

schenkin 05-02-2005 13:57

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

doyler 05-02-2005 16:33

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;
        }


Kevin Watson 05-02-2005 17:20

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

schenkin 07-02-2005 14:49

Re: Autonomous With Camera
 
Does just executing that camera track green color make the robot go towards green?

russell 07-02-2005 22:59

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. :D Yeah, this is my first year programming....

Sachiel7 08-02-2005 00:07

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...

russell 08-02-2005 00:32

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.

neilsonster 09-02-2005 22:05

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!!

schenkin 11-02-2005 07:55

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.

Joe_P. 12-02-2005 10:12

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.

russell 13-02-2005 04:20

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.


All times are GMT -5. The time now is 09:15.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi