Go to Post While at kickoff I asked Woodie if there were any concerns about missed shots at the center goal hitting the operators or the controls. He handed me a ball and told me to throw it at him as hard as I could... How many times does an opportunity like that come up? - Barry Bonzack [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 04-02-2007, 00:36
whytheheckme's Avatar
whytheheckme whytheheckme is offline
Registered User
AKA: Jacob Komar
no team
 
Join Date: Feb 2006
Rookie Year: 2005
Location: Providence, RI
Posts: 1,320
whytheheckme has a reputation beyond reputewhytheheckme has a reputation beyond reputewhytheheckme has a reputation beyond reputewhytheheckme has a reputation beyond reputewhytheheckme has a reputation beyond reputewhytheheckme has a reputation beyond reputewhytheheckme has a reputation beyond reputewhytheheckme has a reputation beyond reputewhytheheckme has a reputation beyond reputewhytheheckme has a reputation beyond reputewhytheheckme has a reputation beyond repute
Send a message via ICQ to whytheheckme Send a message via AIM to whytheheckme Send a message via MSN to whytheheckme Send a message via Yahoo to whytheheckme
Crazy Loops

Hey!

I'm trying to create a simple program that spins my bot for 20 seconds and sees how many tenths of degrees my gyro picks up. I've been programming for a long time, and I can't figure this one out. I'm using easyC because the rest of our team started coding with that, and I guess I'm stuck with it for this year....

Any way, here is some sudo code. Can't copy paste (It's not on this machine, but this is basically what it does)

Operator control
{

int gyro;
int timer = 0;

setgyrotype(4,125)
initgyro(4)
startgyro(4)
starttimer(1)
set_pwm(1,63)
set_pwm(2,63)
set_pwm(3,63)
set_pwm(4,63)
while(timer<20000)
{
gyro = getgyro(4)
timer = GetTimer(1)
PrintToScreen(gyro)
PrintToScreen(timer)
}
set_pwm(1,127)
set_pwm(2,127)
set_pwm(3,127)
set_pwm(4,127)
PrintToScreen("done")
}

Yeah, Yeah... Syntax. Semicolons are overrated. So are proper parameters. It's SUDO CODE....

Anyway... Heres where it breaks down.
It never leaves the while loop. The PrintToScreen SHOWS that the variable counts up to 20000, but continues to go around the loop after that. HOW DOES IT RUN THE LOOP WHEN THE CONDITION ISN'T MET???

Ive also tried an if statement inside the loop that checks the time and makes a variable 'done' 1, and I can show that at 20000, it becomes 1, but it still runs the while loop.

So what gives?
I just updated easyC to 3.0.1.1
I haven't tried this in the old version. Of course the same task in MPLab worked, and took half the time then clicking and dragging If statements....

Jacob
  #2   Spotlight this post!  
Unread 04-02-2007, 00:46
Stuart's Avatar
Stuart Stuart is offline
#include coffee.h
FRC #1745 (P51- Mustangs)
Team Role: Mentor
 
Join Date: Jan 2006
Rookie Year: 2004
Location: Dallas, TX
Posts: 414
Stuart has a reputation beyond reputeStuart has a reputation beyond reputeStuart has a reputation beyond reputeStuart has a reputation beyond reputeStuart has a reputation beyond reputeStuart has a reputation beyond reputeStuart has a reputation beyond reputeStuart has a reputation beyond reputeStuart has a reputation beyond reputeStuart has a reputation beyond reputeStuart has a reputation beyond repute
Send a message via AIM to Stuart
Re: Crazy Loops

well this might be wrong but isnt the operator control function called from one big while loop in main?

you might want to put all of that in a function then in opcon do a
int i = 0;
while(1)
{
if i ==0
function();
i++;
}
__________________
Proud mentor of Team #1745 the P-51 Mustangs

If at first it doesn't work, use a hammer.
If that doesn't work, use a bigger hammer.
  #3   Spotlight this post!  
Unread 04-02-2007, 00:49
dpick1055's Avatar
dpick1055 dpick1055 is offline
David Pick
FRC #1739 (Chicago Knights)
Team Role: Alumni
 
