![]() |
Will camera keep running if i have a while statement going
I have a while statement in Default_Routine that starts when a button is pressed, keeps moving the drive motors until the target is strait ahead of the robot (the pan servo = 127), and then leaves the while loop.
Now here is my question... during the while loop will the camera keep tracking the target because it is interupt driven or will the while loop overide the camera's tracking interupts and just get me stuck in the loop because the camera wont update. i am trying to have my robot aim with it's drive wheels when i press a button |
Re: Will camera keep running if i have a while statement going
you cannot use while or for loops in the RC code.
The main loop of the code does something like this: 1. read all the sensor and OI inputs (including the camera) 2. execute all your code 3. update all the output (to the motors and servos...) goto 1 as you can see, a while loop in step 2 will hold up the entire program, and stop any further inputs or outputs to make matters worse, there is another processor in the RC that you do not have access to. If it sees the code is not updating the outputs at the normal rate it assumes your code has gone out to lunch, and it shuts the robot down. you need to use IF statements to check and see if the condition you are looking for is true. If not then let the code continue, and it will check again on its next loop through. |
Re: Will camera keep running if i have a while statement going
Well, you can use while or for loops - looping over an array is a good use, for example.
|
Re: Will camera keep running if i have a while statement going
i am just going to post what i have mabye someone can tell me haow i would do this without stopping my entire program. This is my first year programming for first and i have promised my team some nice "features". any help would be greatly appreciated
Code:
|
Re: Will camera keep running if i have a while statement going
yes, if you have a while loop that executes quickly, and that is not looking for a change in inputs, esp if its trying to change the outputs (motor speed) to make the inputs change.
using while loops to process data will also have the adverse effect of altering your code-loop time. |
Re: Will camera keep running if i have a while statement going
whats going to happen with your code, as soon as
WHILE locked = 0 becomes true, your while loop becomes an infinite loop - it never exits, so your code will never see new input values from the operator interface - it will act like the trigger never gets released but the supervisor uC will shut the robot down within a second or two anyway, and your bot will act like its been disabled. Also: your light scrolling- the code needs to flow though to the end before any outputs get updated, so the only output that would happen would be the last values you assign to each output variable. |
Re: Will camera keep running if i have a while statement going
wouldn't the last line in the final else statement break it out of the loop once it centers on the traget (the locked = 1). of course then i would still have the "Supervisor Uc" thing yall keep talking about to worry about so i guess it wouldn't work anyway....(not too mention the camera wont work in the loop Sorry for my confusion. I have programmed in a lot of other langauges besides C . I am just new to C and still trying to understand some of the stuff.
What if i put this code into the beginning of the while loop Code:
Getdata(&rxdata);it would almost be like making a super high priority interupt |
Re: Will camera keep running if i have a while statement going
Remove your while statement. Why? Because your code is already running inside of a while loop.
The loop your code runs inside of runs at 26.2ms per loop. Setting pwms and LEDs does not immediately change the actual hardware. That occurs later in the loop by the default code after your code is left. So making your light scrolling work needs delays between setting successive lights. It's not really a C question, it's about how the default code is set up (that you don't normally see). |
Re: Will camera keep running if i have a while statement going
so how would i do this without a while loop???
I understand what you are saying now... i just dont understand how i can fix it. if anyone could point me in the right direction or mabye even give me a little default code it would be greatly appreciated. I just dont understand how it would keep the tracking proccess going in the next loop of the "master while statement" but not have it happen every loop. I need it to only hapeen after the trigger is pressed and keep tracking till it is locked on |
Re: Will camera keep running if i have a while statement going
Servo_track() is the function which does the camera tracking. In your section of code you can set a global variable to turn camera tracking on/off. Then either add checking that variable before the call to Servo_Track() or add the check inside of Servo_Track() itself.
|
Re: Will camera keep running if i have a while statement going
Quote:
|
Re: Will camera keep running if i have a while statement going
I think you should be able to make your "locked" variable a static and change your "while" to an "if". As long as the trigger is being held, this code will be executed every time through the main loop. (I think this is approximately what DHoizner was suggesting.)
Code:
static int locked = 0; |
Re: Will camera keep running if i have a while statement going
Oops, Dan and Greg are right. I stand corrected. :)
|
Re: Will camera keep running if i have a while statement going
thanks to all the people who helped explain this too me. Yall have no idea how much this helped me. Everything just clicked in my head. I get it now. thanks again.
|
| All times are GMT -5. The time now is 16:47. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi