Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   Do you write functions for your code? (http://www.chiefdelphi.com/forums/showthread.php?t=26558)

10intheCrunch 09-03-2004 10:22

Re: Do you write functions for your code?
 
We have a few more... =)

This list I can recall atm: 254_arm, 254_auton, 254_drive, 254_encoders, 254_utilities, 254_interrupts, 254_timers, 254_recordable (recordable autonomous, work in progress)...hmmm, I think that's it, might be one more somewhere.

We're also working on breaking our pump and gear shifting code to functions for ease of use in autonomous mode.

Max Lobovsky 09-03-2004 13:38

Re: Do you write functions for your code?
 
Quote:

Originally Posted by KenWittlief
actaully, the SW we are creating for these machines is realtime embedded code

remember that the C compiler will convert your code into assembly code, and from that into machine code

breaking your code up into many little functions makes it look nice, but it actually takes longer for it to run, and takes up more code space, because the function calls are actully jumps in assembly code

its shorter and faster to have sequential code all in one routine that simply falls through to the next statement.

not that we really have to be concerned with optimizing our code for size or speed.

well wait, I have seen some people posting that they have used up all the available code space this year - so maybe some of us got a little carried away with the functions :^)

Im not sure, but don't good compilers make using functions not so ineffecient? If not, can't you just use inline to get the same effect as not using functions?

velocipenguin 09-03-2004 13:57

Re: Do you write functions for your code?
 
I would have suffered greatly if not for the ability to divide everything into functions this year. Even if some of them are only called once, they still make it much easier to keep code organized, readable, and easy to debug. Our (failed) autonomous code has about 8 separate functions, each of which contains 20-30 lines of code. Trying to keep all that organized within Process_Data_From_Local_IO() would have been a nightmare, but dividing all of it into separate functions made coding a breeze. Sure, it might take another CPU cycle or two to jump to the appropriate memory location, but that's not much of a problem when the thing's running at 40 MHz.

Astronouth7303 09-03-2004 14:14

Re: Do you write functions for your code?
 
I did a lot of the stuff your taliking about. I'll post some of my hardware-driver code. (don't have it on me) It includes #defines for every motor, victor, spike, pot, and whatnot. And to top it of, to move the shoulder to a certain position, you call Shoulder_Check(Target). It also includes macros to scale (and translate) the analogs. :D

SeanCassidy 09-03-2004 19:34

Re: Do you write functions for your code?
 
I used many functions, many just like:

#define square(a) a*a

And also a nice function to turn based on degrees you want to turn. Kickin'.

KenWittlief 09-03-2004 19:42

Re: Do you write functions for your code?
 
dont get me wrong- there is nothing wrong with using functions for your code on this project - I was only pointing out in a reply to a post on the 1st page that using functions is not more effecient from a performance perspective, and if the function is only called from one place in your code, its takes up more code space after being compiled than simply putting the same code inline.

there is a balance somewhere, between breaking up every 3 or 4 lines of code into a separate function, and writing one long monolithic block of SW with no functions.

Pat Fairbank 09-03-2004 20:01

Re: Do you write functions for your code?
 
Functions? We wrote a whole math library worth of functions! Actually, it was the other programmer who did, not me, because he actually can understand CORDIC.

Otherwise, we only used functions in such situations where they would be called in more than one different place, such as our joystick auto-calibration function.

jacob_dilles 09-03-2004 20:09

Re: Do you write functions for your code?
 
Quote:

Originally Posted by Pat Fairbank
Functions? We wrote a whole math library worth of functions! Actually, it was the other programmer who did, not me, because he actually can understand CORDIC.

you mind sharing some math libs? a bunch of people are looking for some good ones, if you dont want to write a white paper i could.

Alan Anderson 09-03-2004 20:41

Re: Do you write functions for your code?
 
Quote:

Originally Posted by Pat Fairbank
Functions? We wrote a whole math library worth of functions! Actually, it was the other programmer who did, not me, because he actually can understand CORDIC.

If I get my CORDIC implementation functional, I'll put it somewhere for others to read. In the meantime, maybe your "other programmer" would like to post his work?

Pat Fairbank 09-03-2004 21:31

Re: Do you write functions for your code?
 
We should be posting a white paper containing our math library in the next week EDIT: day or so, keep an eye out for it. It should be good enough for any team's use; I believe we managed to get our CORDIC trig functions accurate to within 6 decimal places.

Astronouth7303 10-03-2004 07:34

Re: Do you write functions for your code?
 
1 Attachment(s)
Here's SOME of my code.

Pat Fairbank 11-03-2004 07:04

Re: Do you write functions for your code?
 
You can now find 296's math library here.


All times are GMT -5. The time now is 22:27.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi