实时绘图/数据记录

发布于 2024-08-19 18:42:15 字数 136 浏览 3 评论 0原文

我将编写一个程序来绘制来自连接到计算机的传感器的数据。传感器值将绘制为时间的函数(y 轴上的传感器值,x 轴上的时间)。我希望能够实时向绘图添加新值。在 C++ 中最好用什么来做到这一点?

编辑:顺便说一句,该程序将在 Linux 机器上运行

I'm going to write a program that plots data from a sensor connected to the computer. The sensor value is going to be plotted as a function of the time (sensor value on the y-axis, time on the x-axis). I want to be able to add new values to the plot in real time. What would be best to do this with in C++?

Edit: And by the way, the program will be running on a Linux machine

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

陌伤ぢ 2024-08-26 18:42:15

您特别关心 C++ 方面吗?我已经通过将 gnuplot 放入 read/plot/refresh 循环或使用 LiveGraph 没有任何问题。

Are you particularly concerned about the C++ aspect? I've done 10Hz or so rate data without breaking a sweat by putting gnuplot into a read/plot/refresh loop or with LiveGraph with no issues.

美羊羊 2024-08-26 18:42:15

编写一个函数,可以按照您喜欢的方式绘制 std::deque,然后将 .push_back() 值从传感器发送到可用的队列中,并且 <如果队列变得太长而无法进行良好的绘图,则从队列中获取 code>.pop_front() 值。

绘图功能的确切性质取决于您的平台、需求、审美观等。

Write a function that can plot a std::deque in a way you like, then .push_back() values from the sensor onto the queue as they come available, and .pop_front() values from the queue if it becomes too long for nice plotting.

The exact nature of your plotting function depends on your platform, needs, sense of esthetics, etc.

森罗 2024-08-26 18:42:15

您可以使用环形缓冲区。在这样的缓冲区中,您有读取位置和写入位置。这样,一个线程可以写入缓冲区,其他线程可以读取并绘制图表。为了提高效率,您通常最终会编写自己的框架。

这种缓冲区的大小可以使用以下方法进行估计:传感器的数据传输速度(40KHz?)、一个探头的大小以及您希望保留用于绘图目的的时间跨度。

它还取决于您是否想要存储未压缩的此类数据、存储渲染的绘图 - 所有这些都用于进一步的离线分析。在非 RTOS 环境中,您的“实时”取决于处理速度:检索/存储/处理和绘制数据的速度。通常它是接近实时的效率。

You can use ring buffers. In such buffer you have read position and write position. This way one thread can write to buffer and other read and plot a graph. For efficiency you usually end up writing your own framework.

Size of such buffer can be estimated using eg.: data delivery speed from sensor (40KHz?), size of one probe and time span you would like to keep for plotting purposes.

It also depends whether you would like to store such data uncompressed, store rendered plot - all for further offline analysis. In non-RTOS environment your "real-time" depends on processing speed: how fast you can retrieve/store/process and plot data. Usually it is near-real time efficiency.

一曲爱恨情仇 2024-08-26 18:42:15

您可能需要查看 RRDtool 看看它是否满足您的要求。

RRDtool 是一个用于时间序列数据的高性能数据记录和图形系统。

You might want to check out RRDtool to see whether it meets your requirements.

RRDtool is a high performance data logging and graphing system for time series data.

等数载,海棠开 2024-08-26 18:42:15

我对通过 RS232 连接磁导率传感器的设备做了类似的事情。

  • 将从传感器接收到的字节打包到数据包中,
  • 使用集合(主要是列表)来存储它们,
  • 通过在新值到达之前丢弃最近的值来防止集合超过固定大小
  • 找到合适的图形库来绘制(可能是SDL) 如果你想保持简单和跨平台),但这个选择取决于你需要什么样的图表(ncurses 可能就足够了)
  • 最后但并非最不重要的是:因为你使用的是我想你的方法将是多线程的,所以考虑一下并使用同步集合或允许在其他线程检索值时添加值的集合(所以忘记了迭代器,也许一个数组就足够了)

顺便说一句,我认为有很多库,只需搜索它们:

I did a similar thing for a device that had a permeability sensor attached via RS232.

  • package bytes received from sensor into packets
  • use a collection (mainly a list) to store them
  • prevent the collection to go over a fixed size by trashing least recent values before new ones arrive
  • find a suitable graphics library to draw with (maybe SDL if you wanna keep it easy and cross-platform), but this choice depends on what kind of graph you need (ncurses may be enough)
  • last but not least: since you are using a sensor I suppose your approach will be multi-threaded so think about it and use a synchronized collection or a collection that allows adding values when other threads are retrieving them (so forgot iterators, maybe an array is enough)

Btw I think there are so many libraries, just search for them:

仙女 2024-08-26 18:42:15

我假设您将在 RTOS 上部署此应用程序。但是,数据速率是多少,实时要求是多少!因此,如上所述,一个简单的解决方案可能就足够了。但是,如果你有严格的实时限制,一切都会发生巨大的变化。带数据管道的多线程设计可以解决您的实时问题。

I assume that you will deploy this application on a RTOS. But, what will be the data rate and what are real-time requirements! Therefore, as written above, a simple solution may be more than enough. But, if you have hard-real time constraints everything changes drastically. A multi-threaded design with data pipes may solve your real-time problems.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文