Go to Post That's right 10 years and this is the first time ever that the school wanted anything to do with the FIRST team. - RoteAugen [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, 10:14
Zme Zme is offline
Registered User
FRC #2619
 
Join Date: Jan 2009
Location: Michigan
Posts: 83
Zme is on a distinguished road
writing reusable code / preparing for the future

just wondering if it is all that beneficial with the library changes.
I.E. if i write a class now will it be usable next year with out too much work done in updating it.

we are trying to get a strong base built up wince the majority of our programing team is graduating, but we are a little unsure of how to do that. my original thought was get some generic classes up for future use, then i realized that last years code doesn't compile with this year's libraries so i'm a little reluctant to spend a lot of time writing something to be used in the future when it may not work.

thoughts or suggestions on how to proceed?
  #2   Spotlight this post!  
Unread 29-05-2010, 10:31
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

Thta how you should ALWAYS program imo. Of course you might have to adjust it abit but I doubt you would have to adjust it at all if you code it right. Like make the code generic and not too specific. Like make a class for imaging if you are going to do something with that, you can make a location/coordinate/vertex class if you want to do some lacation stuff. There are tons of generic classes you can make that can be benefitial. Hell you can even make your own library if you want.
__________________
Do not say what can or cannot be done, but, instead, say what must be done for the task at hand must be accomplished.
  #3   Spotlight this post!  
Unread 29-05-2010, 10:42
Zme Zme is offline
Registered User
FRC #2619
 
Join Date: Jan 2009
Location: Michigan
Posts: 83
Zme is on a distinguished road
Re: writing reusable code / preparing for the future

its the adjusting bit that i'm worried about, i understand that code that is "written right" as you put it should work for years to come, but i feel that the libraries that we have to use are advancing enough at the moment that it may be a moot point to do it.
  #4   Spotlight this post!  
Unread 29-05-2010, 10:48
Radical Pi Radical Pi is offline
Putting the Jumper in the Bumper
AKA: Ian Thompson
FRC #0639 (Code Red Robotics)
Team Role: Programmer
 
Join Date: Jan 2010
Rookie Year: 2010
Location: New York
Posts: 655
Radical Pi has a spectacular aura aboutRadical Pi has a spectacular aura aboutRadical Pi has a spectacular aura about
Re: writing reusable code / preparing for the future

We have a few minor classes that end up being re-used from year to year (well, only one year with the new system). Primarily PID-related stuff (dual-motor offsets, PIDInput classes, etc)
__________________

"To have no errors would be life without meaning. No strugle, no joy"
"A network is only as strong as it's weakest linksys"
  #5   Spotlight this post!  
Unread 29-05-2010, 10:49
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

A good way to handle library changes is to not call the library in your classes. This will do two things:
1. make the code usable in places where you did not intend on using it, e.g. if you had a pot + motor you could now use it for an encoder+motor instead.
2. Allow you to handle library changes.

Last years code dosen't compile now? it *should*, since there were no modifications to the interface of existing VI's, just modifications within and new ones, at least in LabVIEW.
__________________
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
  #6   Spotlight this post!  
Unread 29-05-2010, 11:04
Zme Zme is offline
Registered User
FRC #2619
 
Join Date: Jan 2009
Location: Michigan
Posts: 83
Zme is on a distinguished road
Re: writing reusable code / preparing for the future

We use c, and while there were not a lit of changes there were just enough to make it throw errors, took a couple of minutes to fix, not a big deal if you know what are you doing, but still a pain, and it kinda defeats the purpose
  #7   Spotlight this post!  
Unread 29-05-2010, 12:11
virtuald's Avatar
virtuald virtuald is offline
RobotPy Guy
AKA: Dustin Spicuzza
FRC #1418 (), FRC #1973, FRC #4796, FRC #6367 ()
Team Role: Mentor
 
Join Date: Dec 2008
Rookie Year: 2003
Location: Boston, MA
Posts: 1,091
virtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant future
Re: writing reusable code / preparing for the future

