Performance issues and crashes with serial reading

3 views (last 30 days)
Vinci
Vinci on 29 Apr 2014
Edited: Vinci on 29 Apr 2014
Hi there
I've been working with two inertial measurement units lately, which both send raw sensor data and calculated state attributes like attitude and position to the PC's COM port.
The first unit was commercial and an easily available flight-controller for DIY drones with cheap sensors and poor precision in general. The second unit was self-developed and uses way more expensive and therefor better sensors. About 4 months ago I created a little GUI for visualizing 3d attitude and position which was very poorly coded. A simple button callback started an endless loop with polled UART communication...
Since creating this GUI was not really my goal and more a "nice-to-have" I didn't really care much at that point, at least it worked. The GUI was used on the first, commercial, unit only and red 18 bytes (9x int16) from the UART every loop. The sampling rate was about 25Hz and was easily handled by MatLab. The visualization itself was a 3D patch object which was turned and positioned by makehgtform-objects. As I just said, everything worked like a charm.
Now, a couple of weeks later I got the self-developed board to work. I pretty much copy and pasted the entire GUI code and just edited my read function, since I don't send data as int16 anymore but as float32. The sampling rate is almost the same with 20Hz.
But for some strange reason I can't get it to work this time. MatLab keeps crashing and hanging up just after a couple of seconds into the loop. No error message or anything is shown which I guess indicates that it simply can't handle the UART communication in time...? Still this looks strange to me, since the amount of data did not really change... just the datatype it gets interpreted as?
Does anybody have an idea what might cause this? Would it improve performance if I make the effort to write callbacks and sort the whole code out? I'm not really an expert on GUI creation and don't want to waste my time if all I get from rewriting everything is prettier code and no performance boost...
Thanks
%%count number of cycles
cnt = cnt+1;
%%read data from serial
while s.BytesAvailable < 18
end
read = fread(s,[1 4],'float32'); % change if more or less sensors are red
data(cnt, :) = read;
% calculate stuff...
/edit I almost forgot... The only "real" difference between the code which already worked and the current version for the new inertial sensor is, that there are way less calculations inside the loop. Maybe the while BytesAvailable kills everything?
Also, the first time a real USB-serial bridge in hardware was used and now I use a virtual com USB class running on a CortexM4... if that makes any difference? Who knows...

Answers (0)

Categories

Find more on Hardware Discovery and Setup in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!