Python question

How would you feel about turning gopigo.py from a module into a package? I imagine keeping the basic controls in the base lib (from gopigo import *), but then being able to add helper functions. e.g. I would love to be able to use left(90) in both Scratch and Python projects to turn it 90° to the left.

Currently, I would have to either re-write/maintain the same code for both (I am morally opposed to this), import from a non standard location, add the helper functions to the gopigo.py module (hard to scale), or write and install my own separate py helper package (makes it hard to share).

Of course, I don’t want to impose my methodologies onto your project, but I mocked up what it would look like in github:

thoughts?

I’m not sure what you mean by taking a module and making it into a package but for the turning issue

Well for my left turn 90 degress i set up a function in python

left90():
left()
time.sleep(1)
stop()

I imported time into my program

What I mean is that currently, if I want to share the left90() function with multiple python projects and even Scratch, then I should install it in a place that is globally reachable. For functions specific to the project, they would be kept in the project’s codespace, but general utility functions tied to the gopigo project, perhaps within a gopigo package is more appropriate. That way, when you install the gopigo package, you get the utility functions as well.

e.g. I built a function for scratch to turn the device n degrees:

        elif msg[:4]=="LEFT":
            if en_gpg:
                if len(msg) > 4:
                    deg= int(msg[4:])
                    pulse= int(deg/DPR)
                    enc_tgt(0,1,pulse)
                left()

But, this can only be used for Scratch programming. I would like to be able to create a function in the gopigo package called, for example, left_deg:

def left_deg(deg):
    deg = int(deg)
    pulse = int(deg/DPR)
    enc_tgt(0,1,pulse)
    left()

Then, maybe change Scratch to be:

from gopigo.utils import left_deg
        elif msg[:4]=="LEFT":
            if en_gpg:
                if len(msg) > 4:
                    left_deg(int(msg[4:]))
                else:
                    left()

Then, maybe write a python program to move forward until it comes within an obstacle, then use the US to scan the room to find a hole big enough to fit through, and then turn the appropriate number of degrees.

e.g.

if dist < 20:
    ang = find_hole()
    *do math to convert deg to left/right*
    left_deg(deg)

or I dunno, I could probably abstract away even more of that, but the point is to minimize the amount of code that has to be repeated.

When others wrote code to add even more useful utility-type functions, they could simply add it to the gopigo package.

Does that make sense? or am I just doing a horrible job explaining this.