Go to Post Give us six more motors in the kit, and we'll try and come up with something... - Karthik [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 08-03-2004, 19:24
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
Do you write functions for your code?

My team's code is pretty simple this year so we just slapped our series of if statements for autonomous and a couple of independent if statements for user_routines inside the normal functions without changing much, but i was curious how many other coders actually did things nice and proper and wrote functions and such. If so, where do you put them and what have you found the most convenient?
__________________
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
  #2   Spotlight this post!  
Unread 08-03-2004, 19:40
jacob_dilles's Avatar
jacob_dilles jacob_dilles is offline
Registered User
AKA: theshadow
FRC #0620 (WarBots)
Team Role: Mentor
 
Join Date: Jan 2003
Rookie Year: 2003
Location: Vienna, VA
Posts: 245
jacob_dilles will become famous soon enough
Send a message via AIM to jacob_dilles
Re: Do you write functions for your code?

haha i wish i had time for preform_autonomus_route("section 1");
__________________
--------------------------
"You're not a real programmer until all your sentences end with semicolons;"
  #3   Spotlight this post!  
Unread 08-03-2004, 19:58
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: Do you write functions for your code?

Quote:
Originally Posted by jacob_dilles
haha i wish i had time for preform_autonomus_route("section 1");
wow, you actually end your sentence with a semicolon. What does your English teacher think?
__________________
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 08-03-2004, 20:09
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: Do you write functions for your code?

Yeah, everything we did was nicely done into functions. (well, everything I did) Functions are much better, even if they only contain three lines of code.
__________________

  #5   Spotlight this post!  
Unread 08-03-2004, 20:20
Ian W. Ian W. is offline
College? What?
no team (Gompei and the Herd)
Team Role: College Student
 
Join Date: Jan 2002
Rookie Year: 2002
Location: Worcester, MA | Smithtown, NY
Posts: 1,464
Ian W. is a name known to allIan W. is a name known to allIan W. is a name known to allIan W. is a name known to allIan W. is a name known to allIan W. is a name known to all
Send a message via AIM to Ian W.
Re: Do you write functions for your code?

Quote:
Originally Posted by maxlobovsky
My team's code is pretty simple this year so we just slapped our series of if statements for autonomous and a couple of independent if statements for user_routines inside the normal functions without changing much, but i was curious how many other coders actually did things nice and proper and wrote functions and such. If so, where do you put them and what have you found the most convenient?
I did what made logical sense to me. Any similar robot functions were grouped together into an actual code function.

I believe I had one for drive motors, one for an arm motor, one for all of our solenoids, and one for our compressor. And then some more random small ones that I don't even remember what they did.

Functions keep things cleaner, and if you have the time to set it up, use it.
__________________
AIM --> Woloi
Email --> ian@woloschin.com
  #6   Spotlight this post!  
Unread 08-03-2004, 21:30
gl75 gl75 is offline
Registered User
AKA: Greg
#0075 (RoboRaiders)
Team Role: Programmer
 
Join Date: Feb 2004
Location: Hillsborough NJ
Posts: 16
gl75 is an unknown quantity at this point
Send a message via AIM to gl75
Re: Do you write functions for your code?

I shouldn't be talking since our robot barely worked, but we used a select statement to switch between autonomous modes in user routines fast. This "in theory" will make our autonomous failsafe if the desired mode encounters a problem.


autoMode = DEAD_RECKON;

switch (autoMode)
{
case DONOTHING:
break;

case DEAD_RECKON: /* Dead_Recockning */
// MyTimerInterrupt is calling Handle_DeadReckoning
//rr_auto_mode_dead_reckoning();
// RR_LEFT_DRIVE_MOTOR = leftScaledSpeedCmd;
// RR_RIGHT_DRIVE_MOTOR = rightScaledSpeedCmd;
// RR_LEFT_DRIVE_MOTOR = 157;
// RR_RIGHT_DRIVE_MOTOR = 175;

if(RR_OPTICAL_SENSOR_1 == 1)
autoMode = LINE_TRACKING;
break;

case KNOCK_BALL:
// put something here
break;

case LINE_TRACKING:
rr_auto_mode_line_tracking();
break;

case DONOTHING:
break;

}

