Spin programming structure.
Dgswaner
Posts: 795
first of all pardon my terminology,
I've been working on each component and getting the connections and code working for each sensor and motor/servo control. I'm about to the point of putting it all together but I was looking for some pointers about how to structure it. I'll see if I can make this clear.
this is how I have it structured.
Main program
Fullduplex serial
soundgen (sound)
PING
and few others
If I want to add code for motor control should I add it in the main program or make an object for it. I could see that working fine either way, but I also want to have a section of code for having my bot rotate slowly reading a compass and turning until it's facing a desired direction. this could use the first object or just a function. are there any benefits about using one method vs another? if I use more objects I'll have to use more global vars. with a host of sensors and functions could I run out of variable space? if I have most of the objects in the main program I'll have 10+ object besides the ones referenced by the objects.
here is what I mean:
main program
objects.....
Motor control
HB55
full duplex serial
VS
Main program
Objects...
Motor control
HB55
full duplex serial
I don't quite know how to plan this. does keeping the main program small and having lots of object save memory? or is it better to keep most of the code in the main program.
I'm sure that each situation is different and I'm not asking for a complete map of how this bot should be programmed. I'm asking for the "good rule of thumb" guidance for projects in general. I have a ton of sensors and I plan on adding a few more. I'm a little worried about running out of memory. and or variable space.
and insight would be appreciated.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"A complex design is the sign of an inferior designer." - Jamie Hyneman, Myth Buster
DGSwaner
Post Edited (Dgswaner) : 12/20/2007 10:30:07 PM GMT
I've been working on each component and getting the connections and code working for each sensor and motor/servo control. I'm about to the point of putting it all together but I was looking for some pointers about how to structure it. I'll see if I can make this clear.
this is how I have it structured.
Main program
Fullduplex serial
soundgen (sound)
PING
and few others
If I want to add code for motor control should I add it in the main program or make an object for it. I could see that working fine either way, but I also want to have a section of code for having my bot rotate slowly reading a compass and turning until it's facing a desired direction. this could use the first object or just a function. are there any benefits about using one method vs another? if I use more objects I'll have to use more global vars. with a host of sensors and functions could I run out of variable space? if I have most of the objects in the main program I'll have 10+ object besides the ones referenced by the objects.
here is what I mean:
main program
objects.....
Motor control
HB55
full duplex serial
VS
Main program
Objects...
Motor control
HB55
full duplex serial
I don't quite know how to plan this. does keeping the main program small and having lots of object save memory? or is it better to keep most of the code in the main program.
I'm sure that each situation is different and I'm not asking for a complete map of how this bot should be programmed. I'm asking for the "good rule of thumb" guidance for projects in general. I have a ton of sensors and I plan on adding a few more. I'm a little worried about running out of memory. and or variable space.
and insight would be appreciated.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"A complex design is the sign of an inferior designer." - Jamie Hyneman, Myth Buster
DGSwaner
Post Edited (Dgswaner) : 12/20/2007 10:30:07 PM GMT
Comments
you are just touching one of the least understood and most researched topics of software engineering, called "programming in the large".
I could recommend you 5 books out of 50, but I doubt you will profit from reading them as they use specific notation ("UML") which even could be a problem "per-se"
The main key is still "experience" and "good taste".
So I can only recommend the "hard way": Program two or three versions and see how you like them.
One of the rules of thumb for modularization is:
- Increase cohesion within modules
- Decrease coupling between modules
You should not care about implementation considerations, as the amount of variables or the overhead it might take to call another object compared to calling a local routine. Of course, when you pass a limit, you have to, but I am not aware of such a limit in your case.
The main issue for larger programs ist: Can it still be understood what is going on?
I just stumbled over this link wich - though highly technical - will give you an idea what box of pandora you have opended.... www.csc.liv.ac.uk/~igor/COMP201/files/SE_L14L15.ppt
but I'm not sure what you mean by decrease coupling between modules." limit the amount of objects calling other objects, and have the main program call each different object?
I guess after 33 years I'm tired of learning the hard way, I'm hoping for a few "good taste" tips so I can ease my work load.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"A complex design is the sign of an inferior designer." - Jamie Hyneman, Myth Buster
DGSwaner
You have to develop your own "good taste"
("White wine for the fish, red wine with the beef, a glass of champagne with the chicken, and some port after the cheese...")
I'd say:
* Create an object when you have definite plans to reuse a piece of functionality in more than one program. Or when you are going to release it for others to use.
* If you are using multiple cogs, put the functionality for each different cog into a separate object. The main (top object) usually being what runs in cog 0.
Other than that, usually just do things in methods in your main program.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Help to build the Propeller wiki - propeller.wikispaces.com
Play Defender - Propeller version of the classic game
Prop Room Robotics - my web store for Roomba spare parts in the UK
The world is your oyster. Plan to use more than one prop in your system and in the beginning develop a very simple signaling system... so that you can switch modes easily. Take a look at Andre LaMothe's book... it is full of interesting factoids that aren't immediately obvious to a complete novice after a good year of hacking around the forum and the other info sources. I particularly like his approach to networking... nice and simple.
Rich
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"A complex design is the sign of an inferior designer." - Jamie Hyneman, Myth Buster
DGSwaner