Shop OBEX P1 Docs P2 Docs Learn Events
Create A Library? — Parallax Forums

Create A Library?

ajwardajward Posts: 1,130
edited 2015-02-26 13:51 in Learn with BlocklyProp
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

Comments

  • prof_brainoprof_braino Posts: 4,313
    edited 2015-02-25 06:06
    Do it. If somebody reads reads it, and asks questions, answer them (i.e fix the library) and continue. If nobody asks questions (gives you something to fix) its either perfect (unlikely) or unread; in that case move on to something else.

    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.
  • GordonMcCombGordonMcComb Posts: 3,366
    edited 2015-02-26 10:48
    I don't usually place servo control functions in a separate library, as I'm constantly changing and tweaking them anyway. Libraries are great for "locked down" code, or at least code you don't suspect will change much. If you're new to the coding, it's hard to tell what you might change, I think you want to be flexible. Having the code in a library won't reduce the memory footprint of the project.

    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.
  • GenetixGenetix Posts: 1,754
    edited 2015-02-26 13:51
    Amanda,

    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.
Sign In or Register to comment.