Join Date: May 2005
Rookie Year: 2004
Location: Chicago
Posts: 75
dpick1055 is on a distinguished road
Send a message via AIM to dpick1055
Re: Crazy Loops

While I have never worked in Easy C my best guess would be that it needs some sort of end while statement. While it doesn't seem likely cause C doesn't have a end while command I know it is in other languages so it's worth a shot. Good luck getting that working.
__________________
Always remember to take your powered wheels off the ground when first testing code. Otherwise you'll end up with holes in the wall like us
  #4   Spotlight this post!  
Unread 04-02-2007, 00:52
mluckham's Avatar
mluckham mluckham is offline
Registered User
FRC #0758 (Sky Robotics)
Team Role: Mentor
 
Join Date: Mar 2006
Rookie Year: 2006
Location: Ontario, Canada
Posts: 116
mluckham will become famous soon enoughmluckham will become famous soon enough
Re: Crazy Loops

GetTimer returns an unsigned long. Your timer variable is an int.

Does that make a difference?
  #5   Spotlight this post!  
Unread 04-02-2007, 00:55
whytheheckme's Avatar
whytheheckme whytheheckme is offline
Registered User
AKA: Jacob Komar
no team
 
Join Date: Feb 2006
Rookie Year: 2005
Location: Providence, RI
Posts: 1,320
whytheheckme has a reputation beyond reputewhytheheckme has a reputation beyond reputewhytheheckme has a reputation beyond reputewhytheheckme has a reputation beyond reputewhytheheckme has a reputation beyond reputewhytheheckme has a reputation beyond reputewhytheheckme has a reputation beyond reputewhytheheckme has a reputation beyond reputewhytheheckme has a reputation beyond reputewhytheheckme has a reputation beyond reputewhytheheckme has a reputation beyond repute
Send a message via ICQ to whytheheckme Send a message via AIM to whytheheckme Send a message via MSN to whytheheckme Send a message via Yahoo to whytheheckme
Re: Crazy Loops

Whats weird, is that using the Wait block works. Just replacing the while loop with this block works. This is inconvenient though, because if you want to do anything with this time, you can't.

Perhaps it is the enclosing loop... I'll try this.

Thanks,
Jacob
  #6   Spotlight this post!  
Unread 04-02-2007, 00:58
Eric Finn's Avatar
Eric Finn Eric Finn is offline
Registered User
FRC #0166 (Chop Shop)
Team Role: College Student
 
Join Date: May 2006
Rookie Year: 2005
Location: Merrimack, NH
Posts: 101
Eric Finn has a spectacular aura aboutEric Finn has a spectacular aura about
Send a message via AIM to Eric Finn
Re: Crazy Loops

Do while 1, and have an if statement in your while loop, something like
if(!(timer < 20000))
{
break;
}
to break out of the loop
__________________
It always takes longer than you expect, even when you take into account Hofstadter's Law.
--Hofstadter's Law

  #7   Spotlight this post!  
Unread 04-02-2007, 00:59
whytheheckme's Avatar
whytheheckme whytheheckme is offline
Registered User
AKA: Jacob Komar
no team
 
Join Date: Feb 2006
Rookie Year: 2005
Location: Providence, RI
Posts: 1,320
whytheheckme has a reputation beyond reputewhytheheckme has a reputation beyond reputewhytheheckme has a reputation beyond reputewhytheheckme has a reputation beyond reputewhytheheckme has a reputation beyond reputewhytheheckme has a reputation beyond reputewhytheheckme has a reputation beyond reputewhytheheckme has a reputation beyond reputewhytheheckme has a reputation beyond reputewhytheheckme has a reputation beyond reputewhytheheckme has a reputation beyond repute
Send a message via ICQ to whytheheckme Send a message via AIM to whytheheckme Send a message via MSN to whytheheckme Send a message via Yahoo to whytheheckme
Re: Crazy Loops

Mmmmm.... About the unsigned long...

It was correct in my real code... I remember changing that. Sorry my sudo wasn't updated.

Whats weird is that it wasn't the timer. I used the timer to change another variable from a 0 to a 1, which was a change you could see with a print statement. The while loop simply said while(done ==0) { yadda yadda }
and you would see done change from 0 to 1 without leaving the loop....

