Go to Post (middle school age) One time I had a truly awful day at school and came home crying. My mother's response? "Do you want to go to the build session tonight? It will make you feel better.." And it did. It always does. - rachelholladay [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
 
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 03-02-2006, 12:08
CompMaster CompMaster is offline
Registered User
#1580
 
Join Date: Jan 2005
Location: Israel
Posts: 9
CompMaster is an unknown quantity at this point
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   Spotlight this post!  
Unread 03-02-2006, 12:21
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,113
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
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   Spotlight this post!  
Unread 03-02-2006, 12:36
CompMaster CompMaster is offline
Registered User
#1580
 
Join Date: Jan 2005
Location: Israel
Posts: 9
CompMaster is an unknown quantity at this point
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   Spotlight this post!  
Unread 03-02-2006, 12:45
KenWittlief KenWittlief is offline
.
no team
Team Role: Engineer
 
Join Date: Mar 2003
Location: Rochester, NY
Posts: 4,213
KenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond repute
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   Spotlight this post!  
Unread 03-02-2006, 12:47
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,113
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
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   Spotlight this post!  
Unread 03-02-2006, 12:52
CompMaster CompMaster is offline
Registered User
#1580
 
Join Date: Jan 2005
Location: Israel
Posts: 9
CompMaster is an unknown quantity at this point
Re: problem with using a loop

while noone touches the joystick the wheels will go to their standard position
  #7   Spotlight this post!  
Unread 03-02-2006, 13:04
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,113
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
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.
  #8   Spotlight this post!  
Unread 03-02-2006, 16:44
Astronouth7303's Avatar
Astronouth7303 Astronouth7303 is offline
Why did I come back?
AKA: Jamie Bliss
FRC #4967 (That ONE Team)
Team Role: Mentor
 
Join Date: Jan 2004
Rookie Year: 2004
Location: Grand Rapids, MI
Posts: 2,071
Astronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud of
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.
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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


All times are GMT -5. The time now is 01:33.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi