Go to Post They had a well made scouting form on the bottom was a check box with nothing next to it, when asked what the box was for they said. "Oh thats the jerk box" Since then one of our team goals is "Stay out of the jerk box" - Gary Stearns [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 29-05-2010, 13:57
davidthefat davidthefat is offline
Alumni
AKA: David Yoon
FRC #0589 (Falkons)
Team Role: Alumni
 
Join Date: Jan 2011
Rookie Year: 2010
Location: California
Posts: 792
davidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud of
Re: writing reusable code / preparing for the future

Quote:
Originally Posted by Chris is me View Post
This includes code you slightly modify or whatever. Unless you retype it, you can't use it without publishing it.

I wouldn't try and get around the letter of the rule because that still breaks the spirit of it.
eh I really don't care anymore, I am going to publish it, I never really comment my code and its going to take people quite a while to even understand what something does
__________________
Do not say what can or cannot be done, but, instead, say what must be done for the task at hand must be accomplished.
  #2   Spotlight this post!  
Unread 29-05-2010, 14:45
apalrd's Avatar
apalrd apalrd is offline
More Torque!
AKA: Andrew Palardy (Most people call me Palardy)
VRC #3333
Team Role: College Student
 
Join Date: Mar 2009
Rookie Year: 2009
Location: Auburn Hills, MI
Posts: 1,347
apalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond repute
Re: writing reusable code / preparing for the future

Quote:
Originally Posted by davidthefat View Post
...I never really comment my code and its going to take people quite a while to even understand what something does
1. Comments make good programming practice. I have gotten used to them in LabVIEW, and I can't see any reason to not at least describe what a function does in C/C++

2. If they cant understand what it does, then it is either too complex or not implemented "well".

Example: If I have a VI that processes the lookup of kicker pullback for kick distance, I name it "kicker_lookup_distance.vi" (similar to how you would name a function "lookup_distance" and put it in namespace "kicker".) Within the VI, it is written in two portions: lookup range (0-1) and scale that to the correct voltage. I have a comment describing what each does, the variables defining vMax and vMin are global constants, and comments describing the process for determining the pullback, etc.
If someone were to look at this VI, knowing that it's name was "kicker_lookup_distance", they would be able to tell what it does and what its purpose is. All of my code is written in this way, with things like state machines in seperate VI's from PID processing, gain scheduling, etc. and seperate VI's for more complex states (e.g. those that don't feed a position directly to the PID control). Each is well commented and a decent programmer should be able to figure out what it does between the comments, VI connector names, and VI (function) names.
__________________
Kettering University - Computer Engineering
Kettering Motorsports
Williams International - Commercial Engines - Controls and Accessories
FRC 33 - The Killer Bees - 2009-2012 Student, 2013-2014 Advisor
VEX IQ 3333 - The Bumble Bees - 2014+ Mentor

"Sometimes, the elegant implementation is a function. Not a method. Not a class. Not a framework. Just a function." ~ John Carmack
  #3   Spotlight this post!  
Unread 29-05-2010, 17:03
demosthenes2k8's Avatar
demosthenes2k8 demosthenes2k8 is offline
Graduated but not gone
AKA: Matt Soucy
FRC #0166 (Chop Shop 166)
Team Role: Mentor
 
Join Date: Jan 2009
Rookie Year: 2007
Location: Merrimack, NH
Posts: 589
demosthenes2k8 is a splendid one to beholddemosthenes2k8 is a splendid one to beholddemosthenes2k8 is a splendid one to beholddemosthenes2k8 is a splendid one to beholddemosthenes2k8 is a splendid one to beholddemosthenes2k8 is a splendid one to beholddemosthenes2k8 is a splendid one to beholddemosthenes2k8 is a splendid one to behold
Send a message via AIM to demosthenes2k8 Send a message via Yahoo to demosthenes2k8
Re: writing reusable code / preparing for the future

Yes, it's always a good idea to write reusable code. It may be annoying now, but it'll save you time in the future.
__________________


GSR Dean's List Finalist 2011
  #4   Spotlight this post!  
Unread 30-05-2010, 00:11
Alex.Norton's Avatar
Alex.Norton Alex.Norton is offline
Fidgetting
no team
 
