Susan Fox wrote:
Hi, there,
I am working to integrate Monte Carlo Localization into my Pyro robot.
Because the localization code bogs down the brain, I was trying to use
the model from the Advanced Devices page for the LogicDevice. The
example suggests using a separate process for the slow "thinking" part.
I am assuming that spawning a separate *thread* isn't sufficient. In
other words, I tried replacing the "time.sleep(2)" part with the
localization step, and it still bogged down the system. Do I have to
run the localization as a wholly separate process and have Pyro
communicate with it, or is there some way to do it from within Pyro?
I'm wondering if anyone has done something similar and might be willing
to share ideas or code examples.
Thanks,
Susan
Susan,
Although that code should work, we have also made that code part of Pyro
and can be activated by simply passing in a "async = 1" parameter to any
device constructor. For example, in a pyrobot/plugins/device/ file you
could:
from pyrobot.robot.device import Device
def INIT(robot):
return Device(async=1)
or, of an object of your own making:
from pyrobot.robot.device import Device
import time, random
class AsyncDevice(Device):
def __init__(self):
Device.__init__(self, async = 1)
def update(self):
print "Running...",
time.sleep(random.random() * 10)
print "Done!"
def INIT(robot):
return {"adevice": AsyncDevice()}
I just tested those, and it works as expected (ie, long-running
processes don't affect the GUI or other devices at all). So, yes,
spawning a new thread should be sufficient. However, there is at least
one complication....
On some operating systems (or some older versions of the Linux kernel)
we have found that this doesn't work right. It seems that the kernel is
not letting separate threads under Python correctly.
If the above doesn't help, let us know what OS and kernel, and what
version of Python.
-Doug
_______________________________________________
Pyro-users mailing list
[email protected]
http://emergent.brynmawr.edu/mailman/listinfo/pyro-users