![]() |
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! |
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? |
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. |
Re: Autonomous With Camera
Quote:
|
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 |
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; |
Re: Autonomous With Camera
Quote:
http://kevin.org/frc/frc_camera.zip -Kevin |
Re: Autonomous With Camera
Does just executing that camera track green color make the robot go towards green?
|
Re: Autonomous With Camera
Quote:
in user_routines_fast.c Code:
int counter=0; //define a counter in the beginningBasically 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.... |
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... |
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.
|
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!!
|
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.
|
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.
|
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. |
Re: Autonomous With Camera
Quote:
Josh |
Re: Autonomous With Camera
Hmmmm, good point. It does increment the counter in the program I am running on the bot, and other than that the only differences in the functional part (I never comment my actual code :)) are that a) right now it tracks red, not green (for a demonstration tomorrow that could get us nine grand) and b) it doesnt say to put the drive code here, instead it uses a modified version of the default drive code. I realised today that I have not actually put the robot on the floor and had it drive with this code, but I have had it on blocks and it tracks nicely and the wheels definetly turn in the right directions. I will let you know after our demo tomorrow if it actually works :D .
|
Re: Autonomous With Camera
That demo sounds sweet, hope that went well for you. I have seen our robot a total of 2 times, so its a bit tough for me to experiment with the code, so I appreciate your help. I still dont understand exactly what is going on with the camera, but I think I know enough now to scrape an auto mode together. I had tested something similiar to your code, but the bot may have been tracking the wrong direction or something, it was acting weird. I dont like the way the default camera code sets turning/forward speed so I think I am just going to make my own code. Again, thanks, and good luck
Josh |
Re: Autonomous With Camera
Ah. Well, the demo thingy is over and the bot sort of worked. But like I said I wrote that code I posted from memory, and come to find out I would have been better off using that, as in my code for the bot I neglected to put an else to stop the motors. Ever seen what a robot can do to a vending machine? Actually it hit the side so nothing actually broke but it was still cool. As it was though the people were still very impressed and I think we will get the money, I was just very annoyed with myself. Anyway, yeah once I fixed that it worked just fine.
|
Re: Autonomous With Camera
im sure that someone has asked this before. but what are the numerical values for the range of the servo on the camera? is it -127 to 127 or what? is it 0 to 254 like the robot? need some help with this please.
|
Re: Autonomous With Camera
It is the normal 0-254 type number, but the range is somewhat decreased, I think the functional range is something like 47-212 or something along those lines. It says in one of the documents in the getting started file.
|
| All times are GMT -5. The time now is 06:06. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi