简体   繁体   English

C ++ Qt异步进程快速计时建议

[英]C++ Qt fast timing of asynchronous processes advice

i'm currently dealing with a Qt GUI i have to set up for a measurement device. 我目前正在处理Qt GUI,必须为测量设备进行设置。 The device is working with a frame grabber card which grabs images from a line camera really fast. 该设备正在与抓帧卡配合使用,该抓卡卡可以非常快地从线摄像机抓取图像。 My image processing which is not that complex takes 0.2ms to complete, and it takes about 40ms to display the signal and the processing result with QCustomPlot which is totally okay. 我的图像处理不是那么复杂,需要0.2毫秒才能完成,用QCustomPlot显示信号和处理结果大约需要40毫秒,这完全可以。 Besides the GUI output the processed signal will also be put out as an analog signal by a NI DAQ device. 除了GUI输出之外,NI DAQ设备还将处理后的信号作为模拟信号输出。

My problem is that i have to update the analog signal with a constant frequency and still update the GUI from time to time. 我的问题是我必须以恒定的频率更新模拟信号,并且仍然不时更新GUI。

My current approach or idea was to create a data pool thread and two worker threads. 我当前的方法或想法是创建一个数据池线程和两个工作线程。 One worker thread receives the data from the frame grabber, processes it an updates the data pool. 一个工作线程从帧捕获器接收数据,对其进行处理并更新数据池。 The second worker thread updates the analog channel of the NI DAQ with a certain frequency of about 2-5kHz given by a clock in the NI DAQ device. 第二个工作线程使用NI DAQ设备中的时钟给定的大约2-5kHz的特定频率更新NI DAQ的模拟通道。 And the GUI thread would read the data pool from to time to time to update the signal display with a rate of about 20-30Hz. GUI线程会不时读取数据池,以大约20-30Hz的速率更新信号显示。

I wanted to use the Qt thread management and he signal-and-slot mechanism because of its "simplicity" and because i already worked with threads in combination with Qt and its thread classes. 我想使用Qt线程管理和他的信号和时隙机制,因为它的“简单性”,并且因为我已经使用过与Qt及其线程类结合使用的线程。

Is there maybe a better way, does somebody have an idead or any suggestion? 有没有更好的方法,有人有想法或建议吗? Is it possible that i get problems in the timing of the threads? 我可能在线程的时间安排上遇到问题吗?

Furhtermore is it possible to assign one thread to one single CPU core on a multi core CPU, so that this core only processes this single thread? 此外,是否可以将一个线程分配给多核CPU上的单个CPU内核,以便该内核仅处理该单个线程?

Is there maybe a better way, does somebody have an idead or any suggestion? 有没有更好的方法,有人有想法或建议吗? Is it possible that i get problems in the timing of the threads? 我可能在线程的时间安排上遇到问题吗?

Signal/Slot mechanism is fine, try it and if you get into performance issues you can still try to find another approach. 信号/插槽机制很好,尝试一下,如果遇到性能问题,您仍然可以尝试找到另一种方法。 I used Signal/Slot Mechanism for real-time video processing with QAbstractVideoSurface and Mediaplayer. 我使用信号/插槽机制通过QAbstractVideoSurface和Mediaplayer进行实时视频处理。 It worked for me. 它为我工作。

Furhtermore is it possible to assign one thread to one single CPU core on a multi core CPU, so that this core only processes this single thread? 此外,是否可以将一个线程分配给多核CPU上的单个CPU内核,以便该内核仅处理该单个线程?

Why would you do that? 为什么要这么做? The operating system or threading library has a scheduler, which takes care of such things. 操作系统或线程库具有一个调度程序,负责处理此类事情。 As long you got no good reason doing this yourself, you should just use the existing way. 只要您没有充分的理由自己进行此操作,就应该使用现有方法。

I would try it with three threads: 1)UI thread, 2)grab-and-process thread, 3)analogue output thread. 我会尝试使用三个线程:1)UI线程,2)抓取和处理线程,3)模拟输出线程。

The trick is to use a triple buffer to connect output of grab-and-process to input of analogue output. 诀窍是使用三重缓冲区将抓取和处理的输出连接到模拟输出的输入。

Say, at moment t , thread(2) finishes processing frame[(t+0)%3] , change output destination to frame[(t+1)%3] immediately, and notifies thread(3), which is looping through data in frame[(t+2)%3] , to switch to frame[(t+0)%3] when appropriate. 说,在时刻t ,线程(2)完成对frame[(t+0)%3] ,立即将输出目标更改为frame[(t+1)%3] ,并通知正在循环通过的线程(3) frame[(t+2)%3] ,以在适当时切换到frame[(t+0)%3]

I used this technique when I was working on an image processing project that has a 10fps processing frame rate and a 60fps NTSC output frame rate. 当我在具有10fps处理帧速率和60fps NTSC输出帧速率的图像处理项目上工作时,便使用了此技术。 To eliminate the tearing effect , a circular buffer with three buffers is the least. 为了消除tearing effect ,最少需要三个缓冲区的循环缓冲区。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM