Realtime plot of floating point data from Serial

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Realtime plot of floating point data from Serial

borabut
Im having trouble getting a real time plot of my serial data on Octave. Im
trying to read some floating point values being sent by an arduino, and plot
them at a rate of 1hz from Octave. My code is below.

    s1 = serial("COM4", 115200);
    set(s1, 'timeout', 1);
    srl_flush(s1);

    pid_plot = 0;
    pid_sp = 0;

    while true    
      data_serial = srl_read(s1,4)
      data_float = typecast(uint8(data_serial), 'single')
      pid_plot = cat(1, pid_plot, data_float)
      plot(pid_plot, "color", "b")
      hold on
      plot([pid_sp,pid_sp], "color", "r")
      drawnow()
      pause(1)
    endwhile
    srl_close(s1)

This code is being used to visualize the output of a PID loop to aid in
tuning. Right now my arduino code is just dummy code that writes sine wave
data over serial. The arduino plotter works fine, showing a perfect sine
wave but octave shows garbage data.

<http://octave.1599824.n4.nabble.com/file/t372752/data.png>

Obviously these data points are wrong since sine wave can only be between -1
and 1, and arduino plotter shows exactly that. What am I doing wrong that my
floating point values are getting mangled in Octave?



--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


-----------------------------------------
Join us March 12-15 at CERN near Geneva
Switzerland for OctConf 2018.  More info:
https://wiki.octave.org/OctConf_2018
-----------------------------------------
Reply | Threaded
Open this post in threaded view
|

Re: Realtime plot of floating point data from Serial

Andreas Weber-6
Am 25.02.2018 um 21:36 schrieb borabut:

> Im having trouble getting a real time plot of my serial data on Octave. Im
> ...
> tuning. Right now my arduino code is just dummy code that writes sine wave
> data over serial. The arduino plotter works fine, showing a perfect sine
> wave but octave shows garbage data.
>
> <http://octave.1599824.n4.nabble.com/file/t372752/data.png>
>
> Obviously these data points are wrong since sine wave can only be between -1
> and 1, and arduino plotter shows exactly that. What am I doing wrong that my
> floating point values are getting mangled in Octave?

Since you don't have any synchronisation, the byte stream between the
arduino and your PC seems to be shifted some (1-3) Bytes.

The quick and dirty way is to power down the arduino, restart Octave and
your program and then power on the arduino. Of course the serial_put on
the ardiono side is only allowed to send floats, no status message,
nothing else.

Btw, adding code and data via a paste service is much better than adding
screenshots

Andy


-----------------------------------------
Join us March 12-15 at CERN near Geneva
Switzerland for OctConf 2018.  More info:
https://wiki.octave.org/OctConf_2018
-----------------------------------------
Reply | Threaded
Open this post in threaded view
|

Re: Realtime plot of floating point data from Serial

borabut
Thank you, you're quick and dirty solution works. Since this is just for
tuning a PID loop Im not very concerned about the elegance of the solution,
only has to work once and never again! Sorry for the screencap, in the
future Ill be sure to provide all data and code in text format.



--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


-----------------------------------------
Join us March 12-15 at CERN near Geneva
Switzerland for OctConf 2018.  More info:
https://wiki.octave.org/OctConf_2018
-----------------------------------------