Go to Post It goes back to what Dave said last year--you can be legal and graciously professional, but still dumb. Play smart. - Billfred [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 14-03-2005, 19:19
NNSWIZ's Avatar
NNSWIZ NNSWIZ is offline
Registered User
#0839
 
Join Date: Jan 2005
Location: AGAWAM, MA
Posts: 1
NNSWIZ is an unknown quantity at this point
Question Program does not end

I have a problem with my autonomous code. It involves the use of a lot of while() loops that the compiler says will not end. I heard you might have to put an extra condition in the loop such as "If the motor is not on..."(In code). Here's my code:
while (rightteeth < 4 || leftteeth < 4)/*if robot has not turned four gear tooth counts... */
{
pwm13 = 0; /*rev left motor */
pwm15 = 255; /*forward right motor, hopefully will turn robot about ten deg's */
}
The variables rightteeth and leftteeth are to count inputs from the hall effect sensors.
Please someone help me!
  #2   Spotlight this post!  
Unread 14-03-2005, 19:34
Ryan M. Ryan M. is offline
Programming User
FRC #1317 (Digital Fusion)
Team Role: Programmer
 
Join Date: Jan 2004
Rookie Year: 2004
Location: Ohio
Posts: 1,508
Ryan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud of
Re: Program does not end

There is nothing actually wrong with the code you've shown so far. The most likely reason that the compiler is complaining is that before you enter the loop you set one or other of the variables to something less than 4. I didn't think that this compiler was that smart, but maybe it realized that you never alter the variables in the loop. However, if you are using interrupts, then this code should be fine. If you could post all your code, that would be extremely helpful.

It may also just be that the compiler is confused. If your code works (have you tested it?), then I'd just ignore the warning.
__________________

  #3   Spotlight this post!  
Unread 14-03-2005, 19:36
Dave Scheck's Avatar
Dave Scheck Dave Scheck is offline
Registered User
FRC #0111 (WildStang)
Team Role: Engineer
 
Join Date: Feb 2003
Rookie Year: 2002
Location: Arlington Heights, IL
Posts: 574
Dave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond repute
Re: Program does not end

Quote:
Originally Posted by NNSWIZ
I have a problem with my autonomous code. It involves the use of a lot of while() loops that the compiler says will not end. I heard you might have to put an extra condition in the loop such as "If the motor is not on..."(In code). Here's my code:
while (rightteeth < 4 || leftteeth < 4)/*if robot has not turned four gear tooth counts... */
{
pwm13 = 0; /*rev left motor */
pwm15 = 255; /*forward right motor, hopefully will turn robot about ten deg's */
}
The variables rightteeth and leftteeth are to count inputs from the hall effect sensors.
Please someone help me!
The compiler is definately right...

You are incorrectly using the while loop. Since you never increment rightteeth or leftteeth inside the loop, it will loop forever This will have the side effect of having your robot run at whatever speed it was running before the loop was hit. This is because the outputs are set at the bottom of the main loop, which will never get hit in your case.

What you probably want to do is use an IF case. The main loop will take care of the iteration.
  #4   Spotlight this post!  
Unread 21-03-2005, 21:39
dm0ney's Avatar
dm0ney dm0ney is offline
Will Code For Food (Food Optional)
AKA: Deepak Mishra
None #0217 (The ThunderChickens)
Team Role: Alumni
 
Join Date: Jan 2005
Rookie Year: 2004
Location: Shelby Twp., MI
Posts: 48
dm0ney will become famous soon enough
Send a message via AIM to dm0ney
Re: Program does not end

While loops are tricky in robotics programming because only the code section within the loop runs until it is broken. Since the sensors are read outside of the loop itself, the loop is infinite.

Another implementation might be like this:
'pseudocode'

if (l teeth < 4 || r teeth < 4)
{
run motors;
}
else
{
motors = 127;
}

The question I ask is if the code is meant to turn the robot, why would the left and right sides both count similarly? Are they on the same gear as a redundancy check? The real question I ask is are the sensors on the robot so one is on each side of the robot, or are they positioned differently?
__________________

Alumni
Team #217, The ThunderChickens



Student, Class of 2009
California Institute of Technology


  #5   Spotlight this post!  
Unread 21-03-2005, 22:33
Dave75 Dave75 is offline
Registered User
AKA: Dave Blackburn
FRC #0075 (RoboRaiders)
Team Role: Mentor
 
Join Date: Mar 2005
Rookie Year: 2004
Location: Hillsborough, NJ
Posts: 6
Dave75 is an unknown quantity at this point
Re: Program does not end

Quote:
Originally Posted by NNSWIZ
I have a problem with my autonomous code. ...
The other comments that have been posted are correct. You're going to have problems if you use a while loop that way. Your code is being called from within the RC's own code, and that code has lots of other things to do. If those things don't get done in time, the RC will shut you down. You need to make sure that each call to your code completes quickly - it only gets about 26 ms to run.

The "if" version in the pseudocode is more in line with what you need. You'll probably also need a static variable to keep track of which state you are in - starting to turn, working on completing the turn, turn completed, starting to drive, driving, etc.

BTW - The compiler is complaining specifically because you are using a loop whose control statement uses variables whose values aren't being changed in the loop. It is not aware that you might be changing them in an interrupt routine. (That is where they get updated, right?)
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
2-week FIRST summer program @ WPI ColleenShaver General Forum 20 31-05-2009 03:02
Mulit-postioning with pnuematics this year? KenWittlief Pneumatics 101 01-02-2005 21:54
how to add steps in the provided encoder program for the edu Zaramel2002 Programming 3 11-02-2004 08:35
Fried program slots? Jeff Waegelin Programming 18 19-03-2003 18:08
Ahh! Program trick confusing! archiver 2001 9 24-06-2002 02:26


All times are GMT -5. The time now is 13:03.

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