Send data by network and plot with octave

别说谁变了你拦得住时间么 提交于 2019-12-08 04:04:18

问题


I am working on a robot and my goal is to plot the state of the robot.

For now, my workflow is this:

  1. Launch the program
  2. Redirect the output in a file (robot/bash): rosrun explo explo_node > states.txt
  3. Send the file to my local machine (robot/bash): scp states.txt my_desktop:/home/user
  4. 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?

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.


回答1:


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.




回答2:


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



回答3:


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


来源:https://stackoverflow.com/questions/44461701/send-data-by-network-and-plot-with-octave

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!