It's just bizzare.

Jacob
  #8   Spotlight this post!  
Unread 04-02-2007, 01:00
whytheheckme's Avatar
whytheheckme whytheheckme is offline
Registered User
AKA: Jacob Komar
no team
 
Join Date: Feb 2006
Rookie Year: 2005
Location: Providence, RI
Posts: 1,320
whytheheckme has a reputation beyond reputewhytheheckme has a reputation beyond reputewhytheheckme has a reputation beyond reputewhytheheckme has a reputation beyond reputewhytheheckme has a reputation beyond reputewhytheheckme has a reputation beyond reputewhytheheckme has a reputation beyond reputewhytheheckme has a reputation beyond reputewhytheheckme has a reputation beyond reputewhytheheckme has a reputation beyond reputewhytheheckme has a reputation beyond repute
Send a message via ICQ to whytheheckme Send a message via AIM to whytheheckme Send a message via MSN to whytheheckme Send a message via Yahoo to whytheheckme
Re: Crazy Loops

Quote:
Originally Posted by Eric Finn View Post
Do while 1, and have an if statement in your while loop, something like
if(!(timer < 20000))
{
break;
}
to break out of the loop
Yeah...... I forgot about break. Thanks for the idea!!!

Jacob
  #9   Spotlight this post!  
Unread 04-02-2007, 01:06
mluckham's Avatar
mluckham mluckham is offline
Registered User
FRC #0758 (Sky Robotics)
Team Role: Mentor
 
Join Date: Mar 2006
Rookie Year: 2006
Location: Ontario, Canada
Posts: 116
mluckham will become famous soon enoughmluckham will become famous soon enough
Re: Crazy Loops

If your 'done' variable was changing by itself, then perhaps the gyro call is assigning a variable of the wrong type ... if that variable is immediately adjacent in memory to the 'done' variable, the overflow would affect it.

