Go to Post And then the judges joined in and did the wave! - Basel A [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-01-2005, 13:52
Max Lobovsky's Avatar
Max Lobovsky Max Lobovsky is offline
Fold em oval!
FRC #1257 (Parallel Universe)
Team Role: College Student
 
Join Date: Jan 2004
Rookie Year: 2004
Location: Scotch Plains, NJ
Posts: 1,026
Max Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant future
Send a message via AIM to Max Lobovsky
Rewriting main loop

I want to rewrite the main loop so that the program enters one of the two possible 26.2ms loop functions (User_Autonomous_Code() and Process_Data_From_Master_uP()) from the same place in the code. As it is, when the code enters autonomous mode, it stays in User_Autonomous_Code() until autonomous mode is unset. The main reason I'd like to change this is so that I can have a single counter counting 26.2ms cycles, rather than one in each function. Secondly, its much more logical to do it this way.

I tried to implement my method, but I get some inexplicable problem where User_Initialization() (which should be called prior to any of my changes) is not getting called, and consequently, the rest of the program cannot run. Does the master processor detect my changes and decide they are illegal or something? Why is the code written like this in the first place?

The changes I made:

in main.c replace

Code:
    while (1)   /* This loop will repeat indefinitely. */
    {
  #ifdef _SIMULATOR
  	statusflag.NEW_SPI_DATA = 1;
  #endif
  
  	if (statusflag.NEW_SPI_DATA)	  /* 26.2ms loop area */
 {								 /* I'm slow! I only execute every 26.2ms because */
 									 /* that's how fast the Master uP gives me data. */
  	  Process_Data_From_Master_uP();  /* You edit this in user_routines.c */
  
  	  if (autonomous_mode)		    /* DO NOT CHANGE! */
  	  {
 	 User_Autonomous_Code();		/* You edit this in user_routines_fast.c */
  	  }
  	}
  	Process_Data_From_Local_IO();	 /* You edit this in user_routines_fast.c */
 									 /* I'm fast! I execute during every loop.*/
    } /* while (1) */
  }  /* END of Main */
with

Code:
     while (1)   /* This loop will repeat indefinitely. */
     {
   #ifdef _SIMULATOR
   	statusflag.NEW_SPI_DATA = 1;
   #endif
   
   	if (statusflag.NEW_SPI_DATA)	  /* 26.2ms loop area */
 {								 /* I'm slow! I only execute every 26.2ms because */
 									 /* that's how fast the Master uP gives me data. */
   		/* You edit this in user_routines.c */
   
   	  if (autonomous_mode)		    /* DO NOT CHANGE! */
   	  {
 	 User_Autonomous_Code();		/* You edit this in user_routines_fast.c */
   	  }
   	  else
   	  {
   		Process_Data_From_Master_uP();
   	  }
   /*counter++; can go here*/
   	}
   	Process_Data_From_Local_IO();	 /* You edit this in user_routines_fast.c */
 									 /* I'm fast! I execute during every loop.*/
     } /* while (1) */
   }  /* END of Main */
In user_routines_fast.c replace

Code:
  while (autonomous_mode)   /* DO NOT CHANGE! */
     {
   	if (statusflag.NEW_SPI_DATA)	  /* 26.2ms loop area */
   	{
   	    Getdata(&rxdata);   /* DO NOT DELETE, or you will be stuck here forever! */
   
   		/* Add your own autonomous code here. */
   
   
   
   		Generate_Pwms(pwm13,pwm14,pwm15,pwm16);
   
   	    Putdata(&txdata);   /* DO NOT DELETE, or you will get no PWM outputs! */
   	}
     }
with

Code:
   	    Getdata(&rxdata);   /* DO NOT DELETE, or you will be stuck here forever! */
   	    Putdata(&txdata);   /* DO NOT DELETE, or you will get no PWM outputs! */
__________________
Learn, edit, inspire: The FIRSTwiki.
Team 1257


2005 NYC Regional - 2nd seed, Xerox Creativity Award, Autodesk Visualization Award
2005 Chesapeake Regional - Engineering Inspiration Award
2004 Chesapeake Regional - Rookie Inspiration award
2004 NJ Regional - Team Spirit Award

Last edited by Max Lobovsky : 04-01-2005 at 13:55.
  #2   Spotlight this post!  
Unread 04-01-2005, 16:00
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,801
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: Rewriting main loop

Your code looks fine. There is no magic check to see if you've changed anything in main.c. Lots of teams have rewritten main.c without issues. All the teams I mentor modify main.c for this and a variety of other reasons as well.
I'll see if I can find some past threads on this topic. [edit]http://www.chiefdelphi.com/forums/sh...ad.php?t=24590