-----

We're using a PID control loop also in our autonomous, taking in feedback from 2 encoders mounted on the left and right drive train. We ended up disabling a good portion of it since the encoders kept getting dislodged. Anyone else use a PID loop with success?
__________________
Greg Liebowitz
Team 75 - RoboRaiders
Webmaster/Programmer
www.roboraiders.com

Last edited by gl75 : 08-03-2004 at 21:35.
  #7   Spotlight this post!  
Unread 08-03-2004, 21: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: Do you write functions for your code?

I understand the theory behind it, but id be interested in seeing some actual implementations of it, especially ones including the I and D not just the P in Proportional, Integral, Differential
__________________
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
  #8   Spotlight this post!  
Unread 08-03-2004, 22:40
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: Do you write functions for your code?

I reallly appreciate the new ability of C to give us not only real functions, but multiple files. I took full advantage of it. (Granted, during the "heat" of a coding session while working on the robot, the code often digressed into horrible slurs of barely legible mush ... I *did* clean it up a bit so others could understand it though )

An example you say? Well, we have an arm that picks up the 2x multiplier, but it tends to backdrive badly, making it difficult to control with the joystick. So, we put in some "antibackdrive" code to stop this, which I put in functions ... including a function to move the arm to a given setpoint (it has a pot on it), which proved useful for the auto ball-knock-down routine.

Oh, and as for the many files I had: obviously, a custom_defs file for all of the many constants a robot always seems to need (much quicker access than scrolling through pages of pbasic code!); and, something that proved particularly useful at vcu, a file named cond_comp.h. That is, conditional compilation. Everything in it is just commented out (shock!) -- there're just a bunch of tests to do in the pit; e.g., test acceptance angle of IR sensors/make sure they haven't broken (funny little things like to do that), we have a "harpoon" whose chain tends to break if we come in too hard, so power is limited in the code when it is too close (another pot on it) ... but when pot is removed and we redo limits, there's a test that debugs the pot values, removes the limit code and sets a low speed setting for the motor ... etc. You can imagine that this saves a lot of time having it all thought out ahead of time, just commenting/uncommenting and testing away. I know there's a thread saying just the opposite ... but I love C!
  #9   Spotlight this post!  
Unread 08-03-2004, 23:17
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: Do you write functions for your code?

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 :^)
  #10   Spotlight this post!  
Unread 08-03-2004, 23:34
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: Do you write functions for your code?

Yep guys, Ken's right on the money with this one.

Functions are great for repeated routines that are called at different times with different arguments, but using functions just for the sake of using functions is wasting your CPU power!

Every time you call a function, the processor has to push all its arguments and the return address onto the stack, goto the function address, execute the function, return to the main routine and clear the stack elements added.

If the function is there just to make your code look pretty, you're wasting CPU cycles on the robot.
  #11   Spotlight this post!  
Unread 09-03-2004, 00:11
rbayer's Avatar Unsung FIRST Hero
rbayer rbayer is offline
Blood, Sweat, and Code
no team (Teamless Orphan)
 
Join Date: Mar 2002
Rookie Year: 2001
Location: Minnetonka, MN
Posts: 1,087
rbayer is a glorious beacon of lightrbayer is a glorious beacon of lightrbayer is a glorious beacon of lightrbayer is a glorious beacon of lightrbayer is a glorious beacon of light
Send a message via AIM to rbayer
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 :^)
On processors without big pipelines (x86, etc have big pipes, especially Intels), function calls are relatively cheap, especially for FIRST robots. The big thing you have to watch out for is stack space, as the PIC can only natively handle 16 nested function calls. There are ways around this limit (like writing your own stack handler), but they tend to be messy and ridiculously hard to debug in addition to being a pain in the neck to write if you've never done it before. Anyways, just be careful that you don't have calls 16-levels deep and everything should be just fine.
__________________
New C-based RoboEmu2 (code simulator) available at: http://www.robbayer.com/software.php
  #12   Spotlight this post!  
Unread 09-03-2004, 00:53
Jay Lundy Jay Lundy is offline
Programmer/Driver 2001-2004
FRC #0254 (The Cheesy Poofs)
Team Role: Alumni
 
