Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Odd timing behavior on RPi 4 (Raspian) #1151

Open
lhstrh opened this issue May 10, 2022 · 1 comment
Open

Odd timing behavior on RPi 4 (Raspian) #1151

lhstrh opened this issue May 10, 2022 · 1 comment
Assignees

Comments

@lhstrh
Copy link
Member

lhstrh commented May 10, 2022

I was able to recreate the problem, using a much simpler LF program below.

Source Code

    target Python;
    
    preamble {=
        import sys
        import pprint as pp
        import numpy as np
        import threading
        import time
    
        getLocalTime = lambda : time.strftime("%d %b %Y %H:%M:%S",time.localtime())
    
    =}
    
    reactor StereoCam {
        output rgbFrame
        output disparityMap
        state captureThread
        state captureThreadEnable
        physical action actionReadDisparityMap
        preamble {=         
            def luxonisThread(self,
                              actionReadDisparityMap):
                """
                    Continuouslty collect rgbFrames and disparity frames
                    from the webcam.
                """
                frameCnt = 0
                if self.captureThreadEnable.is_set():
                    while True:
                        print(f"{getLocalTime()}@Trying to capture disparity {frameCnt}")
                        actionReadDisparityMap.schedule(0,(lf.time.physical_elapsed(),frameCnt))
                        print(f"{getLocalTime()}@Captured disparity {frameCnt}")
                        frameCnt += 1
                        time.sleep(5)
        =}  
        
        reaction(startup) -> actionReadDisparityMap {=
            self.captureThreadEnable = threading.Event()
            self.captureThreadEnable.set()
            self.captureThread = threading.Thread(
                target = self.luxonisThread,
                args = (actionReadDisparityMap,)
            )
            self.captureThread.start()
        =}
    
        reaction(actionReadDisparityMap) -> disparityMap {=
            elapsedTime, disparityMapData = actionReadDisparityMap.value
            disparityMap.set(disparityMapData)
        =}
    
        reaction(shutdown) {=
            self.captureThreadEnable.clear()
            self.captureThread.join()
        =}
    }
    
    reactor plotter {
        input rgbFrame
        input disparityMap
        
        reaction(disparityMap) {=
            print(f"{getLocalTime()}@frame captured:{disparityMap.value}")
        =}
    
    }
    
    main reactor {
        plttr = new plotter()
        strcam = new StereoCam()
        strcam.rgbFrame -> plttr.rgbFrame
        strcam.disparityMap -> plttr.disparityMap
    }

The StereoCam reactor defines a function luxonisThread in the preamble, that schedules a actionReadDisparityMap inside a while True loop. After invoking schedule in every iteration it sleeps for 5s.

The StereoCam reactor defines three reactions, the startup reaction, that creates a thread and passes the luxonisThread as it thread function. It also sets the necessary flags (captureThreadEnable state) to trigger the while loop in the luxonisThread function. The actionReadDisparityMap reaction when triggered extracts the counter value that is set during each iteration of luxonisThread. The extracted value is then pushed via the output port disparityMap. The shutdown if for cleanup functions.

The plotter reactor takes the disparityMap from StereoCam reactor and prints its value.

The get the following problem after running the python code.
image

Basically the print(f"{getLocalTime()}@Captured disparity {frameCnt}") never executes. So I am guessing that it is stuck in actionReadDisparityMap.schedule(0,(lf.time.physical_elapsed(),frameCnt)).

I am running the generated python code in Raspberry-Pi4 (Linux pios3 5.15.32-v7l+ #1538 SMP Thu Mar 31 19:39:41 BST 2022 armv7l GNU/Linux). The lfc compiler is also invoked from the same host.

Originally posted by @Arka2009 in #1116 (comment)

@Arka2009
Copy link

Thanks, @lhstrh for creating a separate issue on this topic.

@Soroosh129 Soroosh129 assigned Soroosh129 and unassigned Soroosh129 May 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants