|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
|||
|
|||
|
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? |
|
#2
|
|||||
|
|||||
|
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.) |
|
#3
|
|||
|
|||
|
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)
pwm11=50;
|
|
#4
|
||||
|
||||
|
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 :^) Last edited by KenWittlief : 03-02-2006 at 13:33. |
|
#5
|
|||||
|
|||||
|
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.
|
|
#6
|
|||
|
|||
|
Re: problem with using a loop
while noone touches the joystick the wheels will go to their standard position
|
|
#7
|
|||||
|
|||||
|
Re: problem with using a loop
You definitely want an if statement.
Code:
if ( (p1_x > 122) && (p1_x < 132) && rc_dig_in01 )
pwm11 = 50;
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. |
|
#8
|
|||||
|
|||||
|
Re: problem with using a loop
Quote:
What you probably wanted was this: Code:
while(p1_x == 127 && rc_dig_in01)
pwm11=50;
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Loop time for OperatorControl function? Debug blows... | Chris_Elston | Programming | 10 | 13-02-2006 14:42 |
| While Loop Require in OperatorControl? | Chris_Elston | Programming | 2 | 15-01-2006 14:29 |
| Need a realistic Statics Problem | sanddrag | Technical Discussion | 10 | 05-12-2005 15:07 |
| arm-limitting gyro PD loop producing some strange results | ZZII 527 | Programming | 8 | 16-02-2005 02:30 |
| Rewriting main loop | Max Lobovsky | Programming | 4 | 04-01-2005 18:35 |