Since the call to User_Initialization comes before the loop you posted I suspect other problems.

Here's one stripped down version. For clarity I removed some lines that delayed all action until the sensors stabilize after power-up, resets autonomous upon disable, and a couple of other specialized routine calls like conversion from 0->254 to -127->127. The Put/Getdata calls are also brought into main.c instead of being repeated elsewhere, so User_Autonomous() is a normal routine.
Code:
void main (void)
{
#ifdef UNCHANGEABLE_DEFINITION_AREA
IFI_Initialization ();		/* DO NOT CHANGE! */
#endif
 
User_Initialization();		/* You edit this in user_routines.c */
 
statusflag.NEW_SPI_DATA = 0; /* DO NOT CHANGE! */ 
 
while (1) /* This loop will repeat indefinitely. */
{
#ifdef _SIMULATOR
	statusflag.NEW_SPI_DATA = 1;
#endif
 
	if (statusflag.NEW_SPI_DATA)	 /* 26.2ms loop area */
	{
	 Getdata(&rxdata); /* Get fresh data from the master microprocessor. */
 
	 Process_Data_From_Master_uP(); // Modified to only handle slow loop sensor stuff
 
	 if (competition_mode) // Robot is disabled
	 {
		 Gyro(); // Initialize gyro assumes FRC is powered up only when robot is in position
	 }
	 else if (autonomous_mode) // Robot is in autonomous
	 {
		 User_Autonomous_Code();
	 }
	 else // Robot is in normal human driver mode
	 {
		User_Driver(); // Joystick driving
	 }
 
	 Putdata(&txdata);			 /* DO NOT CHANGE! */
	 }
 
 
	 Process_Data_From_Local_IO();
 
} /* while (1) */
} /* END of Main */
__________________
"Rationality is our distinguishing characteristic - it's what sets us apart from the beasts." - Aristotle

Last edited by Mark McLeod : 05-01-2005 at 08:23.
  #3   Spotlight this post!  
Unread 04-01-2005, 17:47
Max Lobovsky's Avatar
Max Lobovsky Max Lobovsky is offline
Fold em oval!
FRC #1257 (Parallel Universe)
Team Role: College Student
 
Join Date: Jan 2004
Rookie Year: 2004
Location: Scotch Plains, NJ
Posts: 1,026
Max Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant future
Send a message via AIM to Max Lobovsky
Re: Rewriting main loop

I guess I'll look for some typo or something somewhere. I think I will also move put and getdata() there, too.
__________________
Learn, edit, inspire: The FIRSTwiki.
Team 1257


2005 NYC Regional - 2nd seed, Xerox Creativity Award, Autodesk Visualization Award
2005 Chesapeake Regional - Engineering Inspiration Award
2004 Chesapeake Regional - Rookie Inspiration award
2004 NJ Regional - Team Spirit Award
  #4   Spotlight this post!  
Unread 04-01-2005, 18:05
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: Rewriting main loop

What exactly are the errors you get? It looks like this code is fine to me. If you do get it working, post it back up here (or on the code repository! ). I'd like to use it. (And I don't want to have to figure this out as well...)
__________________

  #5   Spotlight this post!  
Unread 04-01-2005, 18:35
Max Lobovsky's Avatar
Max Lobovsky Max Lobovsky is offline
Fold em oval!
FRC #1257 (Parallel Universe)
Team Role: College Student
 
Join Date: Jan 2004
Rookie Year: 2004
Location: Scotch Plains, NJ
Posts: 1,026
Max Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant future
Send a message via AIM to Max Lobovsky
Re: Rewriting main loop

That wasn't an actual copy of the code I tried to compile, so I imagine there was some small error somewhere in my code.. I just quickly rewrote the changes for the post (it's really just deleting some stuff and moving a single line).
__________________
Learn, edit, inspire: The FIRSTwiki.
Team 1257


2005 NYC Regional - 2nd seed, Xerox Creativity Award, Autodesk Visualization Award
2005 Chesapeake Regional - Engineering Inspiration Award
2004 Chesapeake Regional - Rookie Inspiration award
2004 NJ Regional - Team Spirit Award
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
Rules for hanging, using a loop over the end of the bar caffel Rules/Strategy 10 04-06-2004 15:04
What is going to be your team's main strategy? Matt Attallah Chit-Chat 5 06-04-2004 22:34
Actual execution time measurement Dan Technical Discussion 5 24-03-2003 11:36
NEED HELP with Delay loop for compressor relay switch archiver 2001 10 24-06-2002 02:11
main driver Kaitlin Palmer Off-Season Events 0 09-04-2002 21:26


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

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