|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
|||
|
|||
|
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
|
|||
|
|||
|
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
|
|||||
|
|||||
|
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
|
|||
|
|||
|
Re: Autonomous With Camera
Quote:
If you guys already started on this project than let me know this is my e-mail jigarjuhi@yahoo.ca |
|
#5
|
|||
|
|||
|
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
|
|||
|
|||
|
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
|
||||
|
||||
|
Re: Autonomous With Camera
Quote:
http://kevin.org/frc/frc_camera.zip -Kevin |
|
#8
|
|||
|
|||
|
Re: Autonomous With Camera
Does just executing that camera track green color make the robot go towards green?
|
|
#9
|
|||||
|
|||||
|
Re: Autonomous With Camera
Quote:
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;
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
|
||||
|
||||
|
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... |
|
#11
|
|||||
|
|||||
|
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
|
|||||
|
|||||
|
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
|
|||
|
|||
|
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
|
|||||
|
|||||
|
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
|
|||||
|
|||||
|
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. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
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 |