John,
I implemented the start and stop commands as you suggested and it works … sort-of. It worked twice and then the program hung … I did not have a chance to dig into thus further so cannot tell if the problem is in what I’ve done or in the libpixyusb library … I will do some more digging when I have some time.
I did manage to get this working instead by doing the following:
while(True)
…
pixy_close()
…
pixy_init()
pixy_command(“cmd_getFrame”, …
This essentially accomplishes the same thing you were suggesting, but I assume my solution is very inefficient. For now it works until I can figure out what is going on with the ‘stop’ … ‘start’ sequence.
I did have to fix an issue with libpixyusb to be able to init/close the pixy connection multiple times. The variable ‘interpreter’ in pixy.cpp is global … meaning that it is not destroyed until the program exits. This is a problem as this means that the underlying objects (like the USB connection) are not properly re-initialized on a close() and this means that the next init() call fails. I resolved this by making ‘interpreter’ a pointer and explicitly creating it in the init() function and explicitly deleting it in the close() function … I am now able to init()/close() the pixy connection as many times as I want.
I am wondering if there is a similar problem with the ‘start’ / ‘stop’ sequence? (When pixy_command(“stop”, … is called the thread sitting on this connection spits out error messages until “start” is called.)
I have now successfully compiled and run this python code on a Mac laptop and an RPi … the Pi refresh is slow but the Python code is very inefficient right now … all of the image setup is being done in interpreted python code.
Chris
PS - I committed all of these changes to github.