Join Date: Jun 2001
Rookie Year: 2001
Location: Berkeley, CA
Posts: 320
Jay Lundy is a name known to allJay Lundy is a name known to allJay Lundy is a name known to allJay Lundy is a name known to allJay Lundy is a name known to allJay Lundy is a name known to all
Re: Do you write functions for your code?

Quote:
Originally Posted by maxlobovsky
I understand the theory behind it, but id be interested in seeing some actual implementations of it, especially ones including the I and D not just the P in Proportional, Integral, Differential
We had the same problem someone else mentioned: a long, double-jointed arm that would fall under the weight of gravity. We ended up writing a PI loop to solve the problem. We use pots on the joints (that sounds wrong), which we use to maintain either a target velocity or a target position. It actually works really well for us.

We're a little busy right now, but we may write something up about it eventually.
  #13   Spotlight this post!  
Unread 09-03-2004, 01:54
10intheCrunch's Avatar
10intheCrunch 10intheCrunch is offline
Who's John V-Neun?
AKA: Alex Baxter
None #0254 (Cheesy Poofs)
Team Role: College Student
 
Join Date: Feb 2004
Rookie Year: 2004
Location: San Jose, CA
Posts: 129
10intheCrunch is a jewel in the rough10intheCrunch is a jewel in the rough10intheCrunch is a jewel in the rough10intheCrunch is a jewel in the rough
Send a message via AIM to 10intheCrunch
Re: Do you write functions for your code?

In terms of organization, we also split most of our code into different files. We have a lot of code for the arms that would only get more confusing if it were thrown in with the general usage code (same with the drive code), especially because the arm is only updated on interrupts (5 and 10 times a second).

It's very nice in terms of development, because everything is seperated, we know where it all is, and we can work on different parts of the code at the same time. If we are having problems, it is very easy to take part or all of the file out of the system while we test other things.

As long as you don't go overboard, I think the chip should be fine handling multiple function calls--the power is enough that you *are* going to get through an entire loop in less than the "required" time when new data comes in/interrupt is fired. I think at the very maximum we could have five nested functions (main loop, function called, interrupt handler, arm code, arm position code), and there have been no problems as yet.
__________________
~Alex Baxter
Programming, Arms operation, Team 254
  #14   Spotlight this post!  
Unread 09-03-2004, 03:04
Cyris12 Cyris12 is offline
Registered User
AKA: Ajay Reddy
#0254 (Cheesy Poofs)
Team Role: Programmer
 
Join Date: Feb 2004
Location: San Jose, CA
Posts: 6
Cyris12 is an unknown quantity at this point
Send a message via AIM to Cyris12
Re: Do you write functions for your code?

There's also a lot to be said for standardized naming conventions and using #define.

Standardized naming conventions (InitializeGyro(), InitializeEncoders(), InitializeAutonomous() etc) can prevent a lot of searching to fix typos. It also increases the clarity and readability of your code.

#defines become almost essential when dealing with complicated expressions and equations. It's a lot easier to have a series of clearly labeled constants in a header file than to wade through a line wondering what 3 / 16, 82, 5, and 37 represented. Also, having constants in a header file makes changing certain often used values incredibly easier. There is no degradation in program speed because the compiler replaces the constants with the specified value at run time.
  #15   Spotlight this post!  
Unread 09-03-2004, 06:52
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: Do you write functions for your code?

Quote:
Originally Posted by 10intheCrunch
In terms of organization, we also split most of our code into different files.
We have a couple main files which we added our stuff to, according to category. The main categories that we had were autonomous, operator, and utilites. This worked well as it kept the file numbers managable, but still seperated things out.
__________________

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
What is your most prefered programming language? Hailfire Programming 156 19-01-2005 21:42
Interrupt timer, executing code asap? SeanCassidy Programming 10 07-03-2004 01:47
Inserting Naviagation code into Default code? actorindp Programming 3 28-01-2004 18:12
RC bootup sequence Venkatesh Programming 17 18-11-2003 20:56
Does your team use the Default code. Jeff McCune General Forum 2 09-01-2003 14:46


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

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