PYNQ: PYTHON PRODUCTIVITY FOR ZYNQ

Dumb as a stone

That’s how I feel about asking the following question

Why doesn’t this work? You may recognize it from countless OpenCV examples.

import cv2
while True:
k = cv2.waitKey(1) & 0xFF
# press ‘q’ to exit
if k == ord(‘q’):
print(“q”)
break
elif k == ord(‘b’):
print(“b”)
# change a variable / do something …
elif k == ord(‘k’):
print(“k”)
# change a variable / do something …

Running this the code immediately exits the cell, without error

If I change the test to False it immediately exists the cell, without error

import cv2

while True:
    k = cv2.waitKey(1) & 0xFF
    # press 'q' to exit
    if k == ord('q'):
        break
    elif k == ord('b'):
        # change a variable / do something ...
    elif k == ord('k'):
        # change a variable / do something ...

There seems to be something about the environment that I’m missing:(

How exactly should one keep a code loop running like say some image processing algorithm until there is a “q” pressed?

Jupyter notebook cells can be stopped, or you can trigger an interrupt from the menu: Kernel -> Interrupt

Cathal

Yes, but unfortunately it’s not quite that simple.

In practice I’m running a camera and camera.release() needs to run when the program exits. If this is not done then typically I have to completely re-power the Ultra96.

camera = cv2.VideoCapture(0) MUST be mated to camera.release,

This is even more insidious in that this is an embedded system that will be stuck deep inside a bigger machine and will not always have it’s nice development environment available.

Thus a kernel interrupt is not allowed.

OK, so it seems you want some interactive control of your program flow.
It seems like you could do this with a widget in the notebook, but that may not be the end solution.

How will you eventually run your application and how do you want to trigger this action - from a keypress? Will this be a python program running in a terminal?

Cathal

This simple problem goes to the very heart of the interface of Jupyter and the way it functions. As you know, ZMQ is used to pass messages within the Jupyter framework.That would be the preferred method…

Is it possible for the PL to generate an interrupt that the PS side sees and can respond to within a Jupyter program running on PYNQ?

If the answer is yes, then reference citation would be really helpful.

If not, then perhaps this needs some discussion on how best to proceed.

What exactly is PYNQ behind the curtain?

Yes, PYNQ supports interrupts via Python asyncio
:
https://pynq.readthedocs.io/en/v2.5.1/pynq_libraries/interrupt.html
https://pynq.readthedocs.io/en/v2.5.1/overlay_design_methodology/pynq_and_asyncio.html#pynq-and-asyncio
https://pynq.readthedocs.io/en/v2.5.1/pynq_package/pynq.interrupt.html

Cathal