Go to Post Isn't that sort of like asking "is that an African or European swallow?" - dlavery [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 26-01-2008, 14:49
Sykan's Avatar
Sykan Sykan is offline
Lead Programmer
AKA: David
FRC #0540 (Team 540)
Team Role: Engineer
 
Join Date: Jan 2006
Rookie Year: 2006
Location: Virginia
Posts: 24
Sykan is on a distinguished road
Using While Statements

I was wondering how I can program a continuously updating while loop in teleop mode. for example if i wanted to complete a 90 degree turn: I've been trying it as while(temp_gyro_angle<900) but the robot freezes. How do I continuously update the while loop and get out the the while loop when finished?

Thank you for your help.
  #2   Spotlight this post!  
Unread 26-01-2008, 14:52
psy_wombats's Avatar
psy_wombats psy_wombats is offline
Registered User
AKA: A. King
FRC #0467 (Duct Tape Bandits)
Team Role: Programmer
 
Join Date: Jan 2007
Rookie Year: 2007
Location: Shrewsbury MA
Posts: 95
psy_wombats has a spectacular aura aboutpsy_wombats has a spectacular aura aboutpsy_wombats has a spectacular aura about
Re: Using While Statements

The robot will freeze because the loop interferes with the default 26 ms loop of the robot, causing the code error. As the robot's running its normal loop anyways, you should just be able to use an if statement, as the PWM value will last until the next refresh, and the condition will be re-evaluated.
  #3   Spotlight this post!  
Unread 26-01-2008, 14:55
jacobhurwitz jacobhurwitz is offline
Registered User
FRC #0449 (Blair Robot Project)
Team Role: Programmer
 
Join Date: Jan 2008
Rookie Year: 2007
Location: Maryland
Posts: 45
jacobhurwitz has a spectacular aura aboutjacobhurwitz has a spectacular aura aboutjacobhurwitz has a spectacular aura about
Re: Using While Statements

If you use a while loop, the program essentially "pauses" there and stops communicating with everything. You should use a global state variable. So, you would have something like:

int gyro_state = 0;

void check_gyro()
{
if (gyro_state == 0 && temp_gyro_angle >= 900)
gyro_state = 1;
if (gyro_state == 0) //temp_gyro_angle has always been less than 900
//insert code here
if (gyro_state == 1) //temp_gyro_angle has been more than 900
//insert code here
}
  #4   Spotlight this post!  
Unread 26-01-2008, 15:02
wt200999's Avatar
wt200999 wt200999 is offline
Texas Instruments
AKA: Will Toth
FRC #3005 (Robochargers)
Team Role: Mentor
 
Join Date: Mar 2006
Rookie Year: 2004
Location: Dallas, Texas
Posts: 323
wt200999 has much to be proud ofwt200999 has much to be proud ofwt200999 has much to be proud ofwt200999 has much to be proud ofwt200999 has much to be proud ofwt200999 has much to be proud ofwt200999 has much to be proud ofwt200999 has much to be proud ofwt200999 has much to be proud of
Send a message via MSN to wt200999
Re: Using While Statements

Can't you also use the GetData() or PutData() function? I have been wondering if I could use those in a loop. If you could it would make life a lot easier.
__________________
Programming in LabVIEW? Try VI Snippets!

FIRST LEGO League 2004 - 2005
FRC Team 870 Student 2006 - 2009
FRC Team 3005 Mentor 2013 -
  #5   Spotlight this post!  
Unread 26-01-2008, 21:05
JonathanLKS JonathanLKS is offline
Code::Blocks
FRC #0610 (The Coyotes)
Team Role: Leadership
 
Join Date: Feb 2006
Rookie Year: 2005
Location: Toronto
Posts: 36
JonathanLKS will become famous soon enough
Send a message via MSN to JonathanLKS
Re: Using While Statements

If you put GetData and PutData in your loop, I don't see a reason why it would freeze, after all thats what the main program loop basicly is.
__________________

Team 610 [ Co-Leader | Head Programmer | Webmaster ]
We're attending: Greater Toronto Regional, San Diego Regional, Championship

Last edited by JonathanLKS : 26-01-2008 at 21:06. Reason: typo
  #6   Spotlight this post!  
Unread 26-01-2008, 23:21
wt200999's Avatar
wt200999 wt200999 is offline
Texas Instruments
AKA: Will Toth
FRC #3005 (Robochargers)
Team Role: Mentor
 
Join Date: Mar 2006
Rookie Year: 2004
Location: Dallas, Texas
Posts: 323
wt200999 has much to be proud ofwt200999 has much to be proud ofwt200999 has much to be proud ofwt200999 has much to be proud ofwt200999 has much to be proud ofwt200999 has much to be proud ofwt200999 has much to be proud ofwt200999 has much to be proud ofwt200999 has much to be proud of
Send a message via MSN to wt200999
Re: Using While Statements

I shall try this on Monday....
__________________
Programming in LabVIEW? Try VI Snippets!

FIRST LEGO League 2004 - 2005
FRC Team 870 Student 2006 - 2009
FRC Team 3005 Mentor 2013 -
  #7   Spotlight this post!  
Unread 27-01-2008, 12:29
aaeamdar's Avatar
aaeamdar aaeamdar is offline
Post-A-Holic
AKA: Paul Dennis
FRC #1719 (The Umbrella Corp)
Team Role: College Student
 
Join Date: Jan 2006
Rookie Year: 2005
Location: Baltimore, MD
Posts: 231
aaeamdar has a brilliant futureaaeamdar has a brilliant futureaaeamdar has a brilliant futureaaeamdar has a brilliant futureaaeamdar has a brilliant futureaaeamdar has a brilliant futureaaeamdar has a brilliant futureaaeamdar has a brilliant futureaaeamdar has a brilliant futureaaeamdar has a brilliant futureaaeamdar has a brilliant future
Re: Using While Statements

I would NOT recommend messing with the GetData and PutData functions. Calling them twice in a single main loop may cause you big problems. The correct solution to the problem is what has been previously posted which is to use an "if" statement. The only appropriate use of a while loop in this context is for iterating through a list of processor tasks. Example:

Code:
while (x < 7)
{
    put (Math.pow(x, 2), table[x]);
    x++;
    //This is pseudocode (I forget the appropriate power function and I made up 
    // put (int, int[])
}
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
Filtering out Vibration while using a KOP Accelerometer joshyboy9987 Electrical 31 22-01-2008 08:20
impossible statements Dan Zollman Math and Science 28 20-08-2005 18:34
Conditional #define Statements Ian W. Programming 3 14-02-2004 18:14
Contradictory FIRST Statements Gobiner Rules/Strategy 10 14-01-2003 16:12
Else Statements!!! Adam Shapiro Programming 9 22-12-2002 01:27


All times are GMT -5. The time now is 15:11.

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