Join Date: Apr 2005
Rookie Year: 2003
Location: Ft. Collins, Colorado
Posts: 190
Alex.Norton has much to be proud ofAlex.Norton has much to be proud ofAlex.Norton has much to be proud ofAlex.Norton has much to be proud ofAlex.Norton has much to be proud ofAlex.Norton has much to be proud ofAlex.Norton has much to be proud ofAlex.Norton has much to be proud of
Send a message via AIM to Alex.Norton Send a message via MSN to Alex.Norton
Re: writing reusable code / preparing for the future

This is what an API is for. If you design an API before hand and code to that API, then when the new libraries roll around, you can have a single person modify the code that run underneath the API to use the new library, and all the other programmers can continue writing code for the robot since they know what the API looks like.

You could take the time in the off season to write the API, then when the season rolls around. The programmers can write and test code based on previous library releases knowing that it will work when they change to the new library.

On the topic of reusable code. I always make my code as generic as possible. As example, I recently wrote a quick hearts game, and instead of writing a Deal() function that returned a bunch of hands I wrote a Deck class that would allow me to write a game like go fish if I chose to. Generic and reusable code is one of the hallmarks a good software design.
__________________
"History doesn't repeat itself - at best it sometimes rhymes" --Mark Twain
  #5   Spotlight this post!  
Unread 30-05-2010, 02:16
kwojcik kwojcik is offline
Registered User
no team
Team Role: Mentor
 
Join Date: Sep 2008
Rookie Year: 2009
Location: California
Posts: 24
kwojcik is a splendid one to beholdkwojcik is a splendid one to beholdkwojcik is a splendid one to beholdkwojcik is a splendid one to beholdkwojcik is a splendid one to beholdkwojcik is a splendid one to behold
Re: writing reusable code / preparing for the future

Writing re-usable code for something like a drive train should be pretty easy if you just pay attention to how you build up the code base

1. Separate your constants from your code. Make a constants.h. Avoid magic numbers, "const RIGHT_DRIVE_SPEED_BIAS = .97" instead of throwing .97 into your function that calculates the drive train speed. Do this with speed controller ports, sensor ports, sensor center voltages (i.e. some potentiometer is at 3.423 volts when this arm is at rest), etc etc etc. Almost anything that is physically constant on the robot should be here. Why is this useful? You moved a motor? One side is a bit too fast? Replaced a pot? You change the code on 1 line and 1 line only, everything else still works perfectly.

2. Abstraction, use it. For our drive train code, the only public functions are accessible through a DriveTrainManager object. The manager has 2 DriveSide objects, each of which has a SteeringMotor, and each steering motor has its own PID class. DriveTrainManager has NO idea that SteeringMotors even exist, it only knows about the functions in DriveSide. Why? Theoretically (if we didn't do swerve drive again) the DriveTrainManager and DriveSide objects should be completely reusable, except for the functions that rotate the wheel modules obviously, if we decided to do tank drive.

3. Avoid coupled code (spaghetti code or the infamous spaghetti and meatballs code ). Your drive train should not be using code in your arm class, and visa versa, try to encapsulate each physical aspect of your robot into its own completely modular class. Then make 1 class that deals with all the interactions. Why? Say next year you don't have an arm, so you delete the arm class. Compile the code, and now you have 5 functions in your drive train that are referencing code that no longer exists, so now you have to restructure your drive train code. This can be a complete nightmare once your code base is large enough.

4. Always make a plan, but never follow it. Planning is going to make you understand the code before you even write it, but as you begin to program you're going to realize that its all wrong and restructure the code over and over. You should know each object and module in your code before you start writing anything, or else you're going to end up writing coupled code in a struggle to get thing to work.
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
Team 3132 - Sample code for writing to a file on the cRIO SteveGarward C/C++ 0 05-02-2010 07:26
Preparing for Regionals!!! tribotec_ca88 General Forum 3 26-02-2004 20:16
How formal are your writing styles for the Chairman's award? Katy Chairman's Award 16 16-04-2003 20:07
Preparing for the invasion!!! dlavery Championship Event 4 01-04-2002 19:44


All times are GMT -5. The time now is 11:06.

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