Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   problem with using a loop (http://www.chiefdelphi.com/forums/showthread.php?t=43223)

CompMaster 03-02-2006 12:08

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?

Alan Anderson 03-02-2006 12:21

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.)

CompMaster 03-02-2006 12:36

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;


KenWittlief 03-02-2006 12:45

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 :^)

Alan Anderson 03-02-2006 12:47

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.

CompMaster 03-02-2006 12:52

Re: problem with using a loop
 
while noone touches the joystick the wheels will go to their standard position

Alan Anderson 03-02-2006 13:04

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;

I'm assuming you intend to drive a motor backwards until it reaches a set position and activates a limit switch.

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.

Astronouth7303 03-02-2006 16:44

Re: problem with using a loop
 
Quote:

Originally Posted by CompMaster
This is the MPLAB you know lol...
anyway I mean for any loop like
Code:

while(p1_x=127 && rc_dig_in01)
      pwm11=50;


Even if this was a valid technique, the loop would never exit.

What you probably wanted was this:
Code:

while(p1_x == 127 && rc_dig_in01)
      pwm11=50;

The "=" operator assigns. The "==" operator compares.


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