![]() |
problem with using a loop
when I use the while function it always stucked in a few seconds in this mplab
what should i do? |
Re: problem with using a loop
You should show us the section of the program you're talking about. You should tell us what you expect it to do. You should tell us exactly what it is doing instead.
(And you should probably let us know what you mean when you say "this mplab", because I'm pretty sure most of us think MPLab is the program that we run on a Windows PC in order to write and compile programs for the robot.) |
Re: problem with using a loop
This is the MPLAB you know lol...
anyway I mean for any loop like Code:
while(p1_x=127 && rc_dig_in01) |
Re: problem with using a loop
The SW in the robot runs in a loop (the main loop). About 38 times a second it reads all the inputs, executes your code, then sets all the outputs to there new values.
If you stick a WHILE or FOR loop in you code, then this main loop is stopped until your loop completes. This means no more inputs will be read, no more outputs will be updated. For this reason, you cannot use WHILE or FOR loops in your code. There is also a second processor handling the Inputs and Outputs on a higher level. When it sees your code has stopped updating the outputs every 26mS, it assumes your code has crashed, and it shuts down the controller. EDITED FOR CORRECT TIMING: The communication loop runs about 38 times a second, every 26.2 milliseconds. (thanks Alan :^) |
Re: problem with using a loop
What do you expect that code to do? It's very likely that you want to use an if statement, not a while.
|
Re: problem with using a loop
while noone touches the joystick the wheels will go to their standard position
|
Re: problem with using a loop
You definitely want an if statement.
Code:
if ( (p1_x > 122) && (p1_x < 132) && rc_dig_in01 )Note that I made it test to see that p1_x is in a range around 127, instead of exactly 127. Joysticks will almost never return to exactly center when you let go of them, and the center point will sometimes change with time. |
Re: problem with using a loop
Quote:
What you probably wanted was this: Code:
while(p1_x == 127 && rc_dig_in01) |
| All times are GMT -5. The time now is 01:33. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi