Go to Post Does FIRST know about some rare inverted mushroom that I do not? - sanddrag [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 31-01-2004, 09:49
Astronouth7303's Avatar
Astronouth7303 Astronouth7303 is offline
Why did I come back?
AKA: Jamie Bliss
FRC #4967 (That ONE Team)
Team Role: Mentor
 
Join Date: Jan 2004
Rookie Year: 2004
Location: Grand Rapids, MI
Posts: 2,071
Astronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud of
Editing Main.c

I have been thinking about this for a little while. Why not have 2 sets of initializations and loops? 1 for autonomous, 1 for regular. And while we're at it, include a HALT() routine. Here's my version. Where do I put the prototype for HALT()?
Attached Files
File Type: zip Frc_NewMain.zip (50.7 KB, 57 views)
  #2   Spotlight this post!  
Unread 31-01-2004, 10:55
Dave Flowerday Dave Flowerday is offline
Software Engineer
VRC #0111 (Wildstang)
Team Role: Engineer
 
Join Date: Feb 2002
Rookie Year: 1995
Location: North Barrington, IL
Posts: 1,366
Dave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond repute
Re: Editing Main.c

Quote:
Originally Posted by Astronouth7303
I have been thinking about this for a little while. Why not have 2 sets of initializations and loops? 1 for autonomous, 1 for regular. And while we're at it, include a HALT() routine. Here's my version. Where do I put the prototype for HALT()?
It's an interesting idea, but I'd advise against it. I looked at what you did at main.c and there's two major problems that I see. The first is that your code now depends on the fact that autonomous will be active when the robot is powered on. I don't believe this will be the case at the competitions. I'm pretty sure that last year, when you were setting up your robot on the field, the "Disabled" bit was set but the "Autonomous" bit was clear. Then, when the round started, it would change from "Disabled - no auto" to "Enabled - auto mode" in one packet. Even if they did plan to have the autonomous bit set when you plug your robot in on the field, there might be a delay or something - I wouldn't rely on it.

The second problem is that once your autonomous routine ends, there's no going back. This probably isn't such a big deal, but if somehow one packet from the OI comes down during autonomous mode with the autonomous flag cleared, your robot will stop autonomous mode and you won't be able to get back in. I highly doubt this would happen since IFI checksums the packets to ensure that they are valid before passing them to the user cpu, but still.. you never know what might happen.

Finally, your idea of halting the robot is interesting, but I don't see the purpose for it. Why would you want your robot to ever shut down? And more importantly, why would you want code to do that in there when you compete? I know our drive team would be rather upset if we had code like that in our robot and then a bug or something caused that condition to occur... Also, if you really want to have this halt option, it would probably be a wise idea to turn off all your outputs beforehand (PWMs to 127, relay outputs off, etc).
  #3   Spotlight this post!  
Unread 31-01-2004, 13:04
deltacoder1020's Avatar
deltacoder1020 deltacoder1020 is offline
Computer Guy
AKA: Dav
#1020 (The Indiana Prank Monkeys)
Team Role: Programmer
 
Join Date: Jan 2004
Location: Muncie, Indiana
Posts: 340
deltacoder1020 has a spectacular aura aboutdeltacoder1020 has a spectacular aura about
Send a message via AIM to deltacoder1020
Re: Editing Main.c

there is also the fact that such could result in code duplication - you may use some of the same code for the Process_Data_from_Local as you would for autonomous.
__________________
Team 1020, the Indiana Prank Monkeys (www.team1020.org)
  #4   Spotlight this post!  
Unread 31-01-2004, 18:49
KevinB's Avatar
KevinB KevinB is offline
Registered User
AKA: Alum
no team
Team Role: Alumni
 
Join Date: Dec 2002
Rookie Year: 2001
Location: AL
Posts: 188
KevinB will become famous soon enoughKevinB will become famous soon enough
Send a message via ICQ to KevinB
Re: Editing Main.c

There really is no advantage to doing this. If you're worried about code readability, try splitting the actual code up into separate files like this:

Code:
if (autonomous_mode) {
#include "auton.c"
} else {
#include "manual.c"
}
  #5   Spotlight this post!  
Unread 31-01-2004, 20:45
mtrawls's Avatar
mtrawls mtrawls is offline
I am JVN! (John von Neumann)
#0122 (NASA Knights)
Team Role: Programmer
 
Join Date: Mar 2003
Location: Hampton, VA
Posts: 295
mtrawls is a splendid one to beholdmtrawls is a splendid one to beholdmtrawls is a splendid one to beholdmtrawls is a splendid one to beholdmtrawls is a splendid one to beholdmtrawls is a splendid one to beholdmtrawls is a splendid one to behold
Send a message via AIM to mtrawls
Re: Editing Main.c

Quote:
Originally Posted by KevinB
There really is no advantage to doing this. If you're worried about code readability, try splitting the actual code up into separate files like this:

Code:
if (autonomous_mode) {
#include "auton.c"
} else {
#include "manual.c"
}

What? #include statements are pre-processor directives ... they are (quite necessarily) executed before compilation and definately before you upload the code to the robot. For conditional includes, you'd have to use the pre-processor directive #ifdef ... #endif -- but this isn't what you mean to do. Presumably, everytime you run the robot you'd want to execute *both* autonomous mode, and manual mode -- meaning you'd more than likely want both "auton.c" and "manual.c" to be included every time. Instead of #include "auton.c", perhaps you mean some sort of function call, where the function is defined in auton.c? *color me confused*

Quote:
there is also the fact that such could result in code duplication - you may use some of the same code for the Process_Data_from_Local as you would for autonomous.
That's not such a big concern, though. If something increases readability, or efficiency, or some other desirable thing, you very may well say "re-usability be damned." Reducing code duplication is good because it reduces your work, and reduces the amount of errors creeping up because of subtly different versions ... but it isn't necessarily bad (not that it is--or isn't-- justified here). Oh, and all I really wanted was an excuse to say this (sorry that I forget who it was that said it): For code to be re-usable, it first has to be usable
  #6   Spotlight this post!  
Unread 31-01-2004, 22:23
Random Dude Random Dude is offline
Oregon State Head FTA
AKA: Chris
no team (Oregon Robotics Tournament & Outreach Program)
 
Join Date: Aug 2002
Rookie Year: 1998
Location: Oregon
Posts: 142
Random Dude will become famous soon enoughRandom Dude will become famous soon enough
Re: Editing Main.c

Quote:
Originally Posted by mtrawls
What? #include statements are pre-processor directives ... they are (quite necessarily) executed before compilation and definately before you upload the code to the robot. For conditional includes, you'd have to use the pre-processor directive #ifdef ... #endif -- but this isn't what you mean to do. Presumably, everytime you run the robot you'd want to execute *both* autonomous mode, and manual mode -- meaning you'd more than likely want both "auton.c" and "manual.c" to be included every time. Instead of #include "auton.c", perhaps you mean some sort of function call, where the function is defined in auton.c? *color me confused*



That's not such a big concern, though. If something increases readability, or efficiency, or some other desirable thing, you very may well say "re-usability be damned." Reducing code duplication is good because it reduces your work, and reduces the amount of errors creeping up because of subtly different versions ... but it isn't necessarily bad (not that it is--or isn't-- justified here). Oh, and all I really wanted was an excuse to say this (sorry that I forget who it was that said it): For code to be re-usable, it first has to be usable

No, that *should* work as is.... since the preprocessor would stick both of the files in and then everything would compile. That being said, I do agree that making then relevant sections into functions (in seperate files if you insist), would make much more sense.
  #7   Spotlight this post!  
Unread 31-01-2004, 23:08
deltacoder1020's Avatar
deltacoder1020 deltacoder1020 is offline
Computer Guy
AKA: Dav
#1020 (The Indiana Prank Monkeys)
Team Role: Programmer
 
Join Date: Jan 2004
Location: Muncie, Indiana
Posts: 340
deltacoder1020 has a spectacular aura aboutdeltacoder1020 has a spectacular aura about
Send a message via AIM to deltacoder1020
Re: Editing Main.c

Quote:
Originally Posted by mtrawls
What? #include statements are pre-processor directives ... they are (quite necessarily) executed before compilation and definately before you upload the code to the robot. For conditional includes, you'd have to use the pre-processor directive #ifdef ... #endif -- but this isn't what you mean to do. Presumably, everytime you run the robot you'd want to execute *both* autonomous mode, and manual mode -- meaning you'd more than likely want both "auton.c" and "manual.c" to be included every time. Instead of #include "auton.c", perhaps you mean some sort of function call, where the function is defined in auton.c? *color me confused*



That's not such a big concern, though. If something increases readability, or efficiency, or some other desirable thing, you very may well say "re-usability be damned." Reducing code duplication is good because it reduces your work, and reduces the amount of errors creeping up because of subtly different versions ... but it isn't necessarily bad (not that it is--or isn't-- justified here). Oh, and all I really wanted was an excuse to say this (sorry that I forget who it was that said it): For code to be re-usable, it first has to be usable
of course it does. i comment the heck out of my code, as well as try to arrange it in the most logical way possible

I think what Random Dude meant was that you could use #includes so that you could be sure that the code you were writing would be executed for one mode or another, depending on what file you put it in. that way, you still have both autonomous mode and operator mode, but the code for each is in separate files.
__________________
Team 1020, the Indiana Prank Monkeys (www.team1020.org)
  #8   Spotlight this post!  
Unread 31-01-2004, 23:55
KevinB's Avatar
KevinB KevinB is offline
Registered User
AKA: Alum
no team
Team Role: Alumni
 
Join Date: Dec 2002
Rookie Year: 2001
Location: AL
Posts: 188
KevinB will become famous soon enoughKevinB will become famous soon enough
Send a message via ICQ to KevinB
Re: Editing Main.c

Quote:
Originally Posted by mtrawls
What? #include statements are pre-processor directives ... they are (quite necessarily) executed before compilation and definately before you upload the code to the robot. For conditional includes, you'd have to use the pre-processor directive #ifdef ... #endif -- but this isn't what you mean to do.
I didn't use #ifdef or #endif because thats not what I'm trying to accomplsh. The #include directive simply takes the contents of that file and shoves it into the spot where the #include line was.

You get the conveinence of having the autonomous routine in 1 file and the main routine in the other file, and you save the CPU cycles necessary to jump to and from the function.
  #9   Spotlight this post!  
Unread 01-02-2004, 11:21
Larry Barello Larry Barello is offline
http://www.barello.net
#0492 (Titan Robotics Club)
Team Role: Mentor
 
Join Date: Jan 2002
Location: Bellevue, WA
Posts: 85
Larry Barello has a spectacular aura aboutLarry Barello has a spectacular aura about
Re: Editing Main.c

It is perfectly reasonable to rewrite main(). I did it. I don't understand why IFI put in such a baroque superstructure in the FRC default code. The EDU code was cleaner.

You can replace *everything* that IFI gave you, except for their library. All I saved was the printf (modified slightly) and the main library with the rxget and txput routines since those are "hidden" in a library. The important thing to keep the same is how the IFI stuff is initialized and how you go about getting and putting the packet from the master CPU. Every thing else is fair game.

In short, my main looks like this:

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)
    {
#ifdef _SIMULATOR
        statusflag.NEW_SPI_DATA = 1;
#endif
        if (statusflag.NEW_SPI_DATA)    /* 26.2ms loop area */
        {
            Getdata(&rxdata);
            ProcessPacket();			// User_routines.c
            Putdata(&txdata);           /* DO NOT DELETE, or you will get no PWM outputs! */
        }
        Process_Tasks();                // user_routines.c
    } /* while (1) */
}  /* END of Main */
and my user_code looks like this:

Code:
void ProcessPacket(void)
{
	int c;
	
	// Put common stuff here

	CheckSwitches();			// Mass examine digital input for change

 	if (autonomous_mode)
	{
		User_Autonomous_Code();
	}
	else
	{
		User_Normal_Code();
	}
	pwm01 = DoPid(&Left, &LeftEncoder);
	pwm02 = DoPid(&Right, &RightEncoder);
	
	//---------- Inputs to Relays--------------------------------------------

	relay8_fwd = !rc_dig_in18;  /* Power pump only if pressure switch is off. */
	relay8_rev = 0;
...
and finally, my "tasking code" which was more complicated, but now is pretty simple

Code:
void Process_Tasks(void)
{
	static char GyroTimer = 0, PrintTimer = 0;

	Poll_Rx1();					// The fast loop runs > 100khz
	Poll_Tx1();					// Poll rather than interrupts
	Poll_Rx2();
	Poll_Tx2();

    while (MsTimer)				// Incremented by TimerInterrupt.
	{
		MsTimer--;				// Section.

		if (++GyroTimer == 10)	// 100hz
		{
			GyroTimer = 0;
			Gyro_Task();
		} // END GyroTimer

		if (++PrintTimer == 100)	// 10hz
		{
			PrintTimer = 0;
			TetherTask(STDIO);
		} // END Print task
	}// END Tasking
}
In short my "packet driver" code does common stuff up front (read sensors) the calls appropriate normal or autonomous code, then at the back end formats up stuff to send out.

Just pay attention to those lines with /* DO NOT CHANGE */ appended to them. Not all, but most are important.

Also, if you are interested in my tasking code, I put a zip called "sensors.zip" out on one of the programming forums (PID or Gyro, one of the two...)

Last edited by Larry Barello : 01-02-2004 at 11:23.
  #10   Spotlight this post!  
Unread 02-02-2004, 14:19
Astronouth7303's Avatar
Astronouth7303 Astronouth7303 is offline
Why did I come back?
AKA: Jamie Bliss
FRC #4967 (That ONE Team)
Team Role: Mentor
 
Join Date: Jan 2004
Rookie Year: 2004
Location: Grand Rapids, MI
Posts: 2,071
Astronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud of
Re: Editing 'forbiden' areas

Thanx, Every one!

Unfortunately, I didn't even compile the code I posted. I would be surprised if thier weren't syntax errors or whatnot.

Let's keep discussing about editing core areas for making code faster, more efficent, adding functionality, or just for the heck of it.

A few challenges:
  • write a template for a 'minimum-boot' program. just initialize, comment "//Put Stuff here!" and de-init
  • Write a full program from scratch. Doesn't have to do anything fancy, you just can't use anything from default code (except for lib declarations).
  • Have you done it using ALL your own code (no libs)? let's hear about it!

Still cracking, Astronouth7303
  #11   Spotlight this post!  
Unread 05-02-2004, 01:08
djcapelis's Avatar
djcapelis djcapelis is offline
Fried Manic Custard
None #0675 (Geeks with Power Tools)
Team Role: Programmer
 
Join Date: May 2003
Rookie Year: 2001
Location: Rohnert Park, CA
Posts: 129
djcapelis will become famous soon enoughdjcapelis will become famous soon enough
Send a message via ICQ to djcapelis Send a message via AIM to djcapelis Send a message via Yahoo to djcapelis
Re: Editing Main.c

If anyone really feels like abuse... would it be possible without messing with IFI stuff to actually write a full control with just ASM?

If so... anyone want to give it a try?
__________________
"I have more friends than enemies, I'm working to resolve the issue."
  #12   Spotlight this post!  
Unread 05-02-2004, 17:50
Astronouth7303's Avatar
Astronouth7303 Astronouth7303 is offline
Why did I come back?
AKA: Jamie Bliss
FRC #4967 (That ONE Team)
Team Role: Mentor
 
Join Date: Jan 2004
Rookie Year: 2004
Location: Grand Rapids, MI
Posts: 2,071
Astronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud of
Re: Editing Main.c

Yikes, ouch, assembley language, yikes, ouch, wow. :SinksIn: You really took that to heart!

No, I don't know any asm's. But someone's got to do the first one. May be this will be an off-season thing.

Again, Yikes, ouch, wow.
  #13   Spotlight this post!  
Unread 05-02-2004, 18:39
Raven_Writer's Avatar
Raven_Writer Raven_Writer is offline
2004 Detroit & Pittsburgh Winners
AKA: Eric Hansen
FRC #0005 (RoboCards)
Team Role: Mentor
 
Join Date: Jan 2003
Rookie Year: 2002
Location: Melvindale
Posts: 1,549
Raven_Writer is just really niceRaven_Writer is just really niceRaven_Writer is just really niceRaven_Writer is just really niceRaven_Writer is just really nice
Send a message via ICQ to Raven_Writer Send a message via AIM to Raven_Writer Send a message via MSN to Raven_Writer Send a message via Yahoo to Raven_Writer
Re: Editing Main.c

Quote:
Originally Posted by djcapelis
If anyone really feels like abuse... would it be possible without messing with IFI stuff to actually write a full control with just ASM?

If so... anyone want to give it a try?
It is possible....after all MPLAB/C18 has ASM capabilities, and the processer converts the code into asm then binary (i believe) anyways.
__________________
AIM: wisprmylastbreth
EMail: nightskywriter@gmail.com
Y!: synsoflife

"ai yoru ga" -- "Love the nights"
  #14   Spotlight this post!  
Unread 07-02-2004, 21:24
Astronouth7303's Avatar
Astronouth7303 Astronouth7303 is offline
Why did I come back?
AKA: Jamie Bliss
FRC #4967 (That ONE Team)
Team Role: Mentor
 
Join Date: Jan 2004
Rookie Year: 2004
Location: Grand Rapids, MI
Posts: 2,071
Astronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud of
Re: Editing Main.c

I just remembered: some of IFI's routines are written in ASM (or ASM and C). Check those!
  #15   Spotlight this post!  
Unread 07-02-2004, 21:36
mtrawls's Avatar
mtrawls mtrawls is offline
I am JVN! (John von Neumann)
#0122 (NASA Knights)
Team Role: Programmer
 
Join Date: Mar 2003
Location: Hampton, VA
Posts: 295
mtrawls is a splendid one to beholdmtrawls is a splendid one to beholdmtrawls is a splendid one to beholdmtrawls is a splendid one to beholdmtrawls is a splendid one to beholdmtrawls is a splendid one to beholdmtrawls is a splendid one to behold
Send a message via AIM to mtrawls
Re: Editing Main.c

Hrm... editing main.c, sounds like a good idea. Only I can't. MPLAB won't let me change it -- it isn't accepting any input at all when I have that file in focus. Is there some sort of default protection to protect the unawares that I am unaware about? It was somewhat distressing when, during testing, I did actually want to put something there. Just another reason why MPLAB was getting me angry ... it has several, well "interesting" qualities.
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
Video Editing Software SteveC116 3D Animation and Competition 29 16-02-2004 23:16
DHTML Menu Editing sanddrag Website Design/Showcase 18 05-08-2003 17:34
Video Editing Programs...share what you use and why... Alexander McGee 3D Animation and Competition 25 09-01-2003 22:27
Can we use editing tools? Ydnar 3D Animation and Competition 2 11-03-2002 02:54


All times are GMT -5. The time now is 00:01.

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