Send data by network and plot with octave

瘦欲@ 提交于 2019-12-06 16:55:16

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.

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

(Don't forget to make this script executable!)

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:

  1. Run the visualiseRobotData script from the octave terminal.
    (Note: this will block until a connection is established)
  2. From your bash terminal run: ./sin.sh | nc localhost 9000

And watch the datapoints get plotted as they come in from your sin.sh script.

It's a bit crude, but you can just reload the file in a loop. This one runs for 5 minutes:

for i = 1:300
  load Test/sine.txt
  plot (sine(:,1), sine(:,2))
  sleep (1)
endfor

You can mount remote directory via sshfs:

sshfs user@remote:/path/to/remote_dir local_dir

so you wouldn't have to load remote file. If sshfs is not installed, install it. To unmount remote directory later, execute

fusermount -u local_dir

To get a robot's data from Octave, execute (Octave code)

system("ssh user@host 'cd remote_dir; rosrun explo explo_node > states.txt'")
%% then plot picture from the data in local_dir
%% that is defacto the directory on the remote server
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!