通过网络发送数据并使用倍频程进行绘图 [英] Send data by network and plot with octave
问题描述
我正在研究机器人,我的目标是绘制机器人的状态.
I am working on a robot and my goal is to plot the state of the robot.
现在,我的工作流程是这样:
For now, my workflow is this:
- 启动程序
- 将输出重定向到文件(机器人/bash)中:
rosrun explo explo_node > states.txt
- 将文件发送到我的本地计算机(机器人/bash):
scp states.txt my_desktop:/home/user
- 用八度(桌面/八度)绘制状态:
plot_data('states.txt')
- Launch the program
- Redirect the output in a file (robot/bash):
rosrun explo explo_node > states.txt
- Send the file to my local machine (robot/bash):
scp states.txt my_desktop:/home/user
- Plot the states with octave (desktop/octave):
plot_data('states.txt')
是否有一个简单的解决方案来实时"存储数据?对于八度音阶.我认为我可以毫不费力地从文件中读取作为输入并在添加数据时绘制数据.
Is there a simple solution to have the data in "real time"? For the octave side. I think that I can with not so much difficulty read from a file as an input and plot the data when data is added.
问题是如何将数据发送到文件?
The problem is how do I send the data to a file?
除了八度音阶之外,我还接受其他解决方案.事实是,我需要绘制带有箭头的2d图,以显示机器人的方向.
I am opened to other solutions than octave. The thing is that I need to have 2d plot with arrows for the orientation of the robot.
推荐答案
下面是一个示例,说明如何通过网络发送数据(如Andy建议)并绘制生成的数据(即即时的).我也认为这种方法最灵活/最合适.
Here's an example of how you could send the data over the network (as Andy suggested) and plot as it is generated (i.e. realtime). I also think this approach is the most flexible / appropriate.
为了演示,我将使用一个bash脚本来生成一个 每十秒配对一次 功能,范围 :
To demonstrate, I will use a bash script that generates an pair every 10th of a second, for the function, in the range :
#!/bin/bash
# script: sin.sh
for i in `seq 0 0.01 31.4`;
do
printf "$i, `echo "s($i)" | bc -l`\n"
sleep 0.1
done
(不要忘记使此脚本可执行!)
准备以下八度脚本(需要 socket包!):>
Prepare the following octave script (requires the sockets package!):
% in visualiseRobotData.m
pkg load sockets
s = socket();
bind(s, 9000);
listen(s, 1);
c = accept(s);
figure; hold on;
while ! isempty (a = str2num (char (recv (c, inf))))
plot (a(:,1), a(:,2), '*'); drawnow;
end
hold off;
现在按以下顺序执行操作:
Now execute things in the following order:
- 从八度音阶终端运行
visualiseRobotData
脚本.
(注意:这将阻塞,直到建立连接为止) - 从bash终端运行:
./sin.sh | nc localhost 9000
- Run the
visualiseRobotData
script from the octave terminal.
(Note: this will block until a connection is established) - From your bash terminal run:
./sin.sh | nc localhost 9000
观察数据点是从sin.sh
脚本中传入的数据点.
And watch the datapoints get plotted as they come in from your sin.sh
script.
这篇关于通过网络发送数据并使用倍频程进行绘图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!