[Tutor] Let imported module access calling program

Shrutarshi Basu technorapture at gmail.com
Tue Mar 25 03:43:51 CET 2008


>  This seems kind of strange to me. You want the entire user module to be
>  re-run? Why don't you want looping and timing to be under the user's
>  control? Can you show a short example of what the user code might look like?
>
>  Kent
>


Well perhaps not the entire module, but probably most of it. Here's an
example. Suppose you want to define a simple obstacle avoidance
behavior, the script should be something similar to:

import robot
if robot.sensor('front') > 100:
    robot.left_turn()

Defining the sensor() and left_turn() functions is no problem, but
this should be a continuous behavior, hence the need to run it over
and over at certain time intervals. I already have a config.py
(accessed by robot.py and a few other modules) which the user can
modify to set the intervals (and other details). i've also been
thinking about creating a controller.py which handles the repetition
and imports the user's code and runs its functions, but i would still
like to explore this method.
Thanks again,
Basu


More information about the Tutor mailing list