Keep in mind that any code you use on your robot but do not write during the build season *must* be COTS software or released for all other teams to use.
__________________
Maintainer of RobotPy - Python for FRC
Creator of pyfrc (Robot Simulator + utilities for Python) and pynetworktables/pynetworktables2js (NetworkTables for Python & Javascript)

2017 Season: Teams #1973, #4796, #6369
Team #1418 (remote mentor): Newton Quarterfinalists, 2016 Chesapeake District Champion, 2x Innovation in Control award, 2x district event winner
Team #1418: 2015 DC Regional Innovation In Control Award, #2 seed; 2014 VA Industrial Design Award; 2014 Finalists in DC & VA
Team #2423: 2012 & 2013 Boston Regional Innovation in Control Award


Resources: FIRSTWiki (relaunched!) | My Software Stuff
  #8   Spotlight this post!  
Unread 29-05-2010, 13:16
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

Remember inheritances, you can just inherit the prewritten class and in the inherited class, just modify the functions that need modification or something
__________________
Do not say what can or cannot be done, but, instead, say what must be done for the task at hand must be accomplished.
  #9   Spotlight this post!  
Unread 29-05-2010, 13:45
Zme Zme is offline
Registered User
FRC #2619
 
Join Date: Jan 2009
Location: Michigan
Posts: 83
Zme is on a distinguished road
Re: writing reusable code / preparing for the future

Quote:
Originally Posted by virtuald View Post
Keep in mind that any code you use on your robot but do not write during the build season *must* be COTS software or released for all other teams to use.
Thank you for the reminder, the code is meant to be used as an example only. I will be sure to talk it over with mentors on the team so they know the situation and we will make a decision then as to if we should release it for use, and if so how to go about it.

As for inheritance, yes it is often useful and yes it could be used here, but things change and I feel that doing this with inheritance would make the problem worse by tying directly to that class
  #10   Spotlight this post!  
Unread 29-05-2010, 13:50
Chris is me's Avatar
Chris is me Chris is me is offline
no bag, vex only, final destination
AKA: Pinecone
FRC #0228 (GUS Robotics); FRC #2170 (Titanium Tomahawks)
Team Role: Mentor
 
Join Date: Dec 2008
Rookie Year: 2006
Location: Glastonbury, CT
Posts: 7,766
Chris is me has a reputation beyond reputeChris is me has a reputation beyond reputeChris is me has a reputation beyond reputeChris is me has a reputation beyond reputeChris is me has a reputation beyond reputeChris is me has a reputation beyond reputeChris is me has a reputation beyond reputeChris is me has a reputation beyond reputeChris is me has a reputation beyond reputeChris is me has a reputation beyond reputeChris is me has a reputation beyond repute
Send a message via AIM to Chris is me
Re: writing reusable code / preparing for the future

Quote:
Originally Posted by davidthefat View Post
Remember inheritances, you can just inherit the prewritten class and in the inherited class, just modify the functions that need modification or something
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.
__________________
Mentor / Drive Coach: 228 (2016-?)
--2016 Waterbury SFs (with 3314, 3719), RIDE #2 Seed / Winners (with 1058, 6153), Carver QFs (with 503, 359, 4607)
Mentor / Consultant Person: 2170 (2017-?)
.
College Mentor: 2791 (2010-2015)
-- 2015 TVR Motorola Quality, FLR GM Industrial Design -- 2014 FLR Motorola Quality / SFs (with 341, 4930)
-- 2013 BAE Motorola Quality, WPI Regional #1 Seed / Delphi Excellence in Engineering / Finalists (with 20, 3182)
-- 2012 BAE Imagery / Finalists (with 1519, 885), CT Xerox Creativity / SFs (with 2168, 118)
Student: 1714 (2009) - 2009 MN 10K Lakes Regional Winners (with 2826, 2470)
2791 Build Season Photo Gallery - Look here for mechanism photos My Robotics Blog (Updated April 11 2014)
  #11   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.
  #12   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
  #13   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
  #14   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
  #15   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 22:56.

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