This normally wouldn't be possible with a compiler like EasyC, which doesn't use pointers (well, it doesn't let US use pointers).

Please post the exact code - C code preferrably.

Mike

BTW - PSEUDO-CODE, not SUDO (but probably you know that)
  #10   Spotlight this post!  
Unread 04-02-2007, 01:11
TimCraig TimCraig is offline
Registered User
AKA: Tim Craig
no team
 
Join Date: Aug 2004
Rookie Year: 2003
Location: San Jose, CA
Posts: 221
TimCraig is a splendid one to beholdTimCraig is a splendid one to beholdTimCraig is a splendid one to beholdTimCraig is a splendid one to beholdTimCraig is a splendid one to beholdTimCraig is a splendid one to beholdTimCraig is a splendid one to behold
Re: Crazy Loops

Quote:
Originally Posted by whytheheckme View Post
Sorry my sudo wasn't updated.
Just so you know, it's pseudo code.
  #11   Spotlight this post!  
Unread 04-02-2007, 01:13
whytheheckme's Avatar
whytheheckme whytheheckme is offline
Registered User
AKA: Jacob Komar
no team
 
Join Date: Feb 2006
Rookie Year: 2005
Location: Providence, RI
Posts: 1,320
whytheheckme has a reputation beyond reputewhytheheckme has a reputation beyond reputewhytheheckme has a reputation beyond reputewhytheheckme has a reputation beyond reputewhytheheckme has a reputation beyond reputewhytheheckme has a reputation beyond reputewhytheheckme has a reputation beyond reputewhytheheckme has a reputation beyond reputewhytheheckme has a reputation beyond reputewhytheheckme has a reputation beyond reputewhytheheckme has a reputation beyond repute
Send a message via ICQ to whytheheckme Send a message via AIM to whytheheckme Send a message via MSN to whytheheckme Send a message via Yahoo to whytheheckme
Re: Crazy Loops

Quote:
Originally Posted by mluckham View Post
If your 'done' variable was changing by itself, then perhaps the gyro call is assigning a variable of the wrong type ... if that variable is immediately adjacent in memory to the 'done' variable, the overflow would affect it.
Yeah... This would make sense. Althought printing out the value of done yielded 1.

Quote:
Originally Posted by mluckham View Post
BTW - PSEUDO-CODE, not SUDO (but probably you know that)
lol yeah... Sudo is sudo for pseudo... hence sudo (my aim at a joke... perhaps a few hours of sleep would be more humorous to my team members...) OK that was pretty lame. I'll go back to using pseudo.
  #12   Spotlight this post!  
Unread 04-02-2007, 01:28
mluckham's Avatar
mluckham mluckham is offline
Registered User
FRC #0758 (Sky Robotics)
Team Role: Mentor
 
Join Date: Mar 2006
Rookie Year: 2006
Location: Ontario, Canada
Posts: 116
mluckham will become famous soon enoughmluckham will become famous soon enough
Re: Crazy Loops

Looking only a pseodo-code can lead one to erroneous results.

I once worked on a project where every module was coded, and had to have COMPLETE pseudo-code in the file header as well. Endless hours were spent making sure the two lined up.

Of course the programmers only looked at the code, knowing the pseudo-code would sometimes be wrong.


Recently I had a variable that mysteriously changed values, in a loop like yours. This was using MPLAB. Turned out there were two variables with exactly the same name, one in local scope and one in global scope. The compiler never hinted of the conflict (well, that's my story and I'm sticking to it!). Of course the global one was being updated (by an external .C routine) and the local one was read by the printf ... since it was on the stack and there were interrupts in the system, it always contained garbage.
  #13   Spotlight this post!  
Unread 04-02-2007, 11:05
dcbrown dcbrown is offline
Registered User
AKA: Bud
no team
Team Role: Mentor
 
Join Date: Jan 2005
Rookie Year: 2005
Location: Hollis,NH
Posts: 236
dcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud of
Re: Crazy Loops

The operator control routine in EasyC is run and run and run. If you exit, it will just call it again for you. To stop that behavior add something like the following to the end after the print done.

Code:
while (1) ;
  #14   Spotlight this post!  
Unread 04-02-2007, 11:17
paulcd2000's Avatar
paulcd2000 paulcd2000 is offline
Accidentally speaks in C
AKA: Paul Dagnelie
FRC #1719 (The Umbrella Corp.)
Team Role: Programmer
 
Join Date: Jan 2006
Rookie Year: 2006
Location: Baltimore
Posts: 368
paulcd2000 is a jewel in the roughpaulcd2000 is a jewel in the roughpaulcd2000 is a jewel in the rough
Send a message via AIM to paulcd2000
Re: Crazy Loops

i dunno much about easyC, but in MPlab, while loops are never a good thing. They have a tendency to cause the motors not to get data. If that's not the case in EasyC, then ignore me. Otherwise, use if statements
__________________
"People don't say 'It's just a game' when their team is winning!" -- Scott Adams

5.5 students (on average)* $7/h *210 hours/student= $8085 of labor, all volunteered (not counting mentors', who are each that much)

We have blades on our robot?! ***sweeeeeet***

There are 11 types of people in the world. Those who can read binary, those who can't, and those who say this joke is supposed to be, "There are 10 types of people in the world. Those who can read binary and those who have a life."
  #15   Spotlight this post!  
Unread 04-02-2007, 11:32
dcbrown dcbrown is offline
Registered User
AKA: Bud
no team
Team Role: Mentor
 
Join Date: Jan 2005
Rookie Year: 2005
Location: Hollis,NH
Posts: 236
dcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud of
Re: Crazy Loops

Quote:
i dunno much about easyC, but in MPlab, while loops are never a good thing. They have a tendency to cause the motors not to get data. If that's not the case in EasyC, then ignore me. Otherwise, use if statements
Thats not the case in EasyC - EasyC documentation indicates Getdata and Putdata is done in the background automatically for you.
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
While loops Guy_E VEX 6 01-11-2006 22:04
POLL: control loops Rickertsen2 Programming 2 28-10-2004 20:32
loops inside of subs??? manodrum Programming 4 19-02-2003 20:05
Solution to Timing Loops Steven Carmain Programming 39 10-02-2003 13:33
Programming Loops Mike o. Programming 5 26-03-2002 11:24


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

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