Create A Library?
![ajward](https://forums.parallax.com/uploads/userpics/615/n38M10FI7ZZL5.jpg)
Hi All... A late night (early morning) query.
I have my BoeBot (running C on a Prop BOE) doing some very rudimentary navigation using information from the Ping sensor. There are a number of functions for maneuvering when an obstacle is encountered... backing up a short distance and doing 45, 90 and 180 degree turns both CW and CCW.
I was wondering if it would make sense to put those functions into a library? Right now the code is only 85 lines and not too complicated (at least to me!). As I tinker with Bob, I'm working my through the Propeller C tutorials and I'm starting the section on libraries. I'd like to apply that knowledge to my project... something other than printing that someone is awesomely epic! :-)
Any thoughts... pros or cons?
Thanks!
Amanda
I have my BoeBot (running C on a Prop BOE) doing some very rudimentary navigation using information from the Ping sensor. There are a number of functions for maneuvering when an obstacle is encountered... backing up a short distance and doing 45, 90 and 180 degree turns both CW and CCW.
I was wondering if it would make sense to put those functions into a library? Right now the code is only 85 lines and not too complicated (at least to me!). As I tinker with Bob, I'm working my through the Propeller C tutorials and I'm starting the section on libraries. I'd like to apply that knowledge to my project... something other than printing that someone is awesomely epic! :-)
Any thoughts... pros or cons?
Thanks!
Amanda
Comments
The first audience is you. If it helps you, it can help someone else. If you comeback and read it in two weeks, and it helps, or makes perfect sense, or leaves you scratching your head, you have an idea what a new reader will feel.
This doesn't mean you can't put the servo control code into functions, and then call the functions from your main program loop.
So in sum, until you know your code is static and generalized enough for a library, I'd just leave it in your main file, and copy and paste when you want to create a new project.
You can address Gordon's issue by making your functions parametric and then feeding things such as speeds, times, and distances to the function when it called.
If the list gets to big then use an array and simply feed the function an array pointer.