Go to Post "Is it possible to cut enough holes in the robot to weight reduce 8 lbs?" - ScoutingNerd175 [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 02-11-2006, 03:33
cdennisxlx2's Avatar
cdennisxlx2 cdennisxlx2 is offline
Team San Diego Web Liaison
AKA: Cameron Dennis
FRC #1266 (The Devil Duckies)
Team Role: Mentor
 
Join Date: Jan 2005
Rookie Year: 2005
Location: San Diego
Posts: 188
cdennisxlx2 is a splendid one to beholdcdennisxlx2 is a splendid one to beholdcdennisxlx2 is a splendid one to beholdcdennisxlx2 is a splendid one to beholdcdennisxlx2 is a splendid one to beholdcdennisxlx2 is a splendid one to beholdcdennisxlx2 is a splendid one to behold
!HELP! IM STUCK IN A SUBROUTINE!!! !HELP!

Im developing a set of subroutines to make it easyer for my teams programmers. But when i tried to show them how to call them it calls the first one and stays.

example: From user_routines_fast.c

This is the autonomous code i made to test calling subroutines [line: 141]
Code:
/*******Autonomy Notes*********************
* "time" was initalized on line 24
* relay1_fwd/rev = Bottom Cylinder
* relay3_fwd/rev = Top Cylinder
*	    pwm01 = Left Drive motor
*           pwm02 = Right Drive motor
*           pwm03 = Shooter
*           pwm04 = Tilt
*	  26 loops = One Second (roughly)
****************************************/		
                 
if (time >= 0 && time < 50)
{	
	Left();
}
else if (time > 50 && time < 100)
{
	Stop();
}
else if (time > 100 && time < 150)
{ 
	Right();
}
else if (time > 150)
{
	pwm01 = pwm02 = 127;
}
time++;  //Incriment time

These are the subroutines [line: 290 in user_routines_fast.c]
Code:
unsigned char Left()
{
	pwm01 = 0;
	pwm02 = 254;
	return 0;	
}

unsigned char Right()
{
	pwm01 = 254;
	pwm02 = 0;
	return 0;	
}

unsigned char Stop()
{
	pwm01 = pwm02 = 127;
	return 0;
}

The FUNCTION PROTOTYPES for the subroutines in user_routines.h
Code:
unsigned char Left(void);
unsigned char Right(void);
unsigned char Stop(void);

Can anyone tell me why when i run this it stays in Left()??????????


thank you in advanced
__________________
Team San Diego Robotics Web Liaison
Webmaster and Technical Advisor for the San Diego Regional Planning Committee.
Official Score Keeper for the San Diego Regional
www.sandiegoregional.com
www.frc1266.com
  #2   Spotlight this post!  
Unread 02-11-2006, 04:23
Unsung FIRST Hero
Mike Betts Mike Betts is offline
Electrical Engineer
no team
Team Role: Engineer
 
Join Date: Dec 2001
Rookie Year: 1995
Location: Homosassa, FL
Posts: 1,442
Mike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond repute
Re: !HELP! IM STUCK IN A SUBROUTINE!!! !HELP!

Cameron,

I can not identify exactly where your problem is. Here are some ideas.

I would add a check after incrementing time and set time = 0 if time < 0.

I would look at where time is declared and insure that it is static. Beware of dynamic initializations...

As a matter of style, I would use the form ((A > B) && (A < C)) rather than (A > B && A < C) when working with students. It adds nothing to the speed of the code and eliminates the memorization of operator precedence.

Lastly, I would add a printf to determine what is going on. I strongly suspect the initialization of time is either implicit or the variable is getting stepped on between loops.

Regards,

Mike
__________________
Mike Betts

Alumnus, Team 3518, Panthrobots, 2011
Alumnus, Team 177, Bobcat Robotics, 1995 - 2010
LRI, Connecticut Regional, 2007-2010
LRI, WPI Regional, 2009 - 2010
RI, South Florida Regional, 2012 - 2013

As easy as 355/113...
  #3   Spotlight this post!  
Unread 02-11-2006, 07:30
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: !HELP! IM STUCK IN A SUBROUTINE!!! !HELP!

well first you have 3 holes
50 100 and 150.

dont think that will fix the problem. but at 6am thats all that I can see is wrong.
__________________
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.
  #4   Spotlight this post!  
Unread 02-11-2006, 07:59
Mark McLeod's Avatar
Mark McLeod Mark McLeod is offline
Just Itinerant
AKA: Hey dad...Father...MARK
FRC #0358 (Robotic Eagles)
Team Role: Engineer
 
Join Date: Mar 2003
Rookie Year: 2002
Location: Hauppauge, Long Island, NY
Posts: 8,820
Mark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond repute
Re: !HELP! IM STUCK IN A SUBROUTINE!!! !HELP!

After you get past the "Left();" problem, "time" will eventually wrap around to 0 and start all over again depending on how you've declared it.

I vote with Mike. It seems like "time" could easily be a local variable and thus always be 0. If you remove the "=" from "if (time >= 0 && time < 50)" it would probably not even do "Left()".

P.S.
It's 38 loops per second (26.2 milliseconds per loop) on the FRC.
Why didn't you choose to call Stop() at the end?
__________________
"Rationality is our distinguishing characteristic - it's what sets us apart from the beasts." - Aristotle

Last edited by Mark McLeod : 02-11-2006 at 10:12.
  #5   Spotlight this post!  
Unread 02-11-2006, 09:00
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: !HELP! IM STUCK IN A SUBROUTINE!!! !HELP!

printf is your best debug friend

computers have a nasty habit of doing exactly what you tell them to do

instead of what you want them to do

whenever a program is not doing what you expected, printf the variables to see whats going on inside the SW

in fact, you should get in the habit of checking SW modules this way, to make sure it is doing exactly what you thought it would do (module level testing). Then if its working correctly take the debug (printf...) statements out, or have a debug variable that you set to 0 to disable them.
  #6   Spotlight this post!  
Unread 02-11-2006, 09:42
JamesBrown JamesBrown is offline
Back after 4 years off
FRC #5279
Team Role: Engineer
 
Join Date: Nov 2004
Rookie Year: 2005
Location: Lynchburg VA
Posts: 1,280
JamesBrown has a reputation beyond reputeJamesBrown has a reputation beyond reputeJamesBrown has a reputation beyond reputeJamesBrown has a reputation beyond reputeJamesBrown has a reputation beyond reputeJamesBrown has a reputation beyond reputeJamesBrown has a reputation beyond reputeJamesBrown has a reputation beyond reputeJamesBrown has a reputation beyond reputeJamesBrown has a reputation beyond reputeJamesBrown has a reputation beyond repute
Re: !HELP! IM STUCK IN A SUBROUTINE!!! !HELP!

Assuming he didn't change the comment at the beginning of the code (which I am guessing he didn't because other wise the line numbers don't do much good) then he initialized time in the right place.

The only problem I could see there is if you just declared time and didn't initialize it. Assuming you initialized it as 0 I don't see that as being your problem. I am not sure if it is enough to cause the problem you have but at the very least it is sloppy to return a value through the function if you aren't assigning it to anything.

If you still can't figure out the problem, post all of your user_routine_fast.c and we can probably help more.

James
__________________
I'm Back


5279 (2015-Present)
3594 (2011)
3280 (2010)
1665 (2009)
1350 (2008-2009)
1493 (2007-2008)
1568 (2005-2007)
  #7   Spotlight this post!  
Unread 02-11-2006, 10:27
Daisy Daisy is offline
Registered User
AKA: my real name
FRC #0173 (RAGE)
Team Role: Alumni
 
Join Date: Apr 2006
Rookie Year: 2006
Location: Connecticut
Posts: 207
Daisy has a brilliant futureDaisy has a brilliant futureDaisy has a brilliant futureDaisy has a brilliant futureDaisy has a brilliant futureDaisy has a brilliant futureDaisy has a brilliant futureDaisy has a brilliant futureDaisy has a brilliant futureDaisy has a brilliant futureDaisy has a brilliant future
Re: !HELP! IM STUCK IN A SUBROUTINE!!! !HELP!

After running it in my head (which may not be accurate), I think time is the problem. You're incrementing time, so that after 49, it reaches 50, but at it, you do not define what it does with it (ie Left() or Stop(), etc), so it will keep repeating left.

Daisy

Last edited by Daisy : 02-11-2006 at 10:29. Reason: grammar
  #8   Spotlight this post!  
Unread 02-11-2006, 10:34
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: !HELP! IM STUCK IN A SUBROUTINE!!! !HELP!

Quote:
Originally Posted by Daisy
After running it in my head (which may not be accurate), I think time is the problem. You're incrementing time, so that after 49, it reaches 50, but at it, you do not define what it does with it (ie Left() or Stop(), etc), so it will keep repeating left.Daisy
Yeah, but time gets incremented outside of the if statements. Unless he is clearing the PWM values somewhere, whatever was set in Left will still be sent to the motors for an additional cycle. If he is clearing the values, there would be a 1 cycle pause in the PWM output.

I agree with what was said above. Most likely the time variable isn't global or statically defined. Debug prints should make this apparent rather quickly if this is the case.
  #9   Spotlight this post!  
Unread 02-11-2006, 15:11
cdennisxlx2's Avatar
cdennisxlx2 cdennisxlx2 is offline
Team San Diego Web Liaison
AKA: Cameron Dennis
FRC #1266 (The Devil Duckies)
Team Role: Mentor
 
Join Date: Jan 2005
Rookie Year: 2005
Location: San Diego
Posts: 188
cdennisxlx2 is a splendid one to beholdcdennisxlx2 is a splendid one to beholdcdennisxlx2 is a splendid one to beholdcdennisxlx2 is a splendid one to beholdcdennisxlx2 is a splendid one to beholdcdennisxlx2 is a splendid one to beholdcdennisxlx2 is a splendid one to behold
Re: !HELP! IM STUCK IN A SUBROUTINE!!! !HELP!

Time is not the problem, that part works great. All i need to know is did i code the subroutines wrong or am i calling them wrong? If im doing those right then why is the code stuck in Left() when i run the robot in autonomous mode?
__________________
Team San Diego Robotics Web Liaison
Webmaster and Technical Advisor for the San Diego Regional Planning Committee.
Official Score Keeper for the San Diego Regional
www.sandiegoregional.com
www.frc1266.com
  #10   Spotlight this post!  
Unread 02-11-2006, 15:18
Mark McLeod's Avatar
Mark McLeod Mark McLeod is offline
Just Itinerant
AKA: Hey dad...Father...MARK
FRC #0358 (Robotic Eagles)
Team Role: Engineer
 
Join Date: Mar 2003
Rookie Year: 2002
Location: Hauppauge, Long Island, NY
Posts: 8,820
Mark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond repute
Re: !HELP! IM STUCK IN A SUBROUTINE!!! !HELP!

Post a zip of your user_routines_fast.c here and we'll tell you.

Right now it looks like you're taking something for granted when you post the problem and not bothering to tell us about some seemingly unimportant detail. In programming all details are important. If you weren't overlooking something your code would be working. As with most bugs you don't know what the important detail is yet.
__________________
"Rationality is our distinguishing characteristic - it's what sets us apart from the beasts." - Aristotle

Last edited by Mark McLeod : 02-11-2006 at 15:46.
  #11   Spotlight this post!  
Unread 02-11-2006, 15:55
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: !HELP! IM STUCK IN A SUBROUTINE!!! !HELP!

Quote:
Originally Posted by ghhs_1527
Time is not the problem, that part works great.
How do you know that? My first guess is that you're "initializing" the time variable every time through the loop, so it is always equal to zero when you hit the if statement.

Speaking of "the loop", what is causing it to run 26 times per second? We definitely need to see more of the code in order to help you.
  #12   Spotlight this post!  
Unread 02-11-2006, 17:50
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: !HELP! IM STUCK IN A SUBROUTINE!!! !HELP!

ok its now 5pm and Im awake

ok 50% chance your resetting time to be = to 0 every time you loop.

30% chance that that loop isnt happening every 26 secs(I know it says "im fast I run every 26.1 secs" but its a liar liar pants on fire)

20% chance its something else
__________________
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.
  #13   Spotlight this post!  
Unread 02-11-2006, 19:08
cdennisxlx2's Avatar
cdennisxlx2 cdennisxlx2 is offline
Team San Diego Web Liaison
AKA: Cameron Dennis
FRC #1266 (The Devil Duckies)
Team Role: Mentor
 
Join Date: Jan 2005
Rookie Year: 2005
Location: San Diego
Posts: 188
cdennisxlx2 is a splendid one to beholdcdennisxlx2 is a splendid one to beholdcdennisxlx2 is a splendid one to beholdcdennisxlx2 is a splendid one to beholdcdennisxlx2 is a splendid one to beholdcdennisxlx2 is a splendid one to beholdcdennisxlx2 is a splendid one to behold
Re: !HELP! IM STUCK IN A SUBROUTINE!!! !HELP!

I know it works because it works in all the other modes, just not the one with the subroutines, we have a dip switch to choose autonomous modes. but here are the user_routines_fast.c and user_routines.h files (attached)
Attached Files
File Type: c user_routines_fast.c (9.7 KB, 127 views)
File Type: h user_routines.h (3.2 KB, 99 views)
__________________
Team San Diego Robotics Web Liaison
Webmaster and Technical Advisor for the San Diego Regional Planning Committee.
Official Score Keeper for the San Diego Regional
www.sandiegoregional.com
www.frc1266.com
  #14   Spotlight this post!  
Unread 02-11-2006, 21:27
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: !HELP! IM STUCK IN A SUBROUTINE!!! !HELP!

Code:
	if (rc_dig_in11 = 1) /* 1st Autonomy code */
There's your problem right there. You just tried to assign the value 1 to the variable rc_dig_in11. To test for equality, you must use the == symbol, with two equal signs.

The code you posted will always run the BASH routine. You need to change all those single = to double == in your if and else if statements.
  #15   Spotlight this post!  
Unread 02-11-2006, 22:43
JamesBrown JamesBrown is offline
Back after 4 years off
FRC #5279
Team Role: Engineer
 
Join Date: Nov 2004
Rookie Year: 2005
Location: Lynchburg VA
Posts: 1,280
JamesBrown has a reputation beyond reputeJamesBrown has a reputation beyond reputeJamesBrown has a reputation beyond reputeJamesBrown has a reputation beyond reputeJamesBrown has a reputation beyond reputeJamesBrown has a reputation beyond reputeJamesBrown has a reputation beyond reputeJamesBrown has a reputation beyond reputeJamesBrown has a reputation beyond reputeJamesBrown has a reputation beyond reputeJamesBrown has a reputation beyond repute
Re: !HELP! IM STUCK IN A SUBROUTINE!!! !HELP!

Quote:
Originally Posted by Alan Anderson
Code:
	if (rc_dig_in11 = 1) /* 1st Autonomy code */
There's your problem right there. You just tried to assign the value 1 to the variable rc_dig_in11. To test for equality, you must use the == symbol, with two equal signs.

The code you posted will always run the BASH routine. You need to change all those single = to double == in your if and else if statements.
Yep, that would be it.

As a note to any one else who ever needs help the more code you post the better we can help, don't worry about people stealing it, it wont work on our robots anyway.

James
__________________
I'm Back


5279 (2015-Present)
3594 (2011)
3280 (2010)
1665 (2009)
1350 (2008-2009)
1493 (2007-2008)
1568 (2005-2007)
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
RC Controller Stuck bhk88 Programming 1 31-01-2006 17:46
Stuck on Camera Mount busterblade16 Programming 2 14-02-2005 22:07
stuck in programming mode Shu Song Control System 2 29-04-2004 16:44
help! Am really stuck!!!! pagemauck Programming 8 29-01-2004 12:38
guy stuck in toilet! robot180 Chit-Chat 8 14-11-2003 22:27


All times are GMT -5. The time now is 02:04.

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