Go to Post If you find yourself extremely upset, frustrated, angry, or any other term of emotion, please stop and ask yourself why you participate in FIRST. - indieFan [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 12-10-2007, 11:07
tubeheaD37 tubeheaD37 is offline
Registered User
FRC #2079
 
Join Date: Jan 2007
Location: Massachusetts
Posts: 21
tubeheaD37 is on a distinguished road
Architecture for software

Last year, as the only programmer on the team, and with only a limited knowledge of programming myself, our code turned out disgusting, disorganized, and generally, not pretty. Over the summer I did some learning, and now, its almost time again to attempt to program the robot.

In order to organize myself and the few other team members who are now willing to help me, I decided to create an architecture for the software so that there is a plan for every method and an overarching plan for what the software should look like in the end. Does anyone know of any similar projects which have been done before? Anyone have any good adivce for how to go about this?
  #2   Spotlight this post!  
Unread 12-10-2007, 11:41
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,113
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
Re: Architecture for software

When I came on board as the programming mentor for the TechnoKats in 2004, I didn't know anything about the IFI control system. I did have some clear ideas on software architecture, and they fortunately turned out to match the way things were set up in the system. I have three basic pieces of advice for everyone who starts with the default code.

First, make good use of abstractions. Don't write code that directly names joystick input pins and pwm output pins. Instead, use aliases like this:
Code:
#define OI_LeftDrive			p3_y
#define OI_RightDrive			p4_y
#define RC_DIG_Pressure			rc_dig_in09
#define RC_RLY_Compressor		relay6_fwd
#define RC_PWM_LeftFront_CIM		pwm09
#define RC_PWM_LeftRear_CIM		pwm10
#define RC_PWM_RightFront_CIM		pwm11
#define RC_PWM_RightRear_CIM		pwm12

Second, try to split the functions that read the operator inputs from the functions that set the motor and relay outputs, and try to keep both of them distinct from the functions that turn inputs into outputs. Put all your OI stuff in the equivalent of Default_Routine(), and keep track of what your operators are requesting in a global variable structure containing things like desired speed, desired turn rate, desired arm position, etc. Put all your motor control stuff in Process_Data_From_Local_IO(), basing the outputs on what's in that global variable structure. Put the code that decides how to change from what the robot is doing now to what it's supposed to do next in a separate function that manipulates the global structure based on robot sensors. It might seem inefficient to do it that way, but it permits a lot of flexibility, and the RC has plenty of power.

Finally, try to keep separate tasks in separate functions, but try to keep everything relating to a specific robot subsystem together. Our 2007 program has functions like Read_OI_Input() and Write_OI_Feedback() in the user_routines.c file, and process_feedback(), process_drivebase(), and process_arm() in user_routines_fast.c.
  #3   Spotlight this post!  
Unread 12-10-2007, 12:59
EHaskins EHaskins is offline
Needs to change his user title.
AKA: Eric Haskins
no team (CARD #6 (SCOE))
Team Role: College Student
 
Join Date: Jan 2006
Rookie Year: 2006
Location: Elkhorn, WI USA
Posts: 998
EHaskins has a reputation beyond reputeEHaskins has a reputation beyond reputeEHaskins has a reputation beyond reputeEHaskins has a reputation beyond reputeEHaskins has a reputation beyond reputeEHaskins has a reputation beyond reputeEHaskins has a reputation beyond reputeEHaskins has a reputation beyond reputeEHaskins has a reputation beyond reputeEHaskins has a reputation beyond reputeEHaskins has a reputation beyond repute
Send a message via MSN to EHaskins
Re: Architecture for software

I had the exact same experiance my first year. I did have some knowlege of PC programming, but nothing like the RC.

I suggest you take your code from 07, and re-organize it so its logical. If you take your code, and look to see exactly where and how you went wrong, you will have a much better chance of avoiding those mistakes next time.

If you want a good book to read on the subject, I suggest Steve McConnell's Code Complete. It is aimed at professional PC programmers, but it has a lot of good advice.
__________________
Eric Haskins KC9JVH
  #4   Spotlight this post!  
Unread 13-10-2007, 09:39
Robostang 548's Avatar
Robostang 548 Robostang 548 is offline
I can program the future...
AKA: Don
FRC #0548 (Robostangs)
Team Role: Programmer
 
Join Date: Jan 2007
Rookie Year: 2006
Location: Northville Mi
Posts: 69
Robostang 548 is on a distinguished road
Send a message via AIM to Robostang 548 Send a message via MSN to Robostang 548 Send a message via Yahoo to Robostang 548
Re: Architecture for software

Our team created a patterns and practices document because we have a total of nine programmers this year. It drew out some simple and easy to follow guiedlines for commenting our code as well as the naming of variables constants, and alliases. While we try to create alot of pc programming projects (scouting software, etc) to keep our programmers busy durring the build season (to many people working with the RC just slows us down), the supreem law of the land on our team is that no programmer should have nothing to do because he/she can always doccument their code better.

-Don
__________________

Team 548:
Attending National Championship, Genesee District, Detroit District 2, West Michigan District, Michigan Championship?


  #5   Spotlight this post!  
Unread 13-10-2007, 09:57
lukevanoort lukevanoort is offline
in between teams
AKA: Luke Van Oort
no team
 
Join Date: Oct 2005
Rookie Year: 2005
Location: Waterloo, ON, Canada
Posts: 1,873
lukevanoort has a reputation beyond reputelukevanoort has a reputation beyond reputelukevanoort has a reputation beyond reputelukevanoort has a reputation beyond reputelukevanoort has a reputation beyond reputelukevanoort has a reputation beyond reputelukevanoort has a reputation beyond reputelukevanoort has a reputation beyond reputelukevanoort has a reputation beyond reputelukevanoort has a reputation beyond reputelukevanoort has a reputation beyond repute
Send a message via AIM to lukevanoort
Re: Architecture for software

Diagramming is very handy too. Depending on how complex your code is, it may seem a waste of time; it's not, a good diagram can greatly increase programming efficiency. For example, the simplest diagram is just a block diagram that defines various 'blocks' of code and their interactions, and once you have a block-level diagram you can then set each programmer to develop a different 'block.' If the diagram is good enough, with defined interblock interfaces, all the programmers can be working on and completing code independent of each other.

There are many other types of diagrams, but I feel most are probably not worthwhile in our application. The only other one I can think of that is worthwhile is the 'Use Case Model'--essentially a stimulus-response chart. A use case diagram diagrams out how a program will respond to users inputs.

A decent, free program for diagramming is Dia. Check it out, it has more type of diagramming than a programming team could ever need. (unless you dabble in cybernetics, telephony, and hydraulics)
__________________
Team 1219: 2009 - Mentor
Team 587: 2005 - Animator, 2006-2008 - Team Captain
  #6   Spotlight this post!  
Unread 13-10-2007, 12:45
Tom Bottiglieri Tom Bottiglieri is offline
Registered User
FRC #0254 (The Cheesy Poofs)
Team Role: Engineer
 
Join Date: Jan 2004
Rookie Year: 2003
Location: San Francisco, CA
Posts: 3,187
Tom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond repute
Re: Architecture for software

Try to organize data in predefined structures and write generic functions that do work on those structures. That way if you would like to create a new instance of *something*, you can do it with limited headache. This worked well for us with things like PID control loops.

Code:
typedef struct{
  int	dState,      	// Last position input
	iState,      	// Integrator state
	iMax, 
	iMin,  	        // Maximum and minimum allowable integrator state

	iGain,    	// integral gain
        pGain,    	// proportional gain
        dGain;     	// derivative gain

  unsigned char mode1; //0 for position, 1 for velocity

} PID;
And then you can use the data like this
Code:
//Global
PID shoulder;
PID wrist;

//Function Call
void SetUpMotor(){
   InitPID(&shoulder,p,i,d,imin,imax);
   InitPID(&wrist,p2,i2,d2,imin2,imax2);
{
    
    
//Function Definition
void InitPID(PID *pid,int p, int i, int d, int i_min, int i_max)
{
    pid->pGain = p;
    pid->iGain = i;
    pid->dGain = d;
    pid->iMin=i_min;
    pid->iMax=i_max;
}
Notice how we created 2 separate PID loops with minimal code. This mimics object oriented languages like C++ or Java.
Be very careful with pointers. If you accidentally write over a reference and not a value, you will get undefined behavior out of your program (no compiler error or runtime error, just lots of weird stuff happening)

Last edited by Tom Bottiglieri : 13-10-2007 at 12:49.
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
Software for RCX 2.0 Spiritling Lego Mindstorm Discussion 0 05-01-2007 02:38
Vex SW Architecture yogibear Programming 4 01-12-2006 15:14
Software for Camera if any Silentbob1217 Programming 4 05-10-2006 18:36


All times are GMT -5. The time now is